1 //透明背景图
 2            Brush b = new SolidBrush(Color.FromArgb(50, Color.Transparent));
 3
 4
 5            Bitmap image = new Bitmap(1015, 637);
 6            Graphics g = Graphics.FromImage(image);
 7            g.Clear(Color.Transparent);
 8            g.FillRectangle(b, 0, 0, 1015, 637);
 9            //g.DrawRectangle(Pens.Plum, 0, 0, 299, 49);
10            //Font font = new Font("Alba Super", 20, FontStyle.Underline);
11            //g.DrawString("This is a test.", font, Brushes.Plum, 10, 0);
12
13            //System.Drawing.Image icon = System.Drawing.Image.FromFile(Server.MapPath("your.gif"));
14            //g.DrawImageUnscaled(icon, 240, 0);
15
16            //image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
17            //SolidBrush:定义单色画笔。画笔用于填充图形形状,如矩形、椭圆、扇形、多边形和封闭路径。
18            //这个画笔为描绘阴影的画笔,呈灰色
19            float alpha = 0;
20            int m_alpha = Convert.ToInt32(256 * alpha);
21            SolidBrush semiTransBrush2 = new SolidBrush(Color.FromArgb(m_alpha, 0, 0, 0));
22
23            //从四个 ARGB 分量(alpha、红色、绿色和蓝色)值创建 Color 结构,这里设置透明度为153
24            //这个画笔为描绘正式文字的笔刷,呈白色
25            SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(153, 255, 255, 255));
26
27
28            g.DrawImage(image, 0, 0, image.Width, image.Height);
29            Font f = new Font(setFont, 18, FontStyle.Bold); //字體大小
30            Font fno = new Font(setFont, 10, FontStyle.Bold);
31            Font fclerk = new Font(setFont, 8, FontStyle.Bold);
32            Brush fb = new SolidBrush(Color.Black); //字體顏色
33            string addText = "塗聚文";
34            //new RectangleF(0, 0, 500, 500), strFormat)
35            g.DrawString(addText, f, fb, new RectangleF(130, 220, 550, 110), new StringFormat());//放的姓名位置
36            g.DrawString("行政及人事管理人員", fclerk, fb, new RectangleF(130, 410, 550, 110), new StringFormat());//放職稱的位置
37            g.DrawString("行政及人力资源管理部", fno, fb, new RectangleF(130, 470, 550, 110), new StringFormat());//放部門名稱的位置
38            g.DrawString("L00094", fno, fb, new RectangleF(130, 540, 550, 110), new StringFormat()); //放員工編號的位置
39
40            int xPosOfWm;
41            int yPosOfWm;
42            int phWidth = image.Width;
43            int phHeight = image.Height;
44            Photopath = dirInfo + "2cun.jpg"; //2寸照片
45            System.Drawing.Image copyImage = System.Drawing.Image.FromFile(Photopath);
46            int wmWidth = copyImage.Width;
47            int wmHeight = copyImage.Height;
48
49
50            xPosOfWm = phWidth - wmWidth - 80;
51            yPosOfWm = 80;
52            StringFormat strFormat = new StringFormat();
53
54            g.DrawImage(copyImage, new Rectangle(xPosOfWm, yPosOfWm, wmWidth, wmHeight), 0, 0, copyImage.Width, copyImage.Height, GraphicsUnit.Pixel);
55
56            // Make backColor transparent for myBitmap.
57            ImageAttributes imgAttribs = new ImageAttributes();
58            imgAttribs.SetColorKey(Color.FromArgb(255, 255, 255), Color.FromArgb(255, 255, 255));
59            Color backColor = Color.Transparent;
60            image.MakeTransparent(backColor);
61            //image = MakeTransparentGif(image, Color.Transparent);
62            // Draw the transparent bitmap to the screen.
63            //g.DrawImage(image, image.Width, 0, image.Width, image.Height);
64            this.pictureBox1.Image = image;
65            image.Save(dirInfo + @"geovindu_1011.jpg", ImageFormat.Jpeg);
66
67            g.Dispose();

转载于:https://www.cnblogs.com/geovindu/archive/2013/01/05/2846538.html

