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
2
  • 1
    Where did you find the information indicating that BitmapSource has a Save method, and where did you learn about ImageFormat? Commented Jan 19, 2014 at 9:08
  • Possible duplicate of WPF image to byte array. 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. Commented Jan 19, 2014 at 9:24

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.