Csharp: create Transparent Images in winform

简介: //透明背景图 Brush b = new SolidBrush(Color.FromArgb(50, Color.Transparent)); Bitmap image = new Bitmap(1015, 637); Graphics g = Graphics.FromImage(image);
//透明背景图
           Brush b = new SolidBrush(Color.FromArgb(50, Color.Transparent));

 
           Bitmap image = new Bitmap(1015, 637);
           Graphics g = Graphics.FromImage(image);
           g.Clear(Color.Transparent);
           g.FillRectangle(b, 0, 0, 1015, 637);
           //g.DrawRectangle(Pens.Plum, 0, 0, 299, 49);
           //Font font = new Font("Alba Super", 20, FontStyle.Underline);
           //g.DrawString("This is a test.", font, Brushes.Plum, 10, 0);

           //System.Drawing.Image icon = System.Drawing.Image.FromFile(Server.MapPath("your.gif"));
           //g.DrawImageUnscaled(icon, 240, 0);

           //image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
           //SolidBrush:定义单色画笔。画笔用于填充图形形状,如矩形、椭圆、扇形、多边形和封闭路径。
           //这个画笔为描绘阴影的画笔,呈灰色
           float alpha = 0;
           int m_alpha = Convert.ToInt32(256 * alpha);
           SolidBrush semiTransBrush2 = new SolidBrush(Color.FromArgb(m_alpha, 0, 0, 0));

           //从四个 ARGB 分量(alpha、红色、绿色和蓝色)值创建 Color 结构,这里设置透明度为153
           //这个画笔为描绘正式文字的笔刷,呈白色
           SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(153, 255, 255, 255));


           g.DrawImage(image, 0, 0, image.Width, image.Height);
           Font f = new Font(setFont, 18, FontStyle.Bold); //字體大小
           Font fno = new Font(setFont, 10, FontStyle.Bold);
           Font fclerk = new Font(setFont, 8, FontStyle.Bold);
           Brush fb = new SolidBrush(Color.Black); //字體顏色                
           string addText = "塗聚文";
           //new RectangleF(0, 0, 500, 500), strFormat)  
           g.DrawString(addText, f, fb, new RectangleF(130, 220, 550, 110), new StringFormat());//放的姓名位置
           g.DrawString("行政及人事管理人員", fclerk, fb, new RectangleF(130, 410, 550, 110), new StringFormat());//放職稱的位置
           g.DrawString("行政及人力资源管理部", fno, fb, new RectangleF(130, 470, 550, 110), new StringFormat());//放部門名稱的位置
           g.DrawString("L00094", fno, fb, new RectangleF(130, 540, 550, 110), new StringFormat()); //放員工編號的位置

           int xPosOfWm;
           int yPosOfWm;
           int phWidth = image.Width;
           int phHeight = image.Height;
           Photopath = dirInfo + "2cun.jpg"; //2寸照片
           System.Drawing.Image copyImage = System.Drawing.Image.FromFile(Photopath);
           int wmWidth = copyImage.Width;
           int wmHeight = copyImage.Height;


           xPosOfWm = phWidth - wmWidth - 80;
           yPosOfWm = 80;
           StringFormat strFormat = new StringFormat();

           g.DrawImage(copyImage, new Rectangle(xPosOfWm, yPosOfWm, wmWidth, wmHeight), 0, 0, copyImage.Width, copyImage.Height, GraphicsUnit.Pixel);

           // Make backColor transparent for myBitmap.
           ImageAttributes imgAttribs = new ImageAttributes();
           imgAttribs.SetColorKey(Color.FromArgb(255, 255, 255), Color.FromArgb(255, 255, 255));
           Color backColor = Color.Transparent;
           image.MakeTransparent(backColor);
           //image = MakeTransparentGif(image, Color.Transparent);
           // Draw the transparent bitmap to the screen.
           //g.DrawImage(image, image.Width, 0, image.Width, image.Height);
           this.pictureBox1.Image = image;
           image.Save(dirInfo + @"geovindu_1011.jpg", ImageFormat.Jpeg);

           g.Dispose();

目录
相关文章
|
图形学 Windows
Unity报错之 No Sprite Editor Window registered. Please download 2D Sprite package from Package Manager
Unity2019操作对图集进行操作编辑出错:No Sprite Editor Window registered. Please download 2D Sprite package from Package Manager.
1159 0
Unity报错之 No Sprite Editor Window registered. Please download 2D Sprite package from Package Manager
|
Python
【tkinter学习笔记 - 5】:布局管理器(grid、pack、place)
【tkinter学习笔记 - 5】:布局管理器(grid、pack、place)
220 0
【tkinter学习笔记 - 5】:布局管理器(grid、pack、place)
SAP Spartacus 的 cx-page-layout selector 介绍 - PageLayoutComponent
SAP Spartacus 的 cx-page-layout selector 介绍 - PageLayoutComponent
104 0
SAP Spartacus 的 cx-page-layout selector 介绍 - PageLayoutComponent
|
XML 数据格式
how to SAP Data panel
The SAP Data Panel is a Microsoft Word Add-in developed by SAP for mapping variables as Content Controls into SAP Document Builder Elements and Overlays. The SAP Data Panel replaces the Third Party XML Schemas previously used for mapping variables within SAP Document Builder. The SAP Data Panel can
how to SAP Data panel
SAP UI5 -all controls within the same view will share the same data Model
model changes are propagated until the first descendant that has its own model with the same name
121 0
SAP UI5 -all controls within the same view will share the same data Model
使用代码创建ABAP transparent table
使用代码创建ABAP transparent table
128 0
|
C#
WPF: FishEyePanel/FanPanel - 自定义Panel
原文:WPF: FishEyePanel/FanPanel - 自定义Panel 原文来自CodeProject,主要介绍如何创建自定义的Panel,如同Grid和StackPanel。
1258 0
[UWP]了解模板化控件(5.1):TemplatePart vs. VisualState
原文:[UWP]了解模板化控件(5.1):TemplatePart vs. VisualState 1. TemplatePart vs. VisualState 在前面两篇文章中分别使用了TemplatePart及VisualState的方式实现了相同的功能,其中明显VisualState的方式更灵活一些。
931 0
|
存储 C#
[UWP]了解模板化控件(4):TemplatePart
原文:[UWP]了解模板化控件(4):TemplatePart 1. TemplatePart TemplatePart(部件)是指ControlTemplate中的命名元素。控件逻辑预期这些部分存在于ControlTemplate中,并且使用protected DependencyObject GetTemplateChild(String childName)获取它们后进行操作。
1251 0