locked
Saving a BitmapImage/Image to a file.

    Question

  • How can I do

    System.Drawing.Image myImage = new System.Drawing.Image();
    myImage.Save("c:\\image.gif", System.Drawing.Imaging.ImageFormat.Gif);
    with a
    Windows.UI.Xaml.Media.Imaging.BitmapImage

    object?


    Mediocre Access 2010 | (Baby) Beginner C Sharp | OK at Active Directory (2012) | Fragmented understanding of DNS/DHCP | Laughable experience with Group Policy | Expert question asker on MSDN Forums





    • Edited by UpTide Tuesday, February 10, 2015 8:20 PM
    Tuesday, February 10, 2015 8:16 PM

Answers

  • It depends on what IStorageItem is. Assuming it's a file, call its CopyAsync method or call OpenAsync to get a stream to read out the data and do what you want with it. If it's a folder then I don't know what it means to write it out as an image.
    • Marked as answer by UpTide Thursday, February 12, 2015 1:04 AM
    Thursday, February 12, 2015 1:00 AM
    Owner

All replies

  • You cannot extract the pixels from a BitmapImage. You need to either get the data from the original that you created the BitmapImage from or you can use a WriteableBitmap which exposes its PixelBuffer.

    Once you have the WriteableBitmap's PixelBuffer you can encode it to a GIF file with a BitmapEncoder. See How to save WriteableBitmap to image file in Windows store apps for a sample.

    Tuesday, February 10, 2015 8:23 PM
    Owner
  • I have the IRandomAccessStreamWithContentType object that I made it with.

    Mediocre Access 2010 | (Baby) Beginner C Sharp | OK at Active Directory (2012) | Fragmented understanding of DNS/DHCP | Laughable experience with Group Policy | Expert question asker on MSDN Forums

    Tuesday, February 10, 2015 8:31 PM
  • If you have the original file information then just save that out. No need for an extra conversion.
    Tuesday, February 10, 2015 8:50 PM
    Owner
  • So how can I write an

    IReadOnlyList<IStorageItem>

    to disk, as an image?


    Mediocre Access 2010 | (Baby) Beginner C Sharp | OK at Active Directory (2012) | Fragmented understanding of DNS/DHCP | Laughable experience with Group Policy | Expert question asker on MSDN Forums

    Wednesday, February 11, 2015 10:02 PM
  • It depends on what IStorageItem is. Assuming it's a file, call its CopyAsync method or call OpenAsync to get a stream to read out the data and do what you want with it. If it's a folder then I don't know what it means to write it out as an image.
    • Marked as answer by UpTide Thursday, February 12, 2015 1:04 AM
    Thursday, February 12, 2015 1:00 AM
    Owner
  • Thanks, very helpful!

    Mediocre Access 2010 | (Baby) Beginner C Sharp | OK at Active Directory (2012) | Fragmented understanding of DNS/DHCP | Laughable experience with Group Policy | Expert question asker on MSDN Forums

    Thursday, February 12, 2015 1:04 AM