I have BitmapImage:
BitmapImage image = new BitmapImage();
image.SetSource(memStream);
I want to save the image to the disk to see in the future. I can not find a work example of how to do this? The second question. I need to get the color of a pixel (like: Color cl=image.GetColorPixel(X,Y)
), how can I do that?
Thank you!
You can save BitmapImage in the following way.
image.png will be saved in the LocalFolder of the Application.
Hope it helps!
have a look at this link. there's a snippet showing some manipulation of WriteableBitmap http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.media.imaging.writeablebitmap.aspx
The example is reading but writing shouldn't be difficult.
To iterate through the pixels, have a look at PixelData Property.
You can't save or modify a
BitmapImage
. You need to use aWriteableBitmap
instead. If you really have no choice but start with a BitmapImage - check itsUriSource
property to either download the same image again or load aWriteableBitmap
with same content as the startingBitmapImage
. Note thatUriSource
might be null in some cases - even if theBitmapImage
was loaded by giving it a URI - it might be reset manually or by settingCacheMode
toBitmapCache
on anImage
that's using the givenBitmapImage
as itsSource
.If your trying to take a ui element from your xaml and save it as an image your out of luck. In wpf there is a method on writable bitmap that takes a UIelement as a parameter but that isn't there in windows store apps.
You can use DirectX but this is a very complicated approach. Most of the drawing apps on the store use JavaScript as its much easier to do the save.
Here's a code I found sometime ago in the web. I'm not sure, but if I rember right it was from the sdk samples or a winrt blog
It all comes down to the WritabelBitmap Image ( like the other already posted), create a decoder and push it to the stream.