Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Loading and using image from binary file

Loading and using image from binary file

Scheduled Pinned Locked Moved C#
tutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    eyalbi007
    wrote on last edited by
    #1

    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.

    M G 2 Replies Last reply
    0
    • E eyalbi007

      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.

      M Offline
      M Offline
      MidwestLimey
      wrote on last edited by
      #2
      1. 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:


      E 1 Reply Last reply
      0
      • M MidwestLimey
        1. 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:


        E Offline
        E Offline
        eyalbi007
        wrote on last edited by
        #3

        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!

        1 Reply Last reply
        0
        • E eyalbi007

          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.

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          You can use a BinaryReader to easily read Int16 values. Create a Bitmap 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 the Bitmap. An easy way to set the pixels in the Bitmap is to use the SetPixel method. A more complicated way (but somehing like 100 times faster) is to use the LockBits and UnlockBits methods and unsafe code (pointer operations) to write directly to the memory area for the Bitmap.

          Despite everything, the person most likely to be fooling you next is yourself.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups