我有一个数组int
我的 C# 程序中存在像素,我想将其转换为图像。问题是我正在将程序的 Java 源代码转换为等效的 C# 代码。在java中,该行读取将int像素数组显示到图像中:
Image output = createImage(new MemoryImageSource(width, height, orig, 0, width));
有人可以告诉我 C# 的等效项吗?
这里 orig 是数组int
像素。我搜索了 Bitmap 类,有一个方法叫做SetPixel
但问题是它需要一个 x,y 坐标号。但我的代码中有一个数组int
像素。另一个奇怪的事情是我的原始数组有负数,而且它们距离 255 很远。在 Java 中也是同样的情况(意味着 C# 和 Java 中的数组具有相同的值),并且这些值在 Java 中工作正常。
但我无法将该行翻译成 C#。请帮忙。
使用 WPF,您可以直接从数组创建位图(图像)。然后,您可以对该图像进行编码或显示它或使用它:
int width = 200;
int height = 200;
//
// Here is the pixel format of your data, set it to the proper value for your data
//
PixelFormat pf = PixelFormats.Bgr32;
int rawStride = (width * pf.BitsPerPixel + 7) / 8;
//
// Here is your raw data
//
int[] rawImage = new int[rawStride * height / 4];
//
// Create the BitmapSource
//
BitmapSource bitmap = BitmapSource.Create(
width, height,
96, 96, pf, null,
rawImage, rawStride);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)