This problem occurs when a watermark image is generated! (Graphics objects cannot be created from images with indexed pixel formats .)

Source: Internet
Author: User

The main reason is that the original type of the uploaded image is GIF, so you must first map the original image, and then save the bitmap.

 

/// <Summary>
/// Add a watermark to the image
/// </Summary>
/// <Param name = "strpath"> original file </param>
/// <Param name = "strpathsyp"> watermark file </param>
/// <Param name = "strpathsypf"> watermark result file </param>

Public static void addwaterpic (string strpath, string strpathsyp, string strpathsypf)
{
System. Drawing. Image image = system. Drawing. image. fromfile (strpath );
Bitmap Bm = new Bitmap (image );

System. Drawing. Image copyimage = system. Drawing. image. fromfile (strpathsyp );

System. Drawing. Graphics G = system. Drawing. Graphics. fromimage (BM );

// If You Want to center the watermark, you only need to change the values of BM. Width-copyimage. Width and BM. Height-copyimage. Height.

// You can use convert. toint32 (image. Width * 0.3), convert. toint32 (image. Height * 0.3)

G. drawimage (copyimage, new system. drawing. rectangle (BM. width-copyimage. width, BM. height-copyimage. height, copyimage. width, copyimage. height), 0, 0, copyimage. width, copyimage. height, system. drawing. graphicsunit. pixel );
G. Dispose ();
Copyimage. Dispose ();
BM. Save (strpathsypf );
BM. Dispose ();
}

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.