Snapshot .ToByteArray() thoughts

Nov 4, 2011 at 5:37 PM


I just had a comment on the Snapshot class of TestApi. I've been wanting to modify images in memory and thus was thinking about adding a .ToByteArray() method to the Snapshot class to go along side .ToFile(). Would there be any significant downside to this addition?

/// <summary>
/// Writes the current Snapshot to a byte array
/// </summary>
/// <param name="imageFormat">The image format to be used</param>
/// <returns></returns>
public byte[] ToByteArray(ImageFormat imageFormat)
    byte[] data = null;
    using (var stream = new MemoryStream())
        CreateBitmapFromSnapshot().Save(stream, imageFormat);
        data = stream.ToArray();
    return data;

Any thoughts are greatly appreciated. Thank you! 

May 23, 2012 at 8:05 PM

I know this post is a bit old, but I think adding this is a great idea. I may try to add it in my first submission if you haven't already.