Last post Nov 29, 2017 02:34 AM by SwanVW
Nov 28, 2017 08:33 AM|SwanVW|LINK
I want to add some word to a PNG, also I need other place without words transparent .
The PNG I create by blow code
public string DrawPng(int w,int h,string imagePath)
Bitmap bitmap = new Bitmap(w, h);
Graphics g = Graphics.FromImage(bitmap);
string name = Guid.NewGuid().ToString().Replace("-","");
bitmap.Save(imagePath+ name + ".png", ImageFormat.Png);
return name + ".png";
And I add the words with below
SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(153, 255, 255, 255));
grPhoto.DrawString(waterWords, //string of text
new PointF(xPosOfWm, yPosOfWm), //Position
As you have seen , I have set bmPhoto.MakeTransparent(Color.Transparent); but it doesn't work. I get the PNG with a black background.
Nov 28, 2017 10:05 AM|PatriceSc|LINK
The purpose of this method is to replace a given color with Color.Transparent. For example you create a bitmap and use a color you won't use for the background (such as purple or whatever). You then draw whatever you want and then call MakeTransparent(Color.Purple)
so that what remained purple is now transparent.
If black is only used for your background and not anything else try MakeTransparent(Color.Black).
Nov 29, 2017 01:10 AM|Archer Wang|LINK
thank you. I try it by your advice, and I get what I want.
Nov 29, 2017 02:34 AM|SwanVW|LINK
I add MakeTransparent(Color.Black) follow your suggestion, then it worked. thanks.