I'm using the ink picture control and I'm having trouble getting my code to work. The inkpicture control is used for tablet pcs when the user draws inside the control. I just want to be able to save it to a jpeg. I've been stuck on this for days :)

Dim inkBounds As Rectangle
 
        With inkBounds
 
            .X = 0
 
            .Y = 0
 
            .Width = InkPicture1.Width
 
            .Height = InkPicture1.Height
 
        End With
 
        Dim img As Image
 
 
        img.Save(IO.Directory.GetCurrentDirectory() & "\test_out.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)

Recommended Answers

All 7 Replies

I don't have a tablet PC to test with, but if things work in the same way as with WinForms, your code should be following

InkPicture1.Image.Save(IO.Directory.GetCurrentDirectory() & "\test_out.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)

The code saves the image from the InkPicture1 control, not from the rectangle. I wasn't sure which one you actually wanted to save.

HTH

For some reason that gives me an "object not set to an instance of an object" exception. Any ideas to why that is?

Ok, here's a step-by-step test which control is not set

If InkPicture1 IsNot Nothing Then
  If InkPicture1.Image IsNot Nothing Then
    InkPicture1.Image.Save(IO.Directory.GetCurrentDirectory() & "\test_out.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
  Else
    ' InkPicture1.Image is nothing
  End If
Else
  ' InkPicture1 is nothing
End If

Put a message box or breakpoint on both Else parts to see if the InkPicture1 or InkPicture1.Image is not set. Can't think that something else could cause that error. This is without seeing more of your code. My guess is that you haven't assigned any initial image to InkPicture1.Image or you've somehow "lost" InkPicture1.Image in your code. In WinForms the image can be assign, for example, in the following way InkPicture1.Image = Image.FromFile("D:\test.jpg") , but I don't know how you do it with Tablet PC.

HTH

Okay I put that code and breakpoints that you suggested in there and it looks like the InkPicture1.image is what its stopping at. I tried doing something like this

If Inkpicture1.Ink.Strokes.Count > 0 Then
            Inkpicture1.Image.Save(IO.Directory.GetCurrentDirectory() & "\test_out.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
        End If

but that didnt seem to help. Thats all my code i don't have any more. I still keep getting that exception and I'm still new with vb and the inkpicture :)

I did some googling and found out that InkPicture control does not even have Image property :)

InkEdit control has SaveFile method (see Using InkEdit, InkPicture, and Enhancing the Appearance of Ink).

InkPicture doesn't seem to have any methods for loading and saving it's content, but I found the following article: Save InkPicture image with Ink in common image formats. The code snippet is written in C# but it's quite straight forward to convert it to VB. If you're not familiar with C#, use Convert C# to VB.NET for code conversion.

HTH

commented: Always helpfull +1

Thank you for your help teme64! I finally got it to work :)

HI there, could i please ask how you managed to get this solved as i am experiencing the same issue

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.