Add copyright information to an image in asp.net

Source: Internet
Author: User
asp.net you ever try to use. NET for image processing? The company recently carried out a project, the database stored in a lot of product pictures, but there is no copyright information, at that time, the customer asked all the pictures to hit the company name? What do you do at this time?

Although I am still a river, but the solution to this problem is still a lot, summed up as follows:
1. Using graphics processing software, such as Photoshop, using its batch processing function, you can realize this function, but each data entry member added to the picture, but also to process the picture, very troublesome, see the input of the elder sister usually to me very good, daily smiling face, can bear to torture her? The plan was rejected.

2. The use of. NET smooth-flowing image processing, when the input of the elder sister upload pictures, automatically add company tag, so not better, well, this idea is good, can enter the 2005 best solution 0th Strong, say dry on.

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 an image type, so here's the

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; Length of text
The following defines a rectangular area, in which the white and black characters are later painted in the rectangle.
float rectx = 0;
float recty = 0;
float rectwidth = text. length* (FONTSIZE+8);
float rectheight = fontsize+8;
Declaring a rectangular field
RectangleF TextArea = new RectangleF (rectx,recty,rectwidth,rectheight);

Font font = new Font ("Song Body", FontSize); Defining fonts
Brush Whitebrush = new SolidBrush (color.white); White brush, painting text with
Brush Blackbrush = new SolidBrush (color.black); Black Brush, drawing background

G.fillrectangle (Blackbrush,rectx,recty,rectwidth,rectheight);

g.DrawString (Text,font,whitebrush,textarea);
MemoryStream ms = new MemoryStream ();
Save as JPG type
Bitmap. Save (Ms,imageformat.jpeg);

Output processing image, here for demonstration convenience, I will display the picture in the page
Response.Clear ();
Response.ContentType = "Image/jpeg";
Response.BinaryWrite (Ms. ToArray ());

G.dispose ();
Bitmap. Dispose ();
Image. Dispose ();
}

It's simple to call,

Addtexttoimg ("Me.jpg", "Family.man");

These features are luxuries in the ASP, while in the. NET environment is easy to complete!



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.