imagealphablending( $targetImage, false );
imagesavealpha( $targetImage, true );
did it for me. Thanks ceejayoz.
note, the target image needs the alpha settings, not the source image.
Edit:
full replacement code. See also answers below and their comments. This is not guaranteed to be be perfect in any way, but did achieve my needs at the time.
$uploadTempFile = $myField[ 'tmp_name' ]
list( $uploadWidth, $uploadHeight, $uploadType )
= getimagesize( $uploadTempFile );
$srcImage = imagecreatefrompng( $uploadTempFile );
$targetImage = imagecreatetruecolor( 128, 128 );
imagealphablending( $targetImage, false );
imagesavealpha( $targetImage, true );
imagecopyresampled( $targetImage, $srcImage,
0, 0,
0, 0,
128, 128,
$uploadWidth, $uploadHeight );
imagepng( $targetImage, 'out.png', 9 );
If you want to overlay images over images (and not images over form), this would make the trick:
overImage.Parent = backImage;
overImage.BackColor = Color.Transparent;
overImage.Location = thePointRelativeToTheBackImage;
Where overImage and backImage are PictureBox with png (with transparent background).
This is because, as said before, the transparency of an image is rendered using the back color of the Parent container. PictureBoxes haven't a "Parent" property so you have to make it manually (or create a cutom control of course).
Best Answer
It is difficult to make a control that is partially transparent.
What you should do is handle the lower
PictureBox
'sPaint
event (the one that does not need to be transparent), and draw the overlay image usinge.Graphics.DrawImage(image, x, y)
. This will draw transparent and semi-transparent images correctly.EDIT: In response to your comment, there's nothing wrong with calling the
Invalidate
method in theMouseMove
event. However, you will notice some flickering. To solve the flickering, make a control that inheritsPictureBox
, and callSetStyle(ControlStyles.DoubleBuffered, true)
in the constructor.