0

I'm trying to load .RAW image from file and display it into canvas background (in WPF). File only contains HEX data (without header, but resolution and color is known) - photo viewer cannot display it (because there is no info in header), however in IrfranView after resolution and color is specified, it can be displayed.

Sorry if any duplicates exist, I tried to find some solutions carefully but unfortunately I couldn't find any solution, that worked int WPF. Mostly they were designed for Forms app, not WPF.

To specify my question: How to load .raw data from file, convert it to bitmap and display it in canvas background? Width and height, color (32bit RGBA) are known and pixel HEX raw data are stored in .raw file.

  • Install the appropriate codec. – Clemens May 29 '19 at 05:51
  • Or read the raw pixel data from the file into a byte array and [create a BitmapSource](https://learn.microsoft.com/en-us/dotnet/api/system.windows.media.imaging.bitmapsource.create?view=netframework-4.8#System_Windows_Media_Imaging_BitmapSource_Create_System_Int32_System_Int32_System_Double_System_Double_System_Windows_Media_PixelFormat_System_Windows_Media_Imaging_BitmapPalette_System_Array_System_Int32_) that you apply to the Source property of an Image element. – Clemens May 29 '19 at 08:20
  • Also note that "HEX raw data" makes no sense. It's just binary data that is typically displayed as hex values in an editor. – Clemens May 29 '19 at 08:23
  • Of course, my mistake. Thanks for your advice! – gladiatus55 May 29 '19 at 12:40

1 Answers1

0

Welcome to SO.

Be aware that this question may get flagged for deletion because you haven't posted any code and you haven't asked a specific question. "Please write code for me" questions generally aren't well received in these parts, you might want to read up on the site rules.

To answer your question though, you don't load images onto a Canvas, you load them into an Image element (which can itself be placed inside a Canvas if you want). There are samples on the Microsoft site showing showing how to create one of these from a raw array of integers.

Mark Feldman
  • 15,731
  • 3
  • 31
  • 58