Making Bitmaps and Graphics objects - two ways

  • Thread starter Thread starter **Developer**
  • Start date Start date
D

**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)
 
**Developer** said:
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.
 
..
'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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top