原图旋转/缩放 然后画布画图 ImageProcessor
//旋转 byte[] photoBytes = File.ReadAllBytes(HttpContext.Current.Server.MapPath(diyInfo.ImageUrl)); ImageFactory imageFactory = new ImageFactory(); imageFactory.Load(photoBytes); imageFactory.Rotate(diyInfo.RotationAngle); var ss = imageFactory.Image; //缩放 Bitmap bm1 = new Bitmap(ss, Convert.ToInt32(ss.Width * diyInfo.TemplateZoom * diyInfo.PictureZoom), Convert.ToInt32(ss.Height * diyInfo.TemplateZoom * diyInfo.PictureZoom)); //画布做图 Bitmap huabu = new Bitmap(Convert.ToInt32(diyInfo.EditWidth), Convert.ToInt32(diyInfo.EditHeight)); Graphics huabug = Graphics.FromImage(huabu); var neww = bm1.Width; var newh = bm1.Height; var x = Convert.ToInt32(diyInfo.CenterMarginLeft * diyInfo.TemplateZoom - neww / 2); var y = Convert.ToInt32(diyInfo.CenterMarginTop * diyInfo.TemplateZoom - newh / 2); Point ulCorner = new Point(x, y); huabug.DrawImage(bm1, ulCorner); huabu.Save(@"newbm.jpg");
//创建一块指定大小的画布 var bitmap = new Bitmap(200, 200); var huabug = Graphics.FromImage(bitmap); //在画布指定位置添加一张图片 var ulCorner = new Point(50, 50); var newImage = Image.FromFile(@"C:\\Users\\wei.chen\\Desktop\\ConsoleApplication1\\ConsoleApplication1\\images\\chrome.png"); huabug.DrawImage(newImage, ulCorner); //在画布指定位置写文字 //定义字体 var frm = new PrivateFontCollection(); frm.AddFontFile(@"C:\\Users\\wei.chen\\Desktop\\ConsoleApplication1\\ConsoleApplication1\\fonts\\华康娃娃体.TTF"); Font font = new Font(frm.Families[0], 11); //定义颜色 SolidBrush sbrush = new SolidBrush(System.Drawing.ColorTranslator.FromHtml("#ff0000")); // 绘制围绕点旋转的文本 PointF point = new PointF(50, 50); StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; Matrix mtxRotate = huabug.Transform; mtxRotate.RotateAt(90f, point); // 旋转角度和平移 huabug.Transform = mtxRotate; huabug.DrawString("从前有座山", font, sbrush, point, format); bitmap.Save(@"newbm.jpg");