VB.NET

Moderators: seancampbell
Number of threads: 4022
Number of posts: 10035

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Copy One Bitmap to another Posted by CitizenOlek on 4 Jul 2007 at 4:07 PM
Hi,

How can I copy one Bitmap to another Bitmap?
Report
Re: Copy One Bitmap to another Posted by seancampbell on 5 Jul 2007 at 6:27 AM
Dim Bmp as Bitmap
Dim Bmp2 as Bitmap
Bmp = Bmp2

?

Report
Re: Copy One Bitmap to another Posted by CitizenOlek on 5 Jul 2007 at 7:34 AM
: 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.
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

Report
Re: Copy One Bitmap to another Posted by seancampbell on 5 Jul 2007 at 8:01 AM
I think your code is fine
Report
Re: Copy One Bitmap to another Posted by CitizenOlek on 5 Jul 2007 at 8:30 AM
: I think your code is fine

The part of my code that worries me is:
Dim BMPwithGL As Bitmap = BMPundo1

Beacause, at the start of my Application where I Dimension all my variables, I have already Dim'ed BMPwithGL, thusly:
Dim BMPwithGL As Bitmap

Is it proper to Dim the same variable over and over again like this?
Report
Re: Copy One Bitmap to another Posted by seancampbell on 5 Jul 2007 at 8:56 AM
That's fine, you could change it up to ReDim though
Report
Re: Copy One Bitmap to another [RESOLVED} Posted by CitizenOlek on 5 Jul 2007 at 10:38 AM
: That's fine, you could change it up to ReDim though
:
Thank You.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.