Re: Beginner's question
- From: "Bob Powell [MVP]" <bob@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 25 Oct 2005 21:04:29 +0200
Ah, ok, that sheds some light on it.
Thanks.
--
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting
http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
"B. Chernick" <BChernick@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:04FF4825-78AD-4650-B15C-6256D97E76B0@xxxxxxxxxxxxxxxx
> My apologies to both of you. I over-simplified. Here is the entire
> function, the result of trial-and-error and some samples I found on the
> web.
> The 1st version of g1 works (as a screen capture of the visible portion of
> the form only). The second one returns a blank. Note to Bob: No, the
> MyImage.Save would not work if called directly after the 'Dim MyImage'
> statement.
>
> ------------------------------------
>
> Function CaptureForm1() As Bitmap
>
> Dim g1 As Graphics = Me.CreateGraphics
> 'Dim g1 As Graphics = Graphics.FromImage(pb1.Image)
>
> Dim MyImage As New Bitmap(Me.pb1.Width, Me.pb1.Height, g1)
> Dim g2 As Graphics = Graphics.FromImage(MyImage)
> Dim dc1 As IntPtr = g1.GetHdc()
> Dim dc2 As IntPtr = g2.GetHdc()
> BitBlt(dc2, 0, 0, Me.pb1.Image.Width, Me.pb1.Image.Height, dc1, 0,
> 0, 13369376)
>
> g1.ReleaseHdc(dc1)
> g2.ReleaseHdc(dc2)
>
> MyImage.Save("c:\abc.bmp")
> Return MyImage
> End Function
>
> ------------------------
> "Bob Powell [MVP]" wrote:
>
>> Do you really get a screen capture?? This sounds odd to me.
>>
>> Can you confirm this is the case.
>>
>> --
>> Bob Powell [MVP]
>> Visual C#, System.Drawing
>>
>> Ramuseco Limited .NET consulting
>> http://www.ramuseco.com
>>
>> Find great Windows Forms articles in Windows Forms Tips and Tricks
>> http://www.bobpowell.net/tipstricks.htm
>>
>> Answer those GDI+ questions with the GDI+ FAQ
>> http://www.bobpowell.net/faqmain.htm
>>
>> All new articles provide code in C# and VB.NET.
>> Subscribe to the RSS feeds provided and never miss a new article.
>>
>>
>>
>>
>>
>> "B. Chernick" <BChernick@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
>> news:462E2BE3-57DA-455C-BA30-BC99D1F6DF6A@xxxxxxxxxxxxxxxx
>> >I am trying to capture an image from a picturebox pb1, the first step in
>> > creating a print routine.
>> >
>> > 'Dim g1 As Graphics = Me.CreateGraphics
>> > Dim g1 As Graphics = Graphics.FromImage(pb1.Image)
>> >
>> > Dim MyImage As New Bitmap(Me.pb1.Width, Me.pb1.Height, g1)
>> > MyImage.Save("c:\abc.bmp")
>> >
>> > If I use the first 'Dim g1', I essentially get a screen capture. (This
>> > is
>> > useless as the picturebox and the image are far larger than the visible
>> > screen.) If I use the second version, I get a blank image, although it
>> > is
>> > the correct size. What am I doing wrong?
>>
>>
>>
.
- Follow-Ups:
- Re: Beginner's question
- From: B. Chernick
- Re: Beginner's question
- References:
- Re: Beginner's question
- From: Bob Powell [MVP]
- Re: Beginner's question
- From: B. Chernick
- Re: Beginner's question
- Prev by Date: Re: Beginner's question
- Next by Date: Printing without callbacks
- Previous by thread: Re: Beginner's question
- Next by thread: Re: Beginner's question
- Index(es):
Relevant Pages
|