16,472
社区成员
发帖
与我相关
我的任务
分享
private void getgif()
{
Image img = Image.FromFile(@"C:\1.Bmp");
Bitmap bm = new Bitmap(img.Width, img.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
Image img2 = Image.FromFile(@"C:\2.Bmp");
Image bgbmp = new Bitmap(img2);
img.Dispose();
Bitmap bImage = new Bitmap(bgbmp, 102, 126);
var color = new Color(); //定义一个Color对象,将其存储像素值
for (int i = 0; i < 102; i++) //得到图片的宽度
{
for (int j = 0; j < 126; j++) //得到图片的高度
{
color = bImage.GetPixel(i, j); //得到二维数组中a[i,j]的像素值
//判断该像素值是否接近白色,如果是,那么将其转换成透明色(以RGB>250为界限
if (int.Parse(color.B.ToString()) >= 250 && int.Parse(color.R.ToString()) >= 250 && int.Parse(color.G.ToString()) >= 250)
bImage.SetPixel(i, j, Color.Transparent); //设置背景为透明色
}
}
Graphics g = Graphics.FromImage(bm);
g.Clear(Color.White);
g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel);
g.DrawImage(bImage, new Rectangle(0, 0, bImage.Width, bImage.Height), 0, 0, bImage.Width, bImage.Height, GraphicsUnit.Pixel);
g.DrawString("addasdasdasd", new Font("黑体", 20), new SolidBrush(Color.Black), new Point(50, 10));
g.Dispose();
bm.Save(@"C:\photo.jpg");
}