olidev
olidev

Reputation: 20624

Read float pixel data from a file back to C#

In C++, I write a float image into a file:

FILE* fp = fopen("image.fft", "wb");

float* pixels = getPixel();

fwrite((unsigned char*)pixels, sizeof(pixels), width*height, fp);

For analyzing the image, we need to read the float image into C#. I am stuck with how to read the float image "image.fft" into C#. I know the size width and height of the float image.

Upvotes: 0

Views: 714

Answers (2)

user629926
user629926

Reputation: 1940

You could use this bimap constructor http://msdn.microsoft.com/en-us/library/zy1a2d14.aspx , just use GCHandle to byte array from file to get IntPtr or something like this:

 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;
}

Upvotes: 1

KF2
KF2

Reputation: 10143

use Bitmap class for get and set pixel for more information follow this

Upvotes: 1

Related Questions