I've created Image object in xaml code:
<Image Name="Square" Source="Square.png" Height="400" Width="640"/>
In code-behind I've written:
WriteableBitmap bitmap = new WriteableBitmap((int)Square.Width, (int)Square.Height, 96, 96, PixelFormats.Rgb24, null);
If I'm creating pixel array, puting to WritableBitmap and then to Image like this:
int width = 300;
int height = 300;
WriteableBitmap bitmap = new WriteableBitmap(width, height, 96, 96, PixelFormats.Rgb24, null);
uint[] pixels = new uint[width * height];
bitmap.WritePixels(new Int32Rect(0, 0, 300, 300), pixels, width * 4, 0);
**Square.Source = bitmap;**
I haven't any problem, but when I'm trying to load my image created in xaml code to WritableBitmap, I can't do this:
WriteableBitmap bitmap = new WriteableBitmap((int)Square.Width, (int)Square.Height, 96, 96, PixelFormats.Rgb24, null);
bitmap = Square.Source; // Cannot implicitly convert type 'System.Windows.Media.ImageSource' to 'System.Windows.Media.Imaging.WriteableBitmap'
So if I can't convert type 'System.Windows.Media.ImageSource' to 'System.Windows.Media.Imaging.WriteableBitmap', why I can convert 'System.Windows.Media.Imaging.WriteableBitmap' to 'System.Windows.Media.ImageSource'?
Square.Source = bitmap;
bitmap = Square.Source; // Why it does not work?
Thanks for any help.