如何更改图像的位图颜色 [英] How to change bitmap color of a image
本文介绍了如何更改图像的位图颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Windows应用程序。
I am working on a windows application.
我有一个透明背景的图像。
I have a image with transparent background.
我想将图像的位图颜色从黑色更改为白色。
I want to change bitmap color of image from black to white.
为此目的,我写了一个小函数,看起来像这样:
For this purpose, I have written a little function, that looks like this:
public void colorImageChange()
{
byte a = 255;
StreamResourceInfo sri = Application.GetResourceStream(new Uri("Assets/Picto_1604_Panther_Black.png", UriKind.Relative));
BitmapImage src = new BitmapImage();
src.SetSource(sri.Stream);
// Get WriteableBitmap
WriteableBitmap bitmap = new WriteableBitmap(src);
for (int x = 0; x < bitmap.Pixels.Length; x++)
{
byte[] actualColorValues = BitConverter.GetBytes(bitmap.Pixels[x]);
byte[] modifiedColorValues = new byte[4];
modifiedColorValues[0] = a;
modifiedColorValues[1] = a;
modifiedColorValues[2] = a;
//modifiedColorValues[3] = a;
//opacity
modifiedColorValues[3] = actualColorValues[3];
bitmap.Pixels[x] = BitConverter.ToInt32(modifiedColorValues, 0);
}
// Set Image object, defined in XAML, to the modified bitmap.
ImageViewer1.Source = bitmap;
}
我可以改变图像的颜色,但我的问题是,图像的边缘不平滑。
请帮帮我。
Please help me.
推荐答案
Hi Mars771,
如果你想创建一个处理图像的程序,请尝试使用
OpenCV 库。
如果你通过"C#opencv background transparent"搜索,你会发现很多样本。其中一个....
如何从OpenCV android中的grabcut
输出图像中删除黑色背景?
HTTP:// answe rs.opencv.org/question/24463/how-to-remove-black-background-from-grabcut-output-image-in-opencv-android/?comment=24786#comment-24786
问候,
Hi Mars771,
If you want to create a program which handles images, please try to use OpenCV library.
If you search by "C# opencv background transparent", you will find many samples. One of them....
How to remove black background from grabcut output image in OpenCV android ?
http://answers.opencv.org/question/24463/how-to-remove-black-background-from-grabcut-output-image-in-opencv-android/?comment=24786#comment-24786
Regards,
这篇关于如何更改图像的位图颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文