none
How to control JpegBitmapDecoder output format? RRS feed

  • Question

  • I am using JpegBitmapDecoder to decode images from camera. I noticed that the resulting image is always in Bgr32 format. Documentation says that by default JpegBitmapDecoder produced images in the same format as it was encoded, but even if I encode the stream in Bgr24, the resulting image is still in Bgr32. Is it possible to get Bgr24 or ideally Rgb24 straight from the decoder?

    Saturday, December 7, 2019 2:32 PM

All replies

  • Actually, the documentation says the decoder will either produce Grey8 or Rgb24.  A JPEG file has no clue what format was used in the encoding, other than "greyscale" vs "color'.  The JPEG internal format is basically either Y (for grayscale) or YUV (for color).

    Can you show us your code?  I'm curious to see what options you used.  And, frankly, I'm surprised that the doc says it exports Rgb24, because that format is not terribly useful in Windows, where color bitmaps are almost always Bgr24 or Bgr32.


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Sunday, December 8, 2019 8:45 AM
  • Actually, the documentation says the decoder will either produce Grey8 or Rgb24.  A JPEG file has no clue what format was used in the encoding, other than "greyscale" vs "color'.  The JPEG internal format is basically either Y (for grayscale) or YUV (for color).

    Right, there is different information in documentation. The code is pretty standard:

    var dec = new JpegBitmapDecoder(imageStream, BitmapCreateOptions.None, BitmapCacheOption.Default);
    
    return dec.Frames[0];
    dec.Frames[0].Format prints 'Bgr32', not 'Rgb24'. Note that I have `BitmapCreateOptions.None`. Other alternative could be `BitmapCreateOptions.PreservePixelFormat`, for which documentation says: "Ensures that the PixelFormat a file is stored in is the same as it is loaded to." What do I miss here?
    Sunday, December 8, 2019 4:12 PM
  • Interesting.  My guess is that you will have to live with it.

    The fact that you get Bgr32 is not surprising.  The decoder is eventually going to call a C++ decoder library, and C++ GUI code in Windows is going to create a 32-bit DIB, which is Bgr32.

    Why would you want Rgb24?  No APIs use it.


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Monday, December 9, 2019 7:34 AM
  • Interesting.  My guess is that you will have to live with it.

    The fact that you get Bgr32 is not surprising.  The decoder is eventually going to call a C++ decoder library, and C++ GUI code in Windows is going to create a 32-bit DIB, which is Bgr32.

    Why would you want Rgb24?  No APIs use it.

    Yes, I had to attach an external C++ decoder for that.
    Tuesday, December 10, 2019 2:27 PM
  • Hi Aleksey,

    It seems that your problem has been solved. If so, please click "Mark as answer" to the appropriate answer, so that it will help other members to find the solution quickly if they face a similar issue.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, December 19, 2019 5:51 AM