Answered by:
Merge 2 Images with transparency

Question
-
User-1103495211 posted
I've got 2 images.
1 image with size (205x187) and 1 image with a different size, but this one is smaller then the first one.I try to merge this images. The first 1 is a PNG 32, but i think ASP saw it as 8 bits?
But if i run my script i get:My Script is:
public void mergePNG(typePNG type)
{
System.Drawing.Graphics myGraphic = null;string png= null;
if (type == typePNG.Actie)
{
png = ConfigurationManager.AppSettings["localPath"] + "images\actie.png";
}System.Drawing.Image imgB;
imgB = byteArrayToImage(this.Image);
System.Drawing.Image imgF;
imgF = System.Drawing.Image.FromFile(@"C:\websites\HV tweewielers\images\actie.png");//png);
System.Drawing.Image m;
m = imgB;myGraphic = System.Drawing.Graphics.FromImage(m);
//myGraphic.DpiX = 205;
//myGraphic.DpiY = 187;
myGraphic.DrawImageUnscaled(imgF, 0, 0);
myGraphic.DrawImageUnscaled(imgB, 0, 0);
myGraphic.DrawImageUnscaled(imgB, 0, 0);
myGraphic.Save();this.Image = ConvertImageToByteArray(m, System.Drawing.Imaging.ImageFormat.Jpeg);
}
So i thought mabye if i change this: m = imgB; in m = imgF; then i should at least get an bigger image... , thats true, but the other image is very small:
Quite strange, but i take a look at the 2 images, 1 of them is in code:
imgB (HorizontalResolution = 182, verticalResulition = 182)
imgF (HorizontalResolution = 71.111, verticalresolution, 71.1111)
But i cant change resolutions ore something, i think there is a better way to do this.
also if i right klick on the image and save as, then i get the imgB image! on both images! quite strange... [:|]Friday, August 8, 2008 9:20 AM
Answers
-
User-1103495211 posted
I searched for some Alpha Transperenacy on the internet, and found some code wich should do it.
Right below the working versionstring png = null; if (type == typePNG.Actie) { png = ConfigurationManager.AppSettings["localPath"] + @"images\actie.png"; } System.Drawing.Image fImg = System.Drawing.Image.FromFile(png); System.Drawing.Image img = new Bitmap(205, 187); Graphics g = Graphics.FromImage(img); g.DrawImage(bImg, 12, 35, bImg.Width, bImg.Height); ImageAttributes imgattr = new ImageAttributes(); ColorMatrix colormatrix = new ColorMatrix(); colormatrix.Matrix00 = 1.0F; colormatrix.Matrix11 = 1.0F; colormatrix.Matrix22 = 1.0F; colormatrix.Matrix33 = (float)1.0F; //Opancy, 0.5F is 50% colormatrix.Matrix44 = 1.0F; imgattr.SetColorMatrix(colormatrix); Rectangle destRect = new Rectangle(0, 0, fImg.Width, fImg.Height); g.DrawImage(fImg, destRect, 0, 0, fImg.Width, fImg.Height, System.Drawing.GraphicsUnit.Pixel, imgattr); //Add text: System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(System.Drawing.Color.White); g.DrawString("HV Motor sport", new Font("Verdana",17),brush, new Point(90, 136)); g.Save();
string png = null;
if (type == typePNG.Actie)
{
png = ConfigurationManager.AppSettings["localPath"] + @"images\actie.png";
}
System.Drawing.Image fImg = System.Drawing.Image.FromFile(png);
System.Drawing.Image img = new Bitmap(205, 187);
Graphics g = Graphics.FromImage(img);
g.DrawImage(bImg, 12, 35, bImg.Width, bImg.Height);
ImageAttributes imgattr = new ImageAttributes();
ColorMatrix colormatrix = new ColorMatrix();
colormatrix.Matrix00 = 1.0F;
colormatrix.Matrix11 = 1.0F;
colormatrix.Matrix22 = 1.0F;
colormatrix.Matrix33 = (float)1.0F; //Opancy, 0.5F is 50%
colormatrix.Matrix44 = 1.0F;
imgattr.SetColorMatrix(colormatrix);
Rectangle destRect = new Rectangle(0, 0, fImg.Width, fImg.Height);
g.DrawImage(fImg,
destRect,
0,
0,
fImg.Width,
fImg.Height,
System.Drawing.GraphicsUnit.Pixel,
imgattr);
//Add text:
System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(System.Drawing.Color.White);
g.DrawString("text", new Font("Verdana",17),brush, new Point(90, 136));
g.Save();- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, August 9, 2008 8:39 AM