Codejock Forums Homepage
Forum Home Forum Home > General > Code Snippets > Visual Basic Code Snippets
  New Posts New Posts RSS Feed - MarkupLabel - capture image
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

MarkupLabel - capture image

 Post Reply Post Reply
Author
Message
chrisABC View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 June 2008
Status: Offline
Points: 258
Post Options Post Options   Thanks (0) Thanks(0)   Quote chrisABC Quote  Post ReplyReply Direct Link To This Post Topic: MarkupLabel - capture image
    Posted: 06 September 2009 at 8:02pm
Using the MarkupLabel control you can create an image on the label from XAML, for example a Chart.

Here is some VB code that allows you to capture this image, with examples showing how to copy it to the Clipboard, Save to disk as a BMP, or Print to printer.

It uses API calls, and stores the captured image in a PictureBox (which is not visible).  There may be easier or better ways to do this, but this seems to work fine.

You need a Form with a MarkupLabel on it. Add three Command Buttons and a PictureBox.

There is just one Function, and some Declarations
 (uploads/20090906_195728_CaptureMarkupLa.zip).
And the following in the Button Click events:

Private Sub cmdCopy_Click()
  Set Picture1.Picture = CaptureMarkupToPicturebox
  Clipboard.Clear ' Clear Clipboard.
  Clipboard.SetData Picture1.Image, vbCFBitmap
End Sub

Private Sub cmdPrint_Click()
  Set Picture1.Picture = CaptureMarkupToPicturebox
  Printer.PaintPicture Picture1.Image, 100, 100 ', p.Width * Resize, p.Height * Resize
  Printer.EndDoc
End Sub

Private Sub cmdSave_Click()
  Set Picture1.Picture = CaptureMarkupToPicturebox
  SavePicture Picture1.Picture, "C:\mychart.bmp"
End Sub



Also set the PictureBox properties (eg in Form_Load)
   Picture1.AutoSize = True
   Picture1.Visible = False



I added this code to the excellent XamlCharts sample (which you can download from this Forum).
Now I can Print, Copy, or Save the resulting Chart images.









Chris (Manchester, UK) -- www.abc6.co.uk ---- Using CodeJock ActiveX Suite 13.1.0 with Windows8, VB6 SP6
Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1354
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 07 September 2009 at 8:56am
Cool, nice work Chris! Thanks for this.
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6

Back to Top
Andrew666 View Drop Down
Groupie
Groupie


Joined: 15 October 2008
Status: Offline
Points: 27
Post Options Post Options   Thanks (0) Thanks(0)   Quote Andrew666 Quote  Post ReplyReply Direct Link To This Post Posted: 13 February 2010 at 4:14pm
This works fine if the XAML is fully visible - but if it is partially or totally hidden (e.g. if the containing form is not visible) then it won't work, as it depends on BitBlt.  Putting it in a PrintPreview control doesn't work either, as you can't do anything but print from that control.
 
It would be great if there was a "copy" method for the XAML markup label or access to a picture object...
 
 
--Andrew
Back to Top
drimage View Drop Down
Newbie
Newbie


Joined: 05 June 2013
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote drimage Quote  Post ReplyReply Direct Link To This Post Posted: 05 June 2013 at 10:57pm
the following are some codes about how to capture images in vb.
Public Function TwainAcquireToRasterEdgeImageImage(ByVal HANDLE As Integer) As Integer
' Acquire a single image, from the currently selected Data Source to a DIB handle
Public Function TwainAcquireToDib(ByVal HANDLE As IntPtr) As IntPtr
' Acquire a single image, from the currently selected Data Source to a file
Public Function TwainAcquireToFile(ByVal FilePath As String, ByVal HANDLE As Integer) As RasterEdgeImageStatus

Back to Top
arronlee View Drop Down
Newbie
Newbie


Joined: 04 September 2013
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote arronlee Quote  Post ReplyReply Direct Link To This Post Posted: 04 September 2013 at 11:26pm
Originally posted by drimage drimage wrote:

the following are some codes about how to capture images in vb.
Public Function TwainAcquireToRasterEdgeImageImage(ByVal HANDLE As Integer) As Integer
' Acquire a single image, from the currently selected Data Source to a DIB handle
Public Function TwainAcquireToDib(ByVal HANDLE As IntPtr) As IntPtr
' Acquire a single image, from the currently selected Data Source to a file
Public Function TwainAcquireToFile(ByVal FilePath As String, ByVal HANDLE As Integer) As RasterEdgeImageStatus


Hi, thanks for your sharing.
Becayse I am not so familiar with VB.NET processing, I focus more on capturing images using Twain Scanning in C#.NET. Can you offer some more tutorials about that?Thanks in advance.



Best regards,
Arron


Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.141 seconds.