我正在制作一个Windows窗体应用程序,其中我在笔记本电脑的网络摄像头流中覆盖图像。 覆盖的图像显示荒谬的颜色。它显示出很多粉红色。有什么我可以做的,使叠加的图像看起来正确。 我正在使用camera_Net库连接到网络摄像头 在网络摄像头视频期间覆盖图像的建议也应该受到赞赏。
这是我绘制图像的代码
string filepath = @"E:\office\lux desktop app\Camera_Net-master\Camera_Net-master\Samples\CameraControlTool\water_PNG3290.png";
Bitmap bitmap1 = new Bitmap(filepath);
g.DrawImage(bitmap1, new Rectangle(400 , 0, 250, 600));
答案 0 :(得分:1)
我认为问题在于图像本身。这是一个.png图像,所以我有可能有一个alpha值。背面的白色被裁剪掉,但在水之间,浅蓝色值是粉红色。
我首先尝试使用更简单的图像。像this这样的东西。我认为这样可以正常工作。然后搜索一些更复杂的图像并尝试找到弱点并找到一些替代选项将图像带入凸轮。
答案 1 :(得分:0)
正如@Roman R指出g正确指向不正确的背景, 问题确实在于颜色格式,因此解决方案是根据图像使用正确的图像像素格式。
这是完整的代码
Bitmap bmp = new Bitmap(w, h, PixelFormat.Format32bppRgb);
Graphics g = Graphics.FromImage(bmp);
Image newImage;
newImage = Properties.Resources.red_frame_03;
using (Bitmap oldBmp = new Bitmap(newImage))
using (Bitmap newBmp = new Bitmap(oldBmp))
using (Bitmap targetBmp = newBmp.Clone(new Rectangle(0, 0, newBmp.Width, newBmp.Height), PixelFormat.Format16bppArgb1555))
{
g.DrawImage(targetBmp, new Rectangle(100, 0, 350, 350));
}