473,396 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Get image of a control

How can I get (and save) the image of a control as a bitmap
(or other graphics file format)?

Thank you.

Max

Jul 21 '05 #1
5 1323
Hi Max,

The code below will capture the given Control's image and return a
BitMap.

This example captures the current Form (which is a Control itself)
Dim bmp As Bitmap
bmp = CaptureControl (Me)
bmp.Save ("FormX.bmp", Imaging.ImageFormat.Bmp)

Regards,
Fergus

<code>
Public Declare Function BitBlt Lib "gdi32" ( _
ByVal hDestDC As IntPtr, _
ByVal x As Integer, _
ByVal y As Integer, _
ByVal nWidth As Integer, _
ByVal nHeight As Integer, _
ByVal hSrcDC As IntPtr, _
ByVal xSrc As Integer, _
ByVal ySrc As Integer, _
ByVal dwRop As Integer _
) As Integer

'================================================= ==================
Public Function CaptureControl(ByVal c As Control) As Bitmap

Const SRCCOPY As Integer = &HCC0020

Dim bmp As Bitmap
Dim gDest, gSource As Graphics
Dim hdcSource, hdcDest As IntPtr

bmp = New Bitmap(c.Width, c.Height)

gSource = c.CreateGraphics
Try
gDest = Graphics.FromImage(bmp)
Try
hdcSource = gSource.GetHdc
Try
hdcDest = gDest.GetHdc
Try
BitBlt( _
hdcDest, 0, 0, _
c.Width, c.Height, _
hdcSource, 0, 0, SRCCOPY _
)
Finally
gDest.ReleaseHdc(hdcDest)
End Try
Finally
gSource.ReleaseHdc(hdcSource)
End Try
Finally
gDest.Dispose()
End Try
Finally
gSource.Dispose()
End Try

Return bmp
End Function
</code>
Jul 21 '05 #2
Thank you very much.

Is there a way to capture the image of the control also if
the control is not visible (or is partially covered by
another control)?
Thanks again.
Max

-----Original Message-----
Hi Max,

The code below will capture the given Control's image and return aBitMap.

This example captures the current Form (which is a Control itself) Dim bmp As Bitmap
bmp = CaptureControl (Me)
bmp.Save ("FormX.bmp", Imaging.ImageFormat.Bmp)

Regards,
Fergus


Jul 21 '05 #3
Hi Max,

We have a similar issue in the languages.vb group - when the app in
question doesn't have focus and is behind others. So far, with many things
tried, there's been no success. It seems that the Control must be on top and
visible in order to be captured.

If we get success there I'll post back here. If you get lucky first, it
would be great to hear from you! ;-)

Regards,
Fergus
Jul 21 '05 #4
Ok Fergus, thanks again.

I'll let you know if I find a solution.

Bye.

Max
-----Original Message-----
Hi Max,

We have a similar issue in the languages.vb group - when the app inquestion doesn't have focus and is behind others. So far, with many thingstried, there's been no success. It seems that the Control must be on top andvisible in order to be captured.

If we get success there I'll post back here. If you get lucky first, itwould be great to hear from you! ;-)

Regards,
Fergus
.

Jul 21 '05 #5
On Fri, 24 Oct 2003 09:15:07 +0100, Fergus Cooney wrote:
We have a similar issue in the languages.vb group - when the app in
question doesn't have focus and is behind others. So far, with many things
tried, there's been no success. It seems that the Control must be on top and
visible in order to be captured.

If we get success there I'll post back here. If you get lucky first, it
would be great to hear from you! ;-)


Btw. how to capture whole screen or at least some (visible) window from
..NET?

--
Best regards from
Kamil Burzynski
Jul 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Greg Christie | last post by:
I think I have a somewhat unique situation here, so I thought I should post it for the few poor souls who run across it and try to google it like I did. First of all, I was getting the following...
4
by: Ed Landau | last post by:
In VB6.0, I can put an image on a form and assign it's .picture property at run-time. In VBA (within MS Access), when I put down an image control on a form, it asks me for the source to the image...
4
by: Kevin Myers | last post by:
Hello, Please forgive my reposting of this note with hopefully a more relevant subject line. On an Access 2000 form under Windows 2000 I would like to use a Kodak Image Edit Control to...
12
by: Sharon | last post by:
I’m wrote a small DLL that used the FreeImage.DLL (that can be found at http://www.codeproject.com/bitmap/graphicsuite.asp). I also wrote a small console application in C++ (unmanaged) that uses...
0
by: Satish Appasani | last post by:
Hi: I have a ASP.NET form with Web layout which I've achieved using panels. In one of the tab I have a File control to upload Images. When I put a file in the file control and move to another...
10
by: David W. Simmonds | last post by:
I have a DataList control that has an Image control in the ItemTemplate. I would like to resize the image that goes into that control. I have a series of jpg files that are full size, full...
1
by: Brian | last post by:
Using A2K I have an image control on a report and use code to set the image.picture to the required jpg. 3 of the jpgs resize properly but 2 do not - they display much smaller than the image...
3
by: Raghu Raman | last post by:
Hi i want to save the read the image file and show it on a image control of a mobile webform .But the mobile control does not support html images ,so i am forced to use the server image control...
9
by: Mark Denardo | last post by:
This is related to another post I submitted, but I'll be more precise this time. I have a web page that contains an Image webcontrol that loads its image by: Image1.ImageUrl="<username>.jpg",...
0
by: SayamiSuchi | last post by:
hi I have taken one image control("image1") in the form("frmForm1.aspx").Now i want to one image ("mypic.jpeg") whose size is larger than the image control i.e image1.When i run the program, the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.