Achieve image watermark Effect

Source: Internet
Author: User
// Obtain the public static bitmap scalebitmap (string SRC, int max) of the reduced image {// obtain the height and width of the image bitmapfactory. options = new bitmapfactory. options (); // This setting enables bitmapfactory. the image obtained by decodefile is empty, but the image information is written to options. injustdecodebounds = true; bitmapfactory. decodefile (SRC, options); // to improve the accuracy of the calculation ratio, the original 640 is reduced to 64 max = max/10; int be = options. outwidth/max; If (be % 10! = 0) be + = 10; Be = be/10; If (be <= 0) be = 1; options. insamplesize = be; // you can obtain the data options. injustdecodebounds = false; // get the image return bitmapfactory. decodefile (SRC, options);} // Add a watermark or add the public static bitmap watermarkbitmap (Bitmap SRC, bitmap watermark, String title) {If (src = NULL) {return NULL;} int W = SRC. getwidth (); int H = SRC. getheight (); // you need to handle the problem that the memory size exceeds when the image size is too large. Here, my image is very small, so do not write the corresponding Code Bitmap newb = bitmap. createbitmap (W, H, config. argb_8888); // create a new bitmap canvas CV = new canvas (NEWB); cv. drawbitmap (SRC, 0, 0, null); // draw SRC paint = new paint () at coordinates 0, 0; // Add the image if (watermark! = NULL) {int WW = watermark. getwidth (); int wh = watermark. getheight (); paint. setalpha (50); cv. drawbitmap (watermark, W-ww + 5, H-Wh + 5, paint); // Add the watermark to the bottom right corner of SRC} // Add the text if (title! = NULL) {string familyname = ""; typeface font = typeface. create (familyname, typeface. bold); textpaint = new textpaint (); textpaint. setcolor (color. red); textpaint. settypeface (font); textpaint. settextsize (22); // The staticlayout layout = new staticlayout (title, textpaint, W, alignment. align_normal, 1.0f, 0.0f, true); layout. draw (CV); // Add the upper left corner of the text. // cv. drawtext (title, 0, 40, paint);} cv. save (canvas. all_save_flag); // Save the CV. restore (); // store return newb ;}

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.