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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. WPF
  4. convert byte[] to BitmabImage

convert byte[] to BitmabImage

Scheduled Pinned Locked Moved WPF
helpquestion
7 Posts 5 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.
  • A Offline
    A Offline
    amer shammout
    wrote on last edited by
    #1

    MemoryStream stream = new MemoryStream(b); //b is byte[] BitmapImage image = new BitmapImage(); image.BeginInit(); image.StreamSource = stream; image.EndInit(); when i use this code i receve an error Exception message is {"No imaging component suitable to complete this operation was found."} inner Exception is {"Exception from HRESULT: 0x88982F50"} what is th problem

    K P M 3 Replies Last reply
    0
    • A amer shammout

      MemoryStream stream = new MemoryStream(b); //b is byte[] BitmapImage image = new BitmapImage(); image.BeginInit(); image.StreamSource = stream; image.EndInit(); when i use this code i receve an error Exception message is {"No imaging component suitable to complete this operation was found."} inner Exception is {"Exception from HRESULT: 0x88982F50"} what is th problem

      K Offline
      K Offline
      KarstenK
      wrote on last edited by
      #2

      the BitmapImage needs to get some members filled.:~

      Press F1 for help or google it. Greetings from Germany

      C 1 Reply Last reply
      0
      • K KarstenK

        the BitmapImage needs to get some members filled.:~

        Press F1 for help or google it. Greetings from Germany

        C Offline
        C Offline
        califax2k
        wrote on last edited by
        #3

        I am also interested in which members this might be. Which are the most important ones? Thanks, Lars

        #pragma error( disable : * )

        1 Reply Last reply
        0
        • A amer shammout

          MemoryStream stream = new MemoryStream(b); //b is byte[] BitmapImage image = new BitmapImage(); image.BeginInit(); image.StreamSource = stream; image.EndInit(); when i use this code i receve an error Exception message is {"No imaging component suitable to complete this operation was found."} inner Exception is {"Exception from HRESULT: 0x88982F50"} what is th problem

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          Whenever I've seen this error, it's been caused by one of two things: 1. The image data needs to be offset. In the Northwind data, you have to offset the image byte array by 78 bytes (I think - you'd need to look this up, but this rings a bell) or 2. You aren't actually located at the right place to read the data from in your stream, i.e. you've gone past the end of the data. Use stream.Seek(0, SeekOrigin.Begin); to reset the stream to the start of the byte array. Note that option 2 is just a variation on option 1.

          "WPF has many lovers. It's a veritable porn star!" - Josh Smith

          As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

          My blog | My articles | MoXAML PowerToys | Onyx

          C 1 Reply Last reply
          0
          • P Pete OHanlon

            Whenever I've seen this error, it's been caused by one of two things: 1. The image data needs to be offset. In the Northwind data, you have to offset the image byte array by 78 bytes (I think - you'd need to look this up, but this rings a bell) or 2. You aren't actually located at the right place to read the data from in your stream, i.e. you've gone past the end of the data. Use stream.Seek(0, SeekOrigin.Begin); to reset the stream to the start of the byte array. Note that option 2 is just a variation on option 1.

            "WPF has many lovers. It's a veritable porn star!" - Josh Smith

            As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

            My blog | My articles | MoXAML PowerToys | Onyx

            C Offline
            C Offline
            califax2k
            wrote on last edited by
            #5

            Hi, I think, in my case its different ;) I am receiving an image from a webcam. What I want to do is, The image data is provided through an Image which uses a FormatConvertedBitmap as ImageSource. This bitmap uses a TransformedBitmap as BitmapSource (this all looks a bit like a decorator pattern). Now I do the following: I call CopyPixels on the TransformedBitmap with an pre allocated buffer with size: source.PixelWidth * source.PixelHeight * source.Format.BitsPerPixel / 8. The stride is source.PixelWidth * bytesPerPixel and the offset is 0. I pass this buffer as an argument to a memory stream and try to use this stream as StreamSource for a BitmapImage. It produces exactly the error message mentioned above ;( I played with CachingOptions (set it to None), CreationOptions (PreservePixelFormat) -> nothing ;-( Any Ideas? Greetz, Lars

            #pragma error( disable : * )

            P 1 Reply Last reply
            0
            • C califax2k

              Hi, I think, in my case its different ;) I am receiving an image from a webcam. What I want to do is, The image data is provided through an Image which uses a FormatConvertedBitmap as ImageSource. This bitmap uses a TransformedBitmap as BitmapSource (this all looks a bit like a decorator pattern). Now I do the following: I call CopyPixels on the TransformedBitmap with an pre allocated buffer with size: source.PixelWidth * source.PixelHeight * source.Format.BitsPerPixel / 8. The stride is source.PixelWidth * bytesPerPixel and the offset is 0. I pass this buffer as an argument to a memory stream and try to use this stream as StreamSource for a BitmapImage. It produces exactly the error message mentioned above ;( I played with CachingOptions (set it to None), CreationOptions (PreservePixelFormat) -> nothing ;-( Any Ideas? Greetz, Lars

              #pragma error( disable : * )

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              If you get this message, it generally suggests that the system cannot find a CODEC that could be used as a suitable source. Try saving the data out to disk and seeing if you can load it with a standard imaging application.

              "WPF has many lovers. It's a veritable porn star!" - Josh Smith

              As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

              My blog | My articles | MoXAML PowerToys | Onyx

              1 Reply Last reply
              0
              • A amer shammout

                MemoryStream stream = new MemoryStream(b); //b is byte[] BitmapImage image = new BitmapImage(); image.BeginInit(); image.StreamSource = stream; image.EndInit(); when i use this code i receve an error Exception message is {"No imaging component suitable to complete this operation was found."} inner Exception is {"Exception from HRESULT: 0x88982F50"} what is th problem

                M Offline
                M Offline
                morishuz
                wrote on last edited by
                #7

                i have exactly the same problem and i am not surprised because there is no way this could possibly work. nowhere do you actually set the image width or height or the pixel format of the byte array (in my case it's just a string or RGB values) - nor can i find a way you might actually set these - but they would definitely be required in order to initialise a BitmapImage. if you read from a file or an in memory image format this information is contained in the header of a specific image format such as png or jpg - but in the case of simple raw image data it is not. hence the exception. there obviously must be another solution. sadly i have searched high and low and still have no answers!

                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