0

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
user3190447
  • 41
  • 1
  • 5
  • 1
    Where did you find the information indicating that `BitmapSource` has a `Save` method, and where did you learn about `ImageFormat`? – O. R. Mapper Jan 19 '14 at 09:08
  • Possible duplicate of [WPF image to byte array](http://stackoverflow.com/questions/553611/wpf-image-to-byte). Well, actually only the first of the question is answered there, but that seems to be all you need since you don't ask about SQLite in your post at all. – Dirk Jan 19 '14 at 09:24

1 Answers1

1

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

Community
  • 1
  • 1
alphabit
  • 454
  • 3
  • 8