转换图片 Bitmap To BitmapImage
2011-07-20 15:05
501 查看
http://blog.sina.com.cn/s/blog_6e6941e10100n2yn.html
public class GetBitmpIamge
{
public static BitmapImage BitmapToBitmapImage(Bitmap bitmap)
{
Bitmap bitmapSource = new Bitmap(bitmap.Width, bitmap.Height);
bitmapSource.MakeTransparent();
int i, j;
for (i = 0; i < bitmap.Width; i++)
for (j = 0; j < bitmap.Height; j++)
{
Color pixelColor = bitmap.GetPixel(i, j);
Color newColor = Color.FromArgb(pixelColor.R, pixelColor.G, pixelColor.B);
if (newColor == Color.FromArgb(255, 0, 0, 0))
{
newColor = Color.FromArgb(255, 255, 255, 255);
}
bitmapSource.SetPixel(i, j, newColor);
}
MemoryStream ms = new MemoryStream();
bitmapSource.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = new MemoryStream(ms.ToArray());
bitmapImage.EndInit();
return bitmapImage;
}
}
public class GetBitmpIamge
{
public static BitmapImage BitmapToBitmapImage(Bitmap bitmap)
{
Bitmap bitmapSource = new Bitmap(bitmap.Width, bitmap.Height);
bitmapSource.MakeTransparent();
int i, j;
for (i = 0; i < bitmap.Width; i++)
for (j = 0; j < bitmap.Height; j++)
{
Color pixelColor = bitmap.GetPixel(i, j);
Color newColor = Color.FromArgb(pixelColor.R, pixelColor.G, pixelColor.B);
if (newColor == Color.FromArgb(255, 0, 0, 0))
{
newColor = Color.FromArgb(255, 255, 255, 255);
}
bitmapSource.SetPixel(i, j, newColor);
}
MemoryStream ms = new MemoryStream();
bitmapSource.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = new MemoryStream(ms.ToArray());
bitmapImage.EndInit();
return bitmapImage;
}
}
相关文章推荐
- android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byte
- android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byte
- 保存图片控件上的图片到本地 出现错误:无法将类型为“System.Windows.Media.Imaging.BitmapFrameDecode”的对象强制转换为类型“System.Windows.Media.Imaging.BitmapImage”。
- android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byte
- 把网络图片转换为bitmap并显示在ImageView中
- android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byte
- android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byte
- android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byt
- 黄聪: PHP WkHtmlToPdf/WkHtmlToImage 将网页直接转换成pdf和图片
- 图片从bitmap转换成ImageSource 方法
- 生成二维码图片 MatrixToImageWriter .java
- Simple way to check if an image bitmap is blur
- Android本地图片转换成Bitmap存储
- 将荧屏操作转换为GIF图片 screentogif
- 本地资源的图片文件 转换成bitmap
- 把获得的数据流转换成一副图片(Bitmap)
- bitmapimage与byte[]相互转换
- Byte[]、Image、Bitmap 之间的相互转换
- Android ImageView与Bitmap相互转换
- 【我的Android进阶之旅】推荐一款视频转换GIF图片格式的转换工具(Video to GIF)