none
Combining Ink object and the InkPicture.image object RRS feed

  • Question

  • Hi.

     

    Does anyone know how to take an inkPicture.Ink object and insert it into, or combine it with, the underlying inkPicture.image so I can save the ink and the image as 1 file ( i.e. .tif) and can be viewed with a comon image viewer?

     

    Thanks.

    Marshall

    Friday, November 17, 2006 10:19 PM

Answers

  • Hi Marshall,

    you can use the Renderer object to render the ink to the Graphics object of the Image.

    private void SaveInkAndImageAsTif()
    {
        using (Graphics g = Graphics.FromImage(inkPicture1.Image))
        {
            inkPicture1.Renderer.Draw(g, inkPicture1.Ink.Strokes);
        }
        inkPicture1.Image.Save("test.tif", ImageFormat.Tiff);
    }

    Some rendering aspects of the ink (anti-aliasing, transparency) will be lost when using the above code. If you want to preserve it, you can apply the techniques explained under "Antialiasing and Transparency" at [1].

    In Windows Vista, we have added a new overload to the Renderer.Draw() method that takes a Bitmap reference and does the best possible rendering for you automatically.

    Thanks, Stefan Wick

    [1] http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dntablet/html/tbconprintingink.asp

    [2] http://msdn2.microsoft.com/en-gb/library/ms569826.aspx

     

    Sunday, November 19, 2006 3:40 PM

