Hi all!

I'm playing around a bit with my old Visual Basic 6.0. I'm working with images, and this rather strange error came up:

First I isolate a small piece of a larger picture to a smaller picturebox using PaintPicture: picBoxSprite.PaintPicture picBoxResource.Picture, 0, 0, 64, 64, (X * 64), (Y * 64), 64, 64 This works perfectly fine, and the smaller picture of 64x64 pixels is displayed like a charm.

Next, I want to copy this new picture from my picBoxSprite object (PictureBox) to one of my stretchable Image-objects. So I write the following line: imgDirt.Picture = picBoxSprite.Image This is where my problem occurs; nothing happens! imgDirt remains blank. If I pre-load a random bitmap into picBoxSprite before running the program, the copy operation works perfectly fine.

Why is this? And what can I do to make it work?

Thank you for your time!

Emil Olofsson

The problem is that the picture box and image controls MUST have a file reference as the starting point. You can't "hopscotch" passing blocks of pixels from one control to the other.

So, what happens if you pre-load your picture box picBoxSprite with a file is that it then has a filename reference for the image control to grab onto. If you just copy some pixels in from another picture box (picBoxResource), then the image control has no filename to grab onto. Therefore, it doesn't work.

You can get around this by either creating a temporary file with the image in your picture box using the SavePicture function, then using the LoadPicture function to splash it onto your image control.

Of course, if you really wanted to dig deep, you could just expose all the graphics methods in the Windows API and do it directly. Unless you have a specific reason to do this, I wouldn't recommend it.

Good luck!

I thought all Picture objects were bitmaps loaded into memory, and that you could copy and paste them however you wanted. I was wrong :)

Your solution worked like a charm, thanks a lot!

I thought all Picture objects were bitmaps loaded into memory, and that you could copy and paste them however you wanted. I was wrong :)

Actually, they are. You just can't manipulate them in the context of these controls. You have to get the handle to the device context in memory. Then you can move them around all you like using the Bit Block Transfer (BitBlt :icon_cheesygrin:) Windows API call.

This question has already been answered. Start a new discussion instead.