none
API Cliboard : Can a WritableBitmap to clipboad ?

    Question

  • Hi,

     

    With the Clipboard API, can i copy a WritableBitmap or something like that to my clipboard ?

     It's very usefull with charts.

     

    Regards,

    rg701653

    Friday, November 27, 2009 7:03 AM

All replies

  • It is only possible to use (unicode) text with the current implementation of the Clipboard API.

    Saturday, November 28, 2009 4:40 AM
  •  Ok thanks for your reply.

     

    I will search if it exists a workaround.

    Monday, November 30, 2009 2:35 AM
  • You could convert the WriteableBitmap data to a byte[] array, encode it as Base64 and copy it to the Clipboard as text. See my blog post if you wan to know how to convert the WriteableBitmap's data: Convert, Encode And Decode Silverlight WriteableBitmap Data.

    If you have the byte array, convert it to base64:

    byte[] data = bitmap.ToByteArray();
    string dataB64 = Convert.ToBase64String(data);
     
    Wednesday, December 02, 2009 6:22 AM
  •  Ok.

    I thank use the same solution, but i have one question :

    Javascript-side : i have the WritableBitmap encoded, how to create a picture with un byte array ?

    Wednesday, December 02, 2009 6:42 AM
  • Instead of converting the WriteableBitmap to a byte array you should encode it as a JPEG or an other image format and send that as base64 string. Then on the JScript side you need to decode the base64 string and you have a JPEG file format.

    using(MemoryStrem memStream = new MemoryStream())
    {
       EncodeJpeg(bitmap, memStream);
       byte[] data = memStream.ToArray();
       string dataB64 = Convert.ToBase64String(data);
    }

    Again, see my Convert, Encode And Decode Silverlight WriteableBitmap Data blog post for the EncodeJpeg() method. Big Smile

    Wednesday, December 02, 2009 8:05 AM
  • Great !

    I will test it !

     

    Thank you.

    rg701653

    Wednesday, December 02, 2009 8:18 AM