[英]Read float pixel data from a file back to C#
在C ++中,我将浮动图像写入文件:
FILE* fp = fopen("image.fft", "wb");
float* pixels = getPixel();
fwrite((unsigned char*)pixels, sizeof(pixels), width*height, fp);
为了分析图像,我们需要将浮动图像读入C#。 我坚持如何将浮动图像“image.fft”读入C#。 我知道浮动图像的大小宽度和高度。
使用GET Bitmap类,并设置像素的更多信息,请按照此
你可以使用这个bimap构造函数http://msdn.microsoft.com/en-us/library/zy1a2d14.aspx ,只需使用GCHandle从文件中获取字节数组来获取IntPtr或类似的东西:
Bitmap BytesToBitmap (byte[] bmpBytes, Size imageSize)
{
Bitmap bmp = new Bitmap (imageSize.Width, imageSize.Height);
BitmapData bData = bmp.LockBits (new Rectangle (0,0, bmp.Size.Width,bmp.Size.Length),
ImageLockMode.WriteOnly,
PixelFormat.Format32bppRgb);
// Copy the bytes to the bitmap object
Marshal.Copy (bmpBytes, 0, bData.Scan0, bmpBytes.Length);
bmp.UnlockBits(bData);
return bmp;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.