Solved

can't draw on picture box background

Posted on 1999-01-11
12
351 Views
Last Modified: 2010-05-03
i'm quite confused about the autoredraw property of a picture box.
I have a picture box pic1 with background picture. Now I allow the user to draw something on pic1 (something like the pen in MS paint).
However, I don't get to save the background picture together with the drawn lines as pic1.picture. I've tried setting the Autoredraw to T or F but I still can't get it.
I'm using the SavePicture method.

Is there another way or I did not set the autoredraw properly?
0
Comment
Question by:tezi
12 Comments
 
LVL 3

Expert Comment

by:Sendoh
Comment Utility
Hi !
OK, in this case. Set the
1) autoredraw = true
2) draw line or any other drawing operations.
3) autoredraw to false.
4) call savepicture.

Note: if you need to allow user to undo, add another picture with visible = false as double buffer for undo.

hOpe this'll help
0
 

Expert Comment

by:Amir101298
Comment Utility
set picture1.autoredraw = true
when you call savepicture use
savepicture picture1.image, "c:\temp\temp.bmp"

this should do it
0
 

Author Comment

by:tezi
Comment Utility
Sendoh, your method does not save what is drawn as part of the pic's picture. The pic.picture remains as it is.

Amir, your method actually works, but I also have something else which is copied  (bitblit) on pic1. So the method of Saving the image property actually serves as a "Printscreen" as well, so the unwanted pictures which are copied is also saved.

What I wanted is the pic1.Picture only contains its original picture and what is drawn on it only.
0
 
LVL 3

Expert Comment

by:Sendoh
Comment Utility
Hi !
OK, I'll explain further.

1) autoredraw = true
2) draw line or any other drawing operations.
3) autoredraw = false
4) assign confirm drawing by
        picture1.picture = picture1.image
5) call Bitblt to do whatever.
4) call savepicture by passing whether picture1.image(include bitblt) or picture1.picture where only original plus user drawing.

Hope it'll help ^_^.
0
 

Author Comment

by:tezi
Comment Utility
Sendoh,
what you are actually doing is the same as what Amir has suggested. It still saves the whole image (including unwanted blit pictures on pic1) because you have assigned pic1.Image to pic1.Picture.

What I want is just the pic1.Picture saved together with the drawn lines only.
0
 

Author Comment

by:tezi
Comment Utility
Adjusted points to 50
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 3

Expert Comment

by:Sendoh
Comment Utility
Hi !
I think you didn't really tried it. Right ??
Anyway, I'd prove it to you.

Private Sub Command7_Click()
    Picture1.ScaleMode = 3
    Picture1.AutoRedraw = True
    Picture1.Circle (50, 50), 25
    Picture1.Picture = Picture1.Image
    Picture1.AutoRedraw = False
    BitBlt Picture1.hDC, 0, 0, 50, 50, Picture2.hDC, 0, 0, SRCCOPY
    SavePicture Picture1.Picture, "c:\temp\mci\save.bmp"
End Sub

Inthis case, whatever blitting on picture1.picture will not saved.
Does this suit your need ??
0
 

Author Comment

by:tezi
Comment Utility
I tried your codes already. Let me tell you why I think it does not work. I MUST call bitblt function first, and later I allow the user to draw on pic1. So the pic1.Image already contains the bitblt (the unwanted picture). So pic1.picture will contain EVERYTHING and not just its original background.
0
 
LVL 1

Accepted Solution

by:
Johnn earned 50 total points
Comment Utility
Hi there what you want to do is possible but it takes a little more work, depending on how much you want to bitblt and whether or not you want the user to be able to draw where you've blitted, etc.  Here's how you could do it.
Use a second picture box for the blting your doing set this 2nd box enabled to false

Keep this stuff in mind...
before you make this 2nd box visible, capture the other pic box's image where you intend on putting this box and blt it to this box, unless you just make it the same size and set the background = to the 1st pic(but if you do this you'll need to draw the users stuff twice one on orig and one on 2nd).  

    BitBlt Picture2.hDC, 0, 0, Picture2.Width, Picture2.Height, Picture1.hDC, Picture2.Left, Picture2.Top, SRCCOPY
    Picture2.Visible = True'set to false at design time
'note scale mode=pixel in container, you probably want to set
the 2nd box to be in the 1st box

Then you could blt whatever the heck you want to this and it won't be on the "original", and because it's enabled=false, the 1st box gets all the events.  Actually, if you allow the user to draw in your bitblt area then you'll need to do a test in the mousemove event if they're inside this 2ndbox and draw it on this box as well(the original still get's it drawing)  You also need to set this 2nd box autoredraw=true.  There's so many things you could do with this senerio, I don't have enough details to give you the exact route to go but this is definitely what you want.  You can test this by doing some drawing operations and then hide the 2nd box and you'll see the drawings underneath as well.
0
 

Author Comment

by:tezi
Comment Utility
hi!
I think you're very near to a solution already, but let me tell you what I'm trying to do so that you'll get a better idea and decide whether your method will work or not.

I have a few picture boxes, pic1 ,pic2, pic3 and pic4.
Pic1 is the main one with the background. Pic2, pic3,pic4 is inside pic1. All of them are set to autoredraw = True. pic2, pic3 and pic4 visible =False.

Next I call transparent blit to blit pic2, pic3 and pic4 on pic1. so far so good. Now I wanted to let the user moves pic2 , eg 5 pixels to the right, ok? I also let the user draw dots or lines (anywhere on pic1) so it may overlap on pic2,pic3 or pic4.

Since i'm using the transparent blit function, the pic2 will still be there even if i move the picture box to the right. So if I cls pic1, I would lost track of what the user has drawn...

So just wondering if your method (which is quite creative) will work. I need to keep track of what is drawn so that I can call the cls on pic1 and blit everything all over again on pic1 with pic2 having the new coordinates.

Can you give an example preferably with detection if the user draws on the blit pictures?
You might be of great help.TQ in advance.

0
 

Author Comment

by:tezi
Comment Utility
Hi mdougan

your codes work very perfectly, however there is one big major problem. I also have a few other picture boxes blit on pic1. So when I save the background, I also manage to save them as well. This is a good thing.

The bad thing is when I paste back the background on pic1, the partially "cut" pic3 which is blit on pic1 and is copied on picsAve will appear with the border. so pic3 looks kinda cut off into half.

One more thing, the user can draw inside the blit pictures. And when the background is pasted on it, the drawn lines is gone. :-(

ANy ideas?
0
 

Author Comment

by:tezi
Comment Utility
sorry about the that comment! pls ignore it.


0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now