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);
           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();
时间: 2024-09-20 18:47:36

Csharp: create Transparent Images in winform的相关文章

Csharp: Create Excel Workbook or word from Template File using aspose.Word 14.5 and aspose.Cell 8.1

winform: /// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnGenWord_Click(object sender, EventArgs e) { Dictionary<string, string> d

csharp create ICS file extension

  string schLocation = "Conference Room 涂聚文约会你"; string schSubject = "Business visit discussion约会"; string schDescription = "Schedule description明天到深圳市福田區車公廟冶金大大廈約會"; System.DateTime schBeginDate = Convert.ToDateTime("2/

如何将自己的代码自动添加版权信息

现在大多数公司都规定程序员在程序文件的头部加上版权信息,这样每个人写的文件都可以区分开来,如果某个文件出现问题就可以快速的找到文件的创建人,用最短的时间来解决问题,常常是以下格式: //======================================================================//// Copyright (C) 2007-2008 三月软件工作室 // All rights reserved//// filename :Class4// desc

csharp: winform using Microsoft.Ink(Tablet PC API) create Signature image

/* 下載: //Microsoft Windows XP Tablet PC Edition 2005 Recognizer Pack http://www.microsoft.com/zh-cn/download/details.aspx?id=1601 //Microsoft Windows XP Tablet PC Edition Software Development Kit 1.7 http://www.microsoft.com/en-us/download/details.as

Csharp run sql script create database

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; using System.Data.Sql; using Microsof

Csharp Winform TextBox 樣式以一條橫線顯示

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; using System.Reflection; using System.Runtime.InteropServices; using System.Compon

Csharp: winform PDF view control use Adobe Reader X

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using AcroPDFLib;//引用COM組件Adobe Acrobat Browser Control Type Libra

csharp Send Skype messages from webform and winform

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using SKYPE4COMLib; //下載地址:http://en.sourceforge.jp/projects/sfnet_skype4mp/downloads/Skype4

Csharp: Winform 顏色選擇器 Color convert RGB and RGB convert Color

/// <summary> /// 選擇顏色 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click(object sender, EventArgs e) { //是否選擇了顏色 if (colorDialog1.ShowDialog(thi