Have you tried using. Net for image processing? In a recent project of the company, a lot of product images are stored in the database, but there is no copyright information. At that time, the customer asked to add all the pictures to the company name? What should you do at this time?
Although I am still a pioneer, there are still many solutions to this problem, which come down to the following:
1. this function can be implemented using graphics processing software, such as Photoshop, and its batch processing function. However, every time a data recorder adds images, it will have to be processed, which is very troublesome, reading the recorder's big sister is usually very nice to me. I smile every day. Can I bear to torture her? This solution was rejected.
2. use. net-based Image Processing in the cloud. When the recorder upload an image, the system automatically adds the company tag. This is not a good solution. Well, this idea is good. You can enter the top 10 of the 2005 Best solutions, let's just do it.
Using system. drawing;
Using system. IO;
Using system. Drawing. imaging;
Private void addtexttoimg (string filename, string text)
{
If (! File. exists (mappath (filename )))
{
Throw new filenotfoundexception ("the file don't exist! ");
}
If (text = string. Empty)
{
Return;
}
// You also need to determine whether the file type is of the image type. I will not go into details here.
System. Drawing. Image image = system. Drawing. image. fromfile (mappath (filename ));
Bitmap bitmap = new Bitmap (image, image. Width, image. Height );
Graphics G = graphics. fromimage (Bitmap );
Float fontsize = 12.0f; // font size
Float textwidth = text. length * fontsize; // the length of the text.
// The following defines a rectangle area, and then draws black characters on the rectangle.
Float rectx = 0;
Float recty = 0;
Float rectwidth = text. length * (fontsize + 8 );
Float rectheight = fontsize + 8;
// Declare the rectangular Field
Rectanglef textarea = new rectanglef (rectx, recty, rectwidth, rectheight );
Font font = new font ("", fontsize); // define the font
Brush whitebrush = new solidbrush (color. White); // white brush, used to draw text
Brush blackbrush = new solidbrush (color. Black); // black brush for background painting
G. fillrectangle (blackbrush, rectx, recty, rectwidth, rectheight );
G. drawstring (text, Font, whitebrush, textarea );
Memorystream MS = new memorystream ();
// Save as JPG
Bitmap. Save (MS, imageformat. JPEG );
// Output the processed image. For demonstration convenience, I will display the image on the page
Response. Clear ();
Response. contenttype = "image/JPEG ";
Response. binarywrite (Ms. toarray ());
G. Dispose ();
Bitmap. Dispose ();
Image. Dispose ();
}
It's easy to call,
Addtexttoimg ("me.jpg", "family. Man ");
These functions are a luxury in ASP, but they can be easily completed in the. NET environment!