using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ImageDemoOne
{
class DrawIcon
{
public static void DrawImage()
{
String FileName = "BrushType02.gif";
Image img = Bitmap.FromFile(Path.Combine("D:/cworkroom/ImageDemoOne/ImageDemoOne/img", FileName));
int bordwidth = Convert.ToInt32(1);
int bordheight = Convert.ToInt32(1);
int newheight = img.Height + bordheight;
int newwidth = img.Width + bordwidth;
Color bordcolor = Color.Black;
Bitmap bmp = new Bitmap(newwidth, newheight);
Graphics g = Graphics.FromImage(bmp);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
int Style = 0; //New: 绘制边框的类型, 手动修改0,1,2 可改变边框类型
if (Style == 0) //New: 整个边框.
{
//Changed: 修改rec区域, 将原图缩放. 适合边框内
System.Drawing.Rectangle rec = new Rectangle(bordwidth / 2, bordwidth / 2, newwidth - bordwidth / 2, newheight - bordwidth / 2);
g.DrawImage(img, rec, 0, 0, img.Width, img.Height, GraphicsUnit.Pixel);
g.DrawRectangle(new Pen(bordcolor, bordheight), 0, 0, newwidth, newheight);
}
else if (Style == 1) //New: 上下边框.
{
System.Drawing.Rectangle rec = new Rectangle(0, bordwidth / 2, newwidth, newheight - bordwidth / 2);
g.DrawImage(img, rec, 0, 0, img.Width, img.Height, GraphicsUnit.Pixel);
g.DrawLine(new Pen(bordcolor, bordheight), 0, 0, newwidth, 0);
g.DrawLine(new Pen(bordcolor, bordheight), 0, newheight, newwidth, newheight);
}
else if (Style == 2) //New: 左右边框.
{
System.Drawing.Rectangle rec = new Rectangle(bordwidth / 2, 0, newwidth - bordwidth / 2, newheight);
g.DrawImage(img, rec, 0, 0, img.Width, img.Height, GraphicsUnit.Pixel);
g.DrawLine(new Pen(bordcolor, bordheight), 0, 0, 0, newheight);
g.DrawLine(new Pen(bordcolor, bordheight), newwidth, 0, newwidth, newheight);
}
bmp.Save("c:\\" + "BrushType02.gif");
g.Dispose();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ImageDemoOne
{
class DrawIcon
{
public static void DrawImage()
{
String FileName = "BrushType02.gif";
Image img = Bitmap.FromFile(Path.Combine("D:/cworkroom/ImageDemoOne/ImageDemoOne/img", FileName));
int bordwidth = Convert.ToInt32(1);
int bordheight = Convert.ToInt32(1);
int newheight = img.Height + bordheight;
int newwidth = img.Width + bordwidth;
Color bordcolor = Color.Black;
Bitmap bmp = new Bitmap(newwidth, newheight);
Graphics g = Graphics.FromImage(bmp);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
int Style = 0; //New: 绘制边框的类型, 手动修改0,1,2 可改变边框类型
if (Style == 0) //New: 整个边框.
{
//Changed: 修改rec区域, 将原图缩放. 适合边框内
System.Drawing.Rectangle rec = new Rectangle(bordwidth / 2, bordwidth / 2, newwidth - bordwidth / 2, newheight - bordwidth / 2);
g.DrawImage(img, rec, 0, 0, img.Width, img.Height, GraphicsUnit.Pixel);
g.DrawRectangle(new Pen(bordcolor, bordheight), 0, 0, newwidth, newheight);
}
else if (Style == 1) //New: 上下边框.
{
System.Drawing.Rectangle rec = new Rectangle(0, bordwidth / 2, newwidth, newheight - bordwidth / 2);
g.DrawImage(img, rec, 0, 0, img.Width, img.Height, GraphicsUnit.Pixel);
g.DrawLine(new Pen(bordcolor, bordheight), 0, 0, newwidth, 0);
g.DrawLine(new Pen(bordcolor, bordheight), 0, newheight, newwidth, newheight);
}
else if (Style == 2) //New: 左右边框.
{
System.Drawing.Rectangle rec = new Rectangle(bordwidth / 2, 0, newwidth - bordwidth / 2, newheight);
g.DrawImage(img, rec, 0, 0, img.Width, img.Height, GraphicsUnit.Pixel);
g.DrawLine(new Pen(bordcolor, bordheight), 0, 0, 0, newheight);
g.DrawLine(new Pen(bordcolor, bordheight), newwidth, 0, newwidth, newheight);
}
bmp.Save("c:\\" + "BrushType02.gif");
g.Dispose();
}
}
}