我的intC#程序中有一个像素数组,我想将其转换为图像.问题是我正在将程序的Java源代码转换为等效的C#代码.在java中,行读取将int像素数组显示为image:
Image output = createImage(new MemoryImageSource(width, height, orig, 0, width));
Run Code Online (Sandbox Code Playgroud)
有人能告诉我C#等价吗?
这里的orig是int像素数组.我搜索了Bitmap类并且有一个方法被调用,SetPixel但问题是需要ax,y坐标数.但我的代码中有一个int像素数组.另一个奇怪的事情是我的orig数组有负数,它们远远超过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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16445 次 |
| 最近记录: |