Home All Groups Group Topic Archive Search About

Making Bitmaps and Graphics objects - two ways

Author
4 Feb 2006 2:32 PM
**Developer**
Stumbling through I find both of the following appear to work the same.

I'm guessing there is a difference that I'm just not aware of.

Can someone enlighten me?



Thanks





'This works (4 lines)

Dim TmpBitmapGraphics As Graphics = PictureBoxPic.CreateGraphics

Dim TmpBitmap As New Drawing.Bitmap(PictureBoxPic.ClientSize.Width,
PictureBoxPic.ClientSize.Height, TmpBitmapGraphics)

TmpBitmapGraphics.Dispose() 'Did the above to preserver the PixelFormat

TmpBitmapGraphics = Graphics.FromImage(TmpBitmap)

'This also works (2 lines)

Dim TmpBitmap As New Drawing.Bitmap(PictureBoxPic.ClientSize.Width,
PictureBoxPic.ClientSize.Height)

Dim TmpBitmapGraphics As Graphics = Graphics.FromImage(TmpBitmap)

Author
4 Feb 2006 7:47 PM
I Don't Like Spam
**Developer** wrote:
Show quoteHide quote
> Stumbling through I find both of the following appear to work the same.
>
> I'm guessing there is a difference that I'm just not aware of.
>
> Can someone enlighten me?
>
>
>
> Thanks
>
>
>
>
>
> 'This works (4 lines)
>
> Dim TmpBitmapGraphics As Graphics = PictureBoxPic.CreateGraphics
>
> Dim TmpBitmap As New Drawing.Bitmap(PictureBoxPic.ClientSize.Width,
> PictureBoxPic.ClientSize.Height, TmpBitmapGraphics)
>
> TmpBitmapGraphics.Dispose() 'Did the above to preserver the PixelFormat
>
> TmpBitmapGraphics = Graphics.FromImage(TmpBitmap)
>
> 'This also works (2 lines)
>
> Dim TmpBitmap As New Drawing.Bitmap(PictureBoxPic.ClientSize.Width,
> PictureBoxPic.ClientSize.Height)
>
> Dim TmpBitmapGraphics As Graphics = Graphics.FromImage(TmpBitmap)
>
>

'Set it to the picture boxes graphics object
1. Dim TmpBitmapGraphics As Graphics = PictureBoxPic.CreateGraphics

2. Dim TmpBitmap As New Drawing.Bitmap(PictureBoxPic.ClientSize.Width,
PictureBoxPic.ClientSize.Height, TmpBitmapGraphics)

'Kill this object (this has the same effect as if you never did line 1
3. TmpBitmapGraphics.Dispose() 'Did the above to preserver the PixelFormat

' Set the object to something totally new.
4. TmpBitmapGraphics = Graphics.FromImage(TmpBitmap)

So it seems like this way of doing it is pretty pointless, since you
create the object and then just kill it right after.
Author
6 Feb 2006 12:45 AM
**Developer**
..
>
> 'Set it to the picture boxes graphics object
> 1. Dim TmpBitmapGraphics As Graphics = PictureBoxPic.CreateGraphics
>
> 2. Dim TmpBitmap As New Drawing.Bitmap(PictureBoxPic.ClientSize.Width,
> PictureBoxPic.ClientSize.Height, TmpBitmapGraphics)
>
> 'Kill this object (this has the same effect as if you never did line 1

Except Line 2 used it.  Not sure about the effect though. Can an image in a
picturebox have different DPI? Or does it match the screen?


Show quoteHide quote
> 3. TmpBitmapGraphics.Dispose() 'Did the above to preserver the PixelFormat
>
> ' Set the object to something totally new.
> 4. TmpBitmapGraphics = Graphics.FromImage(TmpBitmap)
>
> So it seems like this way of doing it is pretty pointless, since you
> create the object and then just kill it right after.