Csharp: create Transparent Images in winform相关推荐

  1. C# WinForm 运行久了就内存不足

    转载地址:https://www.debugease.com/csharp/4441632.html 1.WinForm,主窗体-子窗体模式 2.关闭子窗体,使用Hide(),打开子窗体,使用Show ...

  2. GridView+ZedGraph【转】

    edgraph图表控件的强大功能令人出乎意料,与OWC相比我想应该毫不逊色,近来需求要求作出相关数据统计,不想使用BI这类的强大东西,所以搜索到 了免费的开源的Zedgraph控件.使用起来也非常方便 ...

  3. 上传书籍进度信息到服务器...,使用HttpWebRequest实现大文件上传资料.pdf

    Twilight Software Development Studio © 2011 使用HttpWebRequest 实现大文件上传 Author:xuzhihong Create Date:20 ...

  4. 如何将自己的代码自动添加版权信息[转]

    现在大多数公司都规定程序员在程序文件的头部加上版权信息,这样每个人写的文件都可以区分开来,如果某个文件出现问题就可以快速的找到文件的创建人,用最短的时间来解决问题,常常是以下格式: //======= ...

  5. 算法偏见是什么_处理人工智能的偏见如何使算法公平公正

    算法偏见是什么 算法在AI中扮演什么角色? (What Role do Algorithms Play in AI?) As artificial intelligence becomes more ...

  6. 计算机鼠标透明度,给电脑添加透明护眼蒙版(鼠标穿透)

    import win.ui; /*DSG{{*/ var winform = win.form(text="aardio form";right=759;bottom=469;bg ...

  7. c# 制作gif的四种方法

    方法一:使用AnimatedGif库 Nuget安装包: 1 Install-Package AnimatedGif -Version 1.0.5 https://www.nuget.org/pack ...

  8. 简单鲁班锁拼装技巧_3个简单的技巧来消除背景时,丑陋的边缘

    简单鲁班锁拼装技巧 If you cut out a lot of objects from photographs, chances are you've run across a few roug ...

  9. 面向对象六大设计原则

    目录 1 .单一职责(Single Responsibility Principle) 2 .开闭原则(Open Close Principle) 3.里氏替换原则(Liskov Substituti ...

最新文章

  1. 被放弃的概率权,机器下围棋不理会沉没成本
  2. mysql根据时间戳查询指定日期内数据
  3. 我作为一个程序员,除了写程序还会干什么?什么都不会了!
  4. 十分钟掌握pyecharts十类顶级图,都很实用!
  5. MyBatis】MyBatis一级缓存和二级缓存
  6. javafx2_JavaFX 2 GameTutorial第4部分
  7. hadoop遇到的问题及处理
  8. CUDA线程、线程块、线程束、流多处理器、流处理器、网格概念的深入理解
  9. 中国高铁站,为什么离市区这么远
  10. iphone电压测试软件,电压电击iPhone结果会怎样? 通过测试后, 照样可以正常开机...
  11. Windows Server 2016 配置指南 之 安装 PHP redis 拓展
  12. vs C++实现Socket通信、添加ws2_32.lib 动态链接库
  13. Fluent 全流程求解多孔介质算例
  14. linux 修改文件的权限
  15. matlab 矩阵 三维矩阵相乘,将三维矩阵与二维矩阵相乘
  16. 国际学校入学考试MAP语法测试题真题讲解
  17. 文件存储、块存储还是对象存储?
  18. 苹果手机没有备份怎么恢复照片?
  19. js图片轮播效果实现代码
  20. 127Echarts - 关系图(Graph Life Expectancy)

热门文章

  1. SuperTuxKart 0.10 测试版发布
  2. Oracle Golden Gate - 概念和机制
  3. debian下apr-get isntall 出错提示用apt-get -f install问题
  4. Server object instance creation failed on all SOC machines
  5. Windows7和Ubuntu9.10完美硬盘安装(2)
  6. SplitContainer.SplitterDistance属性值设置应注意的与FixedPanel有关
  7. Effective C# 原则8:确保0对于值类型数据是有效的(翻译)
  8. 一步一步手绘Spring AOP运行时序图(Spring AOP 源码分析)
  9. Linux安装MYSQL5.7教程(一次成功)
  10. [Java] 蓝桥杯ALGO-10 算法训练 集合运算