Print Page | Close Window

MarkupLabel - capture image

Printed From: Codejock Forums
Category: General
Forum Name: Visual Basic Code Snippets
Forum Description: Visual Basic Code Snippets
URL: http://forum.codejock.com/forum_posts.asp?TID=15125
Printed Date: 21 November 2024 at 5:59am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: MarkupLabel - capture image
Posted By: chrisABC
Subject: MarkupLabel - capture image
Date 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 - 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.

uploads/20090906_195728_CaptureMarkupLa.zip -









-------------
Chris (Manchester, UK) -- www.abc6.co.uk ---- Using CodeJock ActiveX Suite 13.1.0 with Windows8, VB6 SP6



Replies:
Posted By: jpbro
Date 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



Posted By: Andrew666
Date 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


Posted By: drimage
Date Posted: 05 June 2013 at 10:57pm
the following are some codes about how to http://www.rasteredge.com/how-to/vb-net-imaging/twain-scanning/" rel="nofollow - 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



Posted By: arronlee
Date Posted: 04 September 2013 at 11:26pm
Originally posted by drimage drimage wrote:

the following are some codes about how to http://www.rasteredge.com/how-to/vb-net-imaging/twain-scanning/" rel="nofollow - 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 http://www.rasteredge.com/how-to/csharp-imaging/twain-scanning/" rel="nofollow -



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net