C#中怎么把Image转换成bitmap

nvshenxp 2011-12-12 10:57:34
RT
...全文
2213 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
stayingnumber1 2013-08-01
  • 打赏
  • 举报
回复
对 很好 强制转换
nvshenxp 2011-12-13
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 chenandczh 的回复:]
引用 2 楼 sdl2005lyx 的回复:

Image是抽象基类,Bitmap是它的派生类,存在转换问题。。。

...
直接强转换
[/Quote]

谢谢,正解!
nvshenxp 2011-12-12
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zyloveyrf 的回复:]
Bitmap bmp1 = new Bitmap(sFilePath);
Bitmap bmp2 = new Bitmap(100,100);
g2 = Graphics.FromImage(bmp2);
g2.FillRectangle(new SolidBrush(Color.White),0,0,100,100);
[/Quote]

我是想在读入一整个文件夹的图片之后把图片转换成Bitmap可以实现吗?
string[] arrFileNames = System.IO.Directory.GetFiles(@"f:\image");//图片文件夹路径

foreach (string name in arrFileNames)
{
System.Drawing.Image image;
try
{
image = Image.FromFile(name);
imageList1.Images.Add(name, image);

}
catch (Exception ex)
{
Console.WriteLine("图片[0}加载失败,原因:{1}" + ex.Message);
}
}

this.pictureBox1.Image = imageList1.Images[0];
梦里独赏花 2011-12-12
  • 打赏
  • 举报
回复

FileStream fs = new FileStream(dta.Rows[0]["photoPath"].ToString(), FileMode.Open);
byte[] imageBuffer = new byte[fs.Length];
fs.Read(imageBuffer, 0, imageBuffer.Length);
fs.Close();
MemoryStream ms = new MemoryStream(imageBuffer);
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.StreamSource = ms;
bitmap.EndInit();
ms.Close();
mainFrm.collectionlist.image.Source = bitmap;
sdl2005lyx 2011-12-12
  • 打赏
  • 举报
回复
Image是抽象基类,Bitmap是它的派生类,存在转换问题。。。
萧炎 2011-12-12
  • 打赏
  • 举报
回复
Bitmap bmp1 = new Bitmap(sFilePath);
Bitmap bmp2 = new Bitmap(100,100);
g2 = Graphics.FromImage(bmp2);
g2.FillRectangle(new SolidBrush(Color.White),0,0,100,100);
绿领巾童鞋 2011-12-12
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 sdl2005lyx 的回复:]

Image是抽象基类,Bitmap是它的派生类,存在转换问题。。。
[/Quote]
...
直接强转换

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