All replies

  • Hi Marshall,

    you can use the Renderer object to render the ink to the Graphics object of the Image.

    private void SaveInkAndImageAsTif()
    {
        using (Graphics g = Graphics.FromImage(inkPicture1.Image))
        {
            inkPicture1.Renderer.Draw(g, inkPicture1.Ink.Strokes);
        }
        inkPicture1.Image.Save("test.tif", ImageFormat.Tiff);
    }

    Some rendering aspects of the ink (anti-aliasing, transparency) will be lost when using the above code. If you want to preserve it, you can apply the techniques explained under "Antialiasing and Transparency" at [1].

    In Windows Vista, we have added a new overload to the Renderer.Draw() method that takes a Bitmap reference and does the best possible rendering for you automatically.

    Thanks, Stefan Wick

    [1] http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dntablet/html/tbconprintingink.asp

    [2] http://msdn2.microsoft.com/en-gb/library/ms569826.aspx

     

    Sunday, November 19, 2006 3:40 PM
  • Brilliant.

     

    I was hoping for a simple solution. I actually had the key line 'Renderer.Draw(g, inkPicture1.Ink.Strokes);' in my code, just at the wrong spot. I was stomping on the graphics object after doing the rendering action.

     

    Thanks a lot.

    Marshall

     

     

    Monday, November 20, 2006 3:46 PM
  • I was wondering if you could translate this into VBA using an InkPicture control?  I've played around with it a little, but the control doesn't seem to have the same properties.  I'm basically trying to do the same thing, save the image and the ink from the control together to a gif so I can print them together on a report.

    Thanks! -- afs

    Monday, January 8, 2007 9:17 PM
  •  

    This what I'm using. It's VB.NET, but I think you will do the identical thing in VBA if you have access to the GDI+ Lib. I created a module that inherits the inkpicture object and added the following methods to it:

     

    Imports Microsoft.Ink
    Public Class InkPictureEx

    Inherits InkPicture

    Public Function GetCombinedInkAndImage(ByRef inkBounds As Rectangle) As Image

    '// check for ink objects
    If Me.Ink.Strokes.Count > 0 The

    '// Combine images
    CombineInkAndImage(inkBounds)

    '// return combined image and ink
    GetCombinedInkAndImage = Me.Image

    Else

    '// if no ink, then return original image
    GetCombinedInkAndImage = Me.Image

    End If

    End Function

    Private Sub CombineInkAndImage(ByRef Inkbounds As Rectangle)
    '// Inkbounds is the boundary definition of the valid drawing area for ink in pixels

    '// Combine images
    Using g As Graphics = Graphics.FromImage(Me.Image)

    '// define the bounds of the clip region for the ink object
    Dim point As Point

    point.X = Inkbounds.X
    point.Y = Inkbounds.Y
    Renderer.PixelToInkSpace(g, point)
    Inkbounds.X = point.X
    Inkbounds.Y = point.Y

    point =
    New Point

    point.X = Inkbounds.Height
    point.Y = Inkbounds.Width
    Renderer.PixelToInkSpace(g, point)
    Inkbounds.Height = point.X
    Inkbounds.Width = point.Y

    '// set the bounds of the ink clip region
    Ink.Clip(Inkbounds)

    '// combine ink and image
    Me.Renderer.Draw(g, Me.Ink.Strokes)

    End Using

    '// clear the ink object
    Me.Ink.DeleteStrokes()

    End Sub

    End Class

     Hope this helps.

     

    Tuesday, January 9, 2007 4:51 PM
  • Thanks Marshall,

    I think I get the idea, but I can't find the reference that will let me use the Graphics class - I set a reference in VBA (Access) to the system.drawing.dll that the c++ PrintingInk program from the MS Tablet SDK example uses, but the Graphics object does not appear as part of the deal in Access.  Is that class included in your GDI+ Lib?

    Thanks again for your help -- Al Smith

    Tuesday, January 9, 2007 10:54 PM
  • Yes, it is. I use the System.Drawing namespace in .NET

    There is a GDI+ SDK available at this link:
    http://www.microsoft.com/downloads/details.aspx?familyid=6a63ab9c-df12-4d41-933c-be590feaa05a&displaylang=en

    There is documentation on it's use there as well. I know C++ programmers can access it. But I'm not sure how you would go about using it in VBA. GDI (classic) can be access via an API, but can VBA do API calls? I'm  not sure. I'd download the GDI+ and give that a shot. It's the same GDI+ lib used in .NET.

    Good luck.


    Tuesday, January 9, 2007 11:07 PM
  • Thanks Marshall.

     

    In case anyone else is looking to save TIF images, this is how I did it after using the code Marshall posted above:

     

    Dim inkBounds As Rectangle

    With inkBounds

    .X = 0

    .Y = 0

    .Width = InkPicture1.Width

    .Height = InkPicture1.Height

    End With

    Dim img As Image = GetCombinedInkAndImage(inkBounds)

    img.Save(Directory.GetCurrentDirectory() & "\test_out.tif", System.Drawing.Imaging.ImageFormat.Tiff)

     

    Saturday, October 18, 2008 5:43 PM
  • Thanks for the code. I'm able to save the image with ink as a file on a disk. It's possible to save the file into database as a binary? Can anyone advise me how to do it.

     

    this what i'm doing before, only can save the ink. I'm using vb.net 2003 and sql 2000

     

    '//check any writing add into the panel

    If Me.InkPictVehicle.Ink.Strokes.Count = 0 Then

    '//no writing

    MessageBox.Show("There is no new ink added.")

    Exit Sub

    Else

    Dim gifInk As Stream

    Dim saveInk() As Byte

    Dim image As SqlParameter

    '//has writing - insert data into ink table

    saveInk = Me.InkPictVehicle.Ink.Save(PersistenceFormat.Gif, CompressionMode.Maximum)

     

    sql = "insert into inkGIF values(@vID, @pID, @inkPicGif"

    cmd = New SqlCommand(sql, temr)

    cmd.Parameters.Add("@vID", Me._vID)

    cmd.Parameters.Add("@pID", Me._patID)

    image.Value = saveInk

    image.Size = saveInk.Length

    Try

    temr.Open()

    cmd.ExecuteNonQuery()

    Catch ex As Exception

    MessageBox.Show(ex.ToString())

    Finally

    temr.Close()

    cmd = Nothing

    End Try

     

    Me.InkPictVehicle.Ink.DeleteStrokes()

    MessageBox.Show("Writing saved.", "Information", MessageBoxButtons.OK)

    End If

    Thursday, November 27, 2008 3:53 AM