GDI and image displays

  • Thread starter Thread starter Glyn Meek
  • Start date Start date
G

Glyn Meek

I have a routine which uses the GDI to display an image using '.DrawImage'.

Sections of the image have been made transparent using '.MakeTransparent'.

Everything works well...

....BUT, I later need to replace the original image with a second image, also
with some transparent sections and cannot seem to find a way to do this. If
I merely use 'DrawImage to write the new image, sections of the old image
show through where the new image is transparent.

I have tried putting both images in Rectangles, and manipulating the
rectangles, but this doesn't seem to work either.

I tried to find a way to capture (and then restore) the original background
on the screen before the first image was drawn, but is BitBlt the only way
to do this?

Any GDI experts out there that can give me a hint as to how to get rid of
the original image altogether? or do I need to dive into the arcane world of
BitBlt, and if so, anyone got a good reference?

Regards

Glyn J Meek
 
You can take a screen capture of the section of where the image is located so
whenever you are showing a new image you draw the original background image
then your image. This of course assumes the background never changes.

You can also have a bool variable (ie drawMyImage) indicating if you should
paint the image or not in your onPaint event. For example if you changing
the image set drawMyImage=false then call invalidate then set
drawMyImage=true and call invalidate again.

With a little experimenting you should be able to get it working.
 
So you're drawing one image and then you want to change and draw another but
not have the original displayed anymore? Where are you calling DrawImage
from? If you're performing your image drawing in the OnPaint override, or a
Paint event handler, then you just need to cause a refresh using, as one
option, the Invalidate method. Then simply draw the new image and do not
draw the old one. If you are not drawing your images through the
OnPaint/Paint options, is there a specific reason why?
 
Tim, I think I have the mechanism down OK, but the problem is that I am
using transparent images and when I write one on top of the other, the
underlying original one shows through the 'transparent' parts and I want the
original background to show...so, I am assuming the following technique
(which may be my basic mistake in understanding the way graphics are
written!)

1) I have to capture the original background (which is a gradual shading)
before drawing the first image
2) when 'overwriting' with a subsequent image, I have to rewrite the
original image back and then write the new image over that...correct?
....or, does invalidate juts 'get rid of' the original image and leave me
with the bare form? If it does, then I did NOT realize that the images were
effectively laid down in layers!

Glyn
 
So it sounds like you start with a gradient background on your form and then
you want to paint an image on top of that, correct? How are you painting the
gradient effect onto the form?
 
Back
Top