WPF C#: load a pixmap data block into an Image control

518 Views Asked by At

I have an image in the form of a byte array of a certain size. It is not important to know where it comes from. It has some further parameters: w,h,dn. I do not use dn (can get it if needed however) but color which was calculated this way

if (!savealpha && dn > 1) dn--;} 

and then

 switch (dn)    
 {  
    default:    
    case 1: color = 0; break;   
    case 2: color = 4; break;   
    case 3: color = 2; break;   
    case 4: color = 6; break;   
 }

I need to put this pixmap into an Image control in a C# application.

How to create a c# bitmap ?

1

There are 1 best solutions below

0
Ani On

Implement a custom BitmapSource that reads your pixmap and set that in your XAML. Here's a sample. http://www.i-programmer.info/programming/wpf-workings/822-custom-bitmapsource.html