C#图像画矩形框
//保存127*229的图片_S
//File.Copy(imagepath, temppath, true); //拷贝文件
bmp = new Bitmap(imagepath);
bmp_S = new Bitmap(bmp, 127, 229);
//bmp_S.Save(imagepath_S, ImageFormat.Jpeg);
g = Graphics.FromImage(bmp_S);
//gp = new GraphicsPath();
//rec = new Rectangle(new Point((total - height) / 2, (total - height) / 2), new Size(width, height));
//gp.AddRectangle(rec);
pen = new Pen(Color.Red);
pen.Width = penWidth;
g.DrawRectangle(pen, new Rectangle(new Point((total - height) / 2, (total - height) / 2), new Size(width, height)));
bmp_S.SetResolution(72, 72); //设置分辨率
bmp_S.Save(imagepath_S, ImageFormat.Tiff);
bmp.Dispose();
bmp_S.Dispose();
//创建229*229的图片_M
//创建图像
//File.Copy(imagepath, temppath, true);
bmp = new Bitmap(imagepath);
rec = new Rectangle(0, 0, 229, 229); //绘制整块区域
bmp_M = new Bitmap(rec.Width, rec.Height,PixelFormat.Format24bppRgb); //按指定大小创建位图
//重画
g = Graphics.FromImage(bmp_M); //从位图创建Graphics对象
g.Clear(Color.FromArgb(0, 0, 0, 0)); //清空
g.DrawImage(bmp, rec, new Rectangle(5000, 5000, 229, 229), GraphicsUnit.Pixel); //从pic的给定区域进行绘制
bmp_M.SetResolution(72, 72); //设置分辨率
//绘制矩形框
//gp = new GraphicsPath();
//rec = new Rectangle(new Point((total - width) / 2, (total - height) / 2), new Size(width, height));
//gp.AddRectangle(rec);
pen = new Pen(Color.Red);
pen.Width = penWidth;
g.DrawRectangle(pen, new Rectangle(new Point((total - width) / 2, (total - height) / 2), new Size(width, height)));
g.DrawLine(pen, new Point((total - width) / 2 + tempdist1, total / 2), new Point((total + width) / 2 - tempdist1, total / 2));
g.DrawLine(pen, new Point(total / 2, (total - height) / 2 + tempdist1), new Point(total / 2, (total + height) / 2 - tempdist1));
bmp_M.Save(imagepath_M, ImageFormat.Tiff);
bmp.Dispose();
bmp_M.Dispose();
