Loading and using image from binary file
-
Hi all, I have a flow of things I need to do, and by now I couldn't find a covenient (or any) way doing it: 1. Loading image from binary file. The image is a 3D image, and I know each slice dimentions. Each pixel in this picture is of type Int16 (2 bytes per pixel). 2. Now, I need to set the 'Image' property of my PictureBox to one of my image slices (let's say the first one). I'll be grateful if someone could explain how to perform these procedures. Thanks! Eyal.
-
Hi all, I have a flow of things I need to do, and by now I couldn't find a covenient (or any) way doing it: 1. Loading image from binary file. The image is a 3D image, and I know each slice dimentions. Each pixel in this picture is of type Int16 (2 bytes per pixel). 2. Now, I need to set the 'Image' property of my PictureBox to one of my image slices (let's say the first one). I'll be grateful if someone could explain how to perform these procedures. Thanks! Eyal.
- Write a test app to extract a slice and then test it by viewing it. If you don't have anything to view a slice of your 3D image with, this could be a very long day. You'll need to confirm your knowledge of how the slices are assembled in the 3D image first. 2) You'll need to know more than the pixel depth for a slice. The .Net framework will work with jpg/gif/bmp/dip/tiff/png that I recall so you'll have to convert the slice to one of these if it is not already. To do that you'll need to know the slice layout wrt it's storage technique (i.e. raster etc), any compression and the palette configuration. Then write the conversion routine (if needed) and load up the resulting image.
I'm largely language agnostic
After a while they all bug me :doh:
-
- Write a test app to extract a slice and then test it by viewing it. If you don't have anything to view a slice of your 3D image with, this could be a very long day. You'll need to confirm your knowledge of how the slices are assembled in the 3D image first. 2) You'll need to know more than the pixel depth for a slice. The .Net framework will work with jpg/gif/bmp/dip/tiff/png that I recall so you'll have to convert the slice to one of these if it is not already. To do that you'll need to know the slice layout wrt it's storage technique (i.e. raster etc), any compression and the palette configuration. Then write the conversion routine (if needed) and load up the resulting image.
I'm largely language agnostic
After a while they all bug me :doh:
Hi, I think I know all there is to know regarding how my binary file is assembled. However, there are unresolved issues: 1. Can you please explain how I can create a known-format image after loading the data I need? 2. Since every pixel is represented by 16bit (2 bytes and not 1), the only way I see for loading the image is loop for reading pixel-pixel BinaryReader. Any better suggestions? FileStream.read reads 1 byte at a time... Thanks!
-
Hi all, I have a flow of things I need to do, and by now I couldn't find a covenient (or any) way doing it: 1. Loading image from binary file. The image is a 3D image, and I know each slice dimentions. Each pixel in this picture is of type Int16 (2 bytes per pixel). 2. Now, I need to set the 'Image' property of my PictureBox to one of my image slices (let's say the first one). I'll be grateful if someone could explain how to perform these procedures. Thanks! Eyal.
You can use a
BinaryReader
to easily read Int16 values. Create aBitmap
object with the pixel dimensions of the image that you want to show. Get the values from the 3D data and insert as color values in theBitmap
. An easy way to set the pixels in theBitmap
is to use theSetPixel
method. A more complicated way (but somehing like 100 times faster) is to use theLockBits
andUnlockBits
methods and unsafe code (pointer operations) to write directly to the memory area for theBitmap
.Despite everything, the person most likely to be fooling you next is yourself.