0

I'm saving the inkcavas strokes inside an byte[] and using a field inside a database do store it.

So far it's working. I can store and retrieve the strokes.

But I also need to print it in a PDF file. I'm using migradoc to do so, and it's not working.

If I store an image like jpg or gif inside the database, I can retrieve it and print it into pdf, but the same doesn't apply to ink strokes. I believe it's because the format.

//Instanciating an memory stream from byte[]
System.IO.MemoryStream myMemStream = new System.IO.MemoryStream(myByteArr);

//Trying to convert it into image, here's where the error happens if the array contains strokes. 
//It works if I use another image format
System.Drawing.Image fullsizeImage = System.Drawing.Image.FromStream(myMemStream);
  • In case you've used `StrokeCollection.Save` to serialize the Strokes, this does not generate an encoded bitmap frame that could be decoded by Image.FromStream or a WPF BitmapDecoder. It's just not a bitmap. – Clemens Jun 23 '20 at 12:28
  • Convert your inkcanvas to a picture and work with that. Use rendertargetbitmap. Start reading here https://learn.microsoft.com/en-us/dotnet/framework/wpf/graphics-multimedia/how-to-encode-a-visual-to-an-image-file – Andy Jun 23 '20 at 12:30
  • @Clemens That's what I did. – Thyago Campos Jun 23 '20 at 12:35
  • @Andy, while I was generating the PDF, I tried to create a inkcanvas control on code, just to receive the byte array and then use BmpBitmapEncoder to get generate the image, but doesn't work. A full black image is generated. If I use this method inside a window, it works. – Thyago Campos Jun 23 '20 at 12:35
  • When you create the InkCanvas in code and do not add it to a visual tree, you must manually force its layout. You have to call Measure and Arrange, perhaps also InvalidateVisual. Or you do something like this: https://stackoverflow.com/a/51205585/1136211 – Clemens Jun 23 '20 at 12:51

0 Answers0