如何将'System.Drawing.Image'转换为'System.Drawing.Bitmap'? [英] How to Convert 'System.Drawing.Image' to 'System.Drawing.Bitmap'?
本文介绍了如何将'System.Drawing.Image'转换为'System.Drawing.Bitmap'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个问题:
无法将类型'System.Drawing.Image'隐式转换为'System.Drawing.Bitmap'。存在显式转换(您是否错过了演员?)
在线:位图imagestream = GrayScale(Img);
Hi, i have a problem regarding:
Cannot implicitly convert type 'System.Drawing.Image' to 'System.Drawing.Bitmap'. An explicit conversion exists (are you missing a cast?)
On the line : Bitmap imagestream = GrayScale(Img);
public Image GrayScale(Image Img)
{
Stream imageStream = new MemoryStream();
using (Bitmap bmp = new Bitmap(Img))
{
int rgb;
Color c;
for (int y = 0; y < bmp.Height; y++)
for (int x = 0; x < bmp.Width; x++)
{
c = bmp.GetPixel(x, y);
rgb = (int)((c.R + c.G + c.B) / 3);
bmp.SetPixel(x, y, Color.FromArgb(rgb, rgb, rgb));
}
bmp.Save(imageStream, ImageFormat.Jpeg);
}
return Image.FromStream(imageStream);
}
private void button2_Click(object sender, EventArgs e)
{
Image Img = Image.FromFile("C:\\Users\\L31101\\Desktop\\19.male.happy.normalized.jpg");
Bitmap imagestream = GrayScale(Img);
}
任何人都知道如何解决这个问题?
Anyone knows how to solve this?
推荐答案
试试这个:
Try this:
Bitmap imagestream = new Bitmap(GrayScale(Img));
你好
尝试下面的一个
位图oBitmap =新位图(GrayScale(Img));
位图oBitmap =(位图)GrayScale(Img);
图像oImage = GrayScale(Img);
位图oBitmap = oImage作为位图;
Hello
Try one one of the below
Bitmap oBitmap = new Bitmap(GrayScale(Img));
OR
Bitmap oBitmap = (Bitmap) GrayScale(Img);
OR
Image oImage = GrayScale(Img);
Bitmap oBitmap = oImage as Bitmap;
这篇关于如何将'System.Drawing.Image'转换为'System.Drawing.Bitmap'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文