问题描述
我正在做一个项目,在该项目中,我必须即时清除照片的背景.
我们将在需要照片的人的背面放置一个特定颜色(即黄色)的对象,并在调用摄像头拍摄照片"事件时,代码将自动清除黄色背景并将图片合并到另一个背景上图片.
代码如下:
<code> Image i = Crop(pictureBox1.Image, rectWidth, rectHeight, rectX, rectY); Bitmap img1 = new Bitmap(i); Bitmap img2 = new Bitmap(pictureBox2.Image); Color transparencyColor = img1.GetPixel(0, 0); img1.MakeTransparent(img1.GetPixel(1, 1)); using (Graphics g = Graphics.FromImage(img2)) { using (Image skinImage = (Image)img1) { // draw image g.DrawImage(skinImage, (img2.Width - img1.Width)/2,(img2.Height- img1.Height)/2,img1.Width, img1.Height); } } pictureBox2.Image = (Image)img2; </code>
函数MakeTransparent并不是我尝试过的唯一方法,我已经尝试过发现几乎所有与使背景透明相关的内容,包括在每个像素上运行一个循环并根据需要更改其颜色.
代码正在做使背景色透明和合并的工作,但是我面临的主要问题是照片的曲线仍然显示黄点和实线,这非常糟糕.我不确定是否可以在此问题区域放置图像.
谁能告诉我如何完全清除背景颜色,以及如何使背景完全透明,平滑的边缘和深的曲线也是透明的. :
g.DrawImage(skinImage, (img2.Width - img1.Width)/2,(img2.Height- img1.Height)/2,img1.Width, img1.Height);
它看起来也像是调整了图像的大小(或您正在执行的任何操作.我可以对图像进行成像,这意味着将某些颜色压在一起并变成了不是透明颜色的新"颜色.透明,同时保持宽度和高度不变,然后看看会发生什么.
含义...首先,请尝试确切的示例;-):
http://msdn.microsoft.com/en-us/library/4zzst10b.aspx [ ^ ]
祝你好运!
I am working on a project, in which i have to clear the background of photo on the fly.
we will put an object of specific color (i.e. yellow) on the back of the person who''s photo is required and when the camera Take Photo event is called, the code will automaticaly clear the yellow background and merge the picture on another background image.
The code is given as under:
<code> Image i = Crop(pictureBox1.Image, rectWidth, rectHeight, rectX, rectY); Bitmap img1 = new Bitmap(i); Bitmap img2 = new Bitmap(pictureBox2.Image); Color transparencyColor = img1.GetPixel(0, 0); img1.MakeTransparent(img1.GetPixel(1, 1)); using (Graphics g = Graphics.FromImage(img2)) { using (Image skinImage = (Image)img1) { // draw image g.DrawImage(skinImage, (img2.Width - img1.Width)/2,(img2.Height- img1.Height)/2,img1.Width, img1.Height); } } pictureBox2.Image = (Image)img2; </code>
The function MakeTransparent is not the only way i have tried, I have experimented almost everything i found related to make background transparent including running a loop on every pixel and changing its colour if required.
The code is doing the job to make background color transparent and merge is also ok but the main problem which i am facing is that the curves of the photo are still showing yellow dots and solid lines which is very bad. I am not sure if i can place an image in this question area.
Can any one tell me how to completely clear the background colour and make background fully transparent with smooth edges and deep curves are also transparent.
这篇关于将照片背景设置为透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!