Making Bitmaps and Graphics objects - two ways

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • **Developer**

    #1

    Making Bitmaps and Graphics objects - two ways

    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 TmpBitmapGraphi cs As Graphics = PictureBoxPic.C reateGraphics

    Dim TmpBitmap As New Drawing.Bitmap( PictureBoxPic.C lientSize.Width ,
    PictureBoxPic.C lientSize.Heigh t, TmpBitmapGraphi cs)

    TmpBitmapGraphi cs.Dispose() 'Did the above to preserver the PixelFormat

    TmpBitmapGraphi cs = Graphics.FromIm age(TmpBitmap)

    'This also works (2 lines)

    Dim TmpBitmap As New Drawing.Bitmap( PictureBoxPic.C lientSize.Width ,
    PictureBoxPic.C lientSize.Heigh t)

    Dim TmpBitmapGraphi cs As Graphics = Graphics.FromIm age(TmpBitmap)


  • I Don't Like Spam

    #2
    Re: Making Bitmaps and Graphics objects - two ways

    **Developer** wrote:[color=blue]
    > 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 TmpBitmapGraphi cs As Graphics = PictureBoxPic.C reateGraphics
    >
    > Dim TmpBitmap As New Drawing.Bitmap( PictureBoxPic.C lientSize.Width ,
    > PictureBoxPic.C lientSize.Heigh t, TmpBitmapGraphi cs)
    >
    > TmpBitmapGraphi cs.Dispose() 'Did the above to preserver the PixelFormat
    >
    > TmpBitmapGraphi cs = Graphics.FromIm age(TmpBitmap)
    >
    > 'This also works (2 lines)
    >
    > Dim TmpBitmap As New Drawing.Bitmap( PictureBoxPic.C lientSize.Width ,
    > PictureBoxPic.C lientSize.Heigh t)
    >
    > Dim TmpBitmapGraphi cs As Graphics = Graphics.FromIm age(TmpBitmap)
    >
    >[/color]

    'Set it to the picture boxes graphics object
    1. Dim TmpBitmapGraphi cs As Graphics = PictureBoxPic.C reateGraphics

    2. Dim TmpBitmap As New Drawing.Bitmap( PictureBoxPic.C lientSize.Width ,
    PictureBoxPic.C lientSize.Heigh t, TmpBitmapGraphi cs)

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

    ' Set the object to something totally new.
    4. TmpBitmapGraphi cs = Graphics.FromIm age(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.

    Comment

    • **Developer**

      #3
      Re: Making Bitmaps and Graphics objects - two ways

      ..[color=blue]
      >
      > 'Set it to the picture boxes graphics object
      > 1. Dim TmpBitmapGraphi cs As Graphics = PictureBoxPic.C reateGraphics
      >
      > 2. Dim TmpBitmap As New Drawing.Bitmap( PictureBoxPic.C lientSize.Width ,
      > PictureBoxPic.C lientSize.Heigh t, TmpBitmapGraphi cs)
      >
      > 'Kill this object (this has the same effect as if you never did line 1[/color]

      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?

      [color=blue]
      > 3. TmpBitmapGraphi cs.Dispose() 'Did the above to preserver the PixelFormat
      >
      > ' Set the object to something totally new.
      > 4. TmpBitmapGraphi cs = Graphics.FromIm age(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.[/color]


      Comment

      Working...