user8795061
user8795061

Reputation: 11

Extracting content .img file

I am working on a project where we have to extract information from .img file. What is known, is that .img file contains image with 512x512 pixels, and size of each pixel is 2 bits of type short. We have to extract that image form the file. The question is, how to read that file with C#? My current line for binary reading is:

byte[] bytes = System.IO.File.ReadAllBytes("C:\temp\Jonatan\test23.img");

Thank you for your help!

Upvotes: 1

Views: 546

Answers (1)

Clemens
Clemens

Reputation: 128147

Depending on the actual format of your pixel data, creating a bitmap from the byte array might be as simple as this:

var width = 512;
var height = 512;
var stride = width * 2;

var bitmap = BitmapSource.Create(
    width, height, 96, 96, PixelFormats.Gray16, null, bytes, stride);

You might now have an Image element in XAML

<Image x:Name="image"/>

and set its Source property to the BitmapSource:

image.Source = bitmap;

Upvotes: 2

Related Questions