Reputation: 51
How to convert Convert Bitmap to Byte Array and save it to Sqlite. Im using c# and xaml
Here's my code
BitmapSource image = new BitmapImage(new Uri("ms-appx:///Assets/BG.jpg", UriKind.Absolute));
using (MemoryStream ms = new MemoryStream())
{
WriteableBitmap btmMap = new WriteableBitmap
(image.PixelWidth, image.PixelHeight);
// write an image into the stream
image.Save(ms, ImageFormat.Jpeg); // error, Save and ImageFormat
}
Error for "Save":
'Windows.UI.Xaml.Media.Imaging.BitmapSource' does not contain a definition for 'Save' and no extension method 'Save' accepting a first argument of type 'Windows.UI.Xaml.Media.Imaging.BitmapSource' could be found (are you missing a using directive or an assembly reference?)
Error for ImageFormat:
The name 'ImageFormat' does not exist in the current context
Upvotes: 0
Views: 754
Reputation: 454
A way could probably be to convert the BitmapImage to a normal Bitmap and save that stream, then.
See: Converting BitmapImage to Bitmap and vice versa
Hope this helps
Upvotes: 1