本文介绍了如何在位图上交换红色和蓝色通道?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在位图上交换红色和蓝色通道而不使用不安全的方法并在c#中快速?
提前谢谢.
谢谢.这是c#中的代码:
How to swap Red and Blue channels on bitmap without using unsafe methods and fast in c#?
Thanks in advance.
Thanks . Here is the code in c#:
private Bitmap SwapRedAndBlueChannels(Bitmap bitmap)
{
var imageAttr = new ImageAttributes();
imageAttr.SetColorMatrix(new ColorMatrix(
new[]
{
new[] {0.0F, 0.0F, 1.0F, 0.0F, 0.0F},
new[] {0.0F, 1.0F, 0.0F, 0.0F, 0.0F},
new[] {1.0F, 0.0F, 0.0F, 0.0F, 0.0F},
new[] {0.0F, 0.0F, 0.0F, 1.0F, 0.0F},
new[] {0.0F, 0.0F, 0.0F, 0.0F, 1.0F}
}
));
var temp = new Bitmap(bitmap.Width, bitmap.Height);
GraphicsUnit pixel = GraphicsUnit.Pixel;
using (Graphics g = Graphics.FromImage(temp))
{
g.DrawImage(bitmap, Rectangle.Round(bitmap.GetBounds(ref pixel)), 0, 0, bitmap.Width, bitmap.Height,
GraphicsUnit.Pixel, imageAttr);
}
return temp;
}
推荐答案
这篇关于如何在位图上交换红色和蓝色通道?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!