public class ImageHelper
{
public static void DrawTransparent(byte[] data, int width, int height, string imgPath, Color color)
{
Rectangle rec = new Rectangle(0, 0, 231, 71);
Bitmap img = new Bitmap(rec.Width, rec.Height);
using (Graphics grafs = Graphics.FromImage(img))
{
Brush imgBrush = new SolidBrush(color);
grafs.SmoothingMode = SmoothingMode.AntiAlias;
grafs.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
grafs.FillRectangle(imgBrush, 0, 0, 231, 71);
using (Image machineImage = GetImage(data))
{
grafs.DrawImage(machineImage, rec);
img.MakeTransparent(Color.White);
img.MakeTransparent(Color.FromArgb(Convert.ToInt32("FFFEFE", 16)));
img.Save(imgPath);
}
}
}
protected static Image GetImage(byte[] data)
{
Stream stream = new MemoryStream(data);
return Image.FromStream(stream);
}
}