Copy One Bitmap to another - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Copy One Bitmap to another

CitizenOlekCitizenOlek Posts: 53Member
Hi,

How can I copy one Bitmap to another Bitmap?

Comments

  • seancampbellseancampbell Pennsylvania, USAPosts: 684Member ✭✭✭
    Dim Bmp as Bitmap
    Dim Bmp2 as Bitmap
    Bmp = Bmp2

    ?

  • CitizenOlekCitizenOlek Posts: 53Member
    : Dim Bmp as Bitmap
    : Dim Bmp2 as Bitmap
    : Bmp = Bmp2
    :
    : ?
    :
    :
    Hi Sean,

    That was the first thing I tried, and it had no effect. I assumed that because I didn't use a graphics object to draw the one Bitmap to the other that the code was just Null. I'm just guessing.

    What I'm trying to do is create an Undo function for a drawing program I wrote.

    So my logic goes - Make a Bitmap copy of what's happening on the screen, called BMPundo1, and when the User hits 'Undo' replace the Bitmap shown on the screen, called BMPwithGL, with BMPundo1.

    One problem I've had while trying to figure this out is that several versions of code I've found that succeeds in doing what I want, lock up the target Bitmap objects. preventing me from accessing them any further. To clarify, I am able to draw OK, then I hit Undo, the image changes properly to the stored 'Undo Image', now I can no longer Draw, or Clear the screen, etc.

    The following code seems to work, but I'm not sure if it's proper or the best.
    [code]
    Private Sub StoreUndo()
    BMPundo1 = DirectCast(BMPwithGL.Clone, Bitmap)
    End Sub

    Private Sub btnUndo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUndo.Click
    Dim BMPwithGL As Bitmap = BMPundo1
    PictureBox1.Image = BMPwithGL
    End Sub
    [/code]
  • seancampbellseancampbell Pennsylvania, USAPosts: 684Member ✭✭✭
    I think your code is fine
  • CitizenOlekCitizenOlek Posts: 53Member
    : I think your code is fine

    The part of my code that worries me is:
    [code]
    Dim BMPwithGL As Bitmap = BMPundo1
    [/code]
    Beacause, at the start of my Application where I Dimension all my variables, I have already Dim'ed BMPwithGL, thusly:
    [code]
    Dim BMPwithGL As Bitmap
    [/code]
    Is it proper to Dim the same variable over and over again like this?
  • seancampbellseancampbell Pennsylvania, USAPosts: 684Member ✭✭✭
    That's fine, you could change it up to ReDim though
  • CitizenOlekCitizenOlek Posts: 53Member
    : That's fine, you could change it up to ReDim though
    :
    Thank You.
Sign In or Register to comment.