title: Converting Ink to Base64 and then to Image gets shapes cropped
body: <p>I am using the function below to convert some ink shapes I have drawn on a picturebox control to Base64</p>
  
  <pre><code>  Function GetBase64(ByVal InkCollector As InkCollector) As String
      Dim utf8 As UTF8Encoding = New UTF8Encoding()
      InkCollector.Enabled = False
      Return utf8.GetString(InkCollector.Ink.Save(PersistenceFormat.Base64InkSerializedFormat, CompressionMode.Maximum))
      InkCollector.Enabled = True
    End Function
  </code></pre>
  
  <p>I can then use the string to reproduce the sketch into a new image by feeding it to this function:</p>
  
  <pre><code>  Function Base64toImage(ByVal Base64 As String) As System.Drawing.Image
      Dim utf8 As UTF8Encoding = New UTF8Encoding()
      Dim imgSig As System.Drawing.Image
      Dim tmploadedInk As Ink = New Ink()
      Dim strGIF As String
      Dim imageBytes() As Byte
      Dim MS As MemoryStream
  
      'Load the Base64 String in Format(PersistenceFormat = Base64InkSerializedFormat) as ink
      tmploadedInk.Load(utf8.GetBytes(Base64))
      'Convert the ink to Base64 String in format (PersistenceFormat.Gif, CompressionMode.Maximum)
      strGIF = Convert.ToBase64String(tmploadedInk.Save(PersistenceFormat.Gif, CompressionMode.Maximum))
      'Convert Base64 String to Byte Array
      imageBytes = Convert.FromBase64String(strGIF)
  
      MS = New MemoryStream(imageBytes, 0, imageBytes.Length)
  
      ' Convert byte[] to Image
      MS.Write(imageBytes, 0, imageBytes.Length)
  
      imgSig = Image.FromStream(MS, True)
  
      Return imgSig
    End Function
  </code></pre>
  
  <p>This works fine except for the fact the shapes are cropped and therefore they get aligned to the top left corner of the generated image. If I use a line of code like below:</p>
  
  <pre><code>PictureBox1.Image = Signiture.Base64toImage(Signiture.GetBase64(Sketch_InkCollector))
  </code></pre>
  
  <p>The shapes appear at the top left and ignore the fact that they might have been drawn at the center of the original picture box. I believe that the positioning data is being properly saved into the Base64 string, but are somehow being ignored when the shapes are transferred to the image variable. The reason I believe this is because when I use the function below with the Base64 string, the shapes get placed properly in their original position.</p>
  
  <pre><code>  Sub SetBase64PictureBox(ByVal InkCollector As InkCollector, ByVal PictureBox As PictureBox, ByVal Base64 As String)
      Dim loadedInk As Ink = New Ink()
      Dim utf8 As UTF8Encoding = New UTF8Encoding()
      InkCollector.Enabled = False
      InkCollector.Ink.DeleteStrokes()        ' Clear all strokes
      loadedInk.Load(utf8.GetBytes(Base64))
      InkCollector.Ink = loadedInk
      InkCollector.Enabled = True
      PictureBox.Invalidate()
    End Sub
  </code></pre>
  
  <p>Thank you</p>
  
  <p>Update:</p>
  
  <p>Found a temporary solution in this link:</p>
  
  <p><a href="https://stackoverflow.com/questions/21008399/inkpicture-control-how-to-save-both-ink-and-image-to-an-image-file?rq=1">InkPicture control - How to save both ink and image to an image file</a></p>
  
  <p>It is not exactly what I was after but the end result is the same since I wanted to the combined picture and the ink strokes into an image to show in a PDF file.</p>