This Code May Be used to Edit An Existing Image and Save it as a New Image
Bitmap thumbImage = null; try { thumbImage = new Bitmap(@"c:\Image.jpg"); Graphics finalImage = Graphics.FromImage(thumbImage);
//Custom drawing if (sDraw != null && sDraw != "") { System.Drawing.Font drawFont = new System.Drawing.Font("Arial", 16); SizeF size = finalImage.MeasureString(sDraw, drawFont);
Matrix mx = new Matrix(1, 0, 0, 1, 0, 0);
mx.Rotate(315, MatrixOrder.Append);
mx.Translate(thumbImage.Width / 2, thumbImage.Height / 2, MatrixOrder.Append);
finalImage.Transform = mx;
SolidBrush drawBrush = new SolidBrush(System.Drawing.Color.Black); finalImage.DrawString(sDraw, drawFont, drawBrush, -size.Width / 2, -size.Height / 2, StringFormat.GenericTypographic); }
finalImage.Dispose(); thumbImage.Save(@"c:\NewImage.jpg"); } catch (Exception ex) { thumbImage = null; }
Note : THe variable 'sDraw' contains the value to draw on the Image.
|
| Author: nisar 18 Apr 2009 | Member Level: Gold Points : 1 |
i want to add text on image, this code have this functionality, or of you know how to achieve this functionality then please guide me thanks
|
| Author: shobhit jain 20 Apr 2009 | Member Level: Silver Points : 1 |
Yes this code can add the text on image. simply fill your text in sDraw variable. The text will be added as a watermark. For adding text at other directions change the matrix used.
|
| Author: nisar 20 Apr 2009 | Member Level: Gold Points : 1 |
Thanks for your reply, but i am unable to use matrix, mean i dnt know which class support matrix?
|
| Author: shobhit jain 20 Apr 2009 | Member Level: Silver Points : 0 |
namespace System.Drawing.Drawing2D contains Matrix class.
|
| Author: nisar 20 Apr 2009 | Member Level: Gold Points : 1 |
thanks for your quick reply, now this code works for me, but the problem is when i insert text, It inserted at the middle with rotated, but i want to insert this text on left upper corner with straight text, please guide me how can achieve this......
|
| Author: shobhit jain 20 Apr 2009 | Member Level: Silver Points : 1 |
remove the lines mx.Rotate(315, MatrixOrder.Append); and mx.Translate(thumbImage.Width / 2, thumbImage.Height / 2, MatrixOrder.Append);
Add the line mx.Translate(0, 0, MatrixOrder.Append);
|
| Author: nisar 20 Apr 2009 | Member Level: Gold Points : 1 |
thanks shobhit jain, now its work perfectly according to my requirement, keep posting such codes....
|
| Author: shobhit jain 20 Apr 2009 | Member Level: Silver Points : 1 |
remove the lines mx.Rotate(315, MatrixOrder.Append); and mx.Translate(thumbImage.Width / 2, thumbImage.Height / 2, MatrixOrder.Append);
Add the line mx.Translate(0, 0, MatrixOrder.Append);
|