"Turn" VI, image overlay of Android image effect processing

Source: Internet
Author: User

This article will talk about the image overlay effect processed by picture effects. The same as the front face is the pixel processing, you can refer to the previous Android image processing series seven-picture graffiti, watermark-image overlay and Android image processing series six-to the picture to add a border (bottom)-image overlay two articles, This article is a little different from the previous one. The superposition principle is that the pixels of two pictures are superimposed by transparency, and no color filtering is done. Overlay images can be in JPG format, in front of the same, it is best to enlarge the assets directory. See below:

+ =

Code:

/*** Picture Effect overlay *@paramBMP limits the size of the bitmap *@return     */    PrivateBitmap Overlay (Bitmap bmp) {LongStart =System.currenttimemillis (); intwidth =bmp.getwidth (); intHeight =bmp.getheight (); Bitmap Bitmap=bitmap.createbitmap (width, height, Bitmap.Config.RGB_565); //zoom in on a border pictureBitmap overlay =Bitmapfactory.decoderesource (Mcontext.getresources (), r.drawable.rainbow_overlay); intW =overlay.getwidth (); inth =overlay.getheight (); floatScaleX = width * 1F/W; floatScaleY = height * 1F/h; Matrix Matrix=NewMatrix ();                Matrix.postscale (ScaleX, ScaleY); Bitmap overlaycopy= Bitmap.createbitmap (overlay, 0, 0, W, h, Matrix,true); intPixcolor = 0; intLaycolor = 0; intPIXR = 0; intPIXG = 0; intPIXB = 0; intPixA = 0; intNEWR = 0; intNEWG = 0; intNewb = 0; intNewa = 0; intLayr = 0; intLAYG = 0; intLayb = 0; intLayA = 0; Final floatAlpha = 0.5F; int[] Srcpixels =New int[Width *height]; int[] Laypixels =New int[Width *height]; Bmp.getpixels (Srcpixels,0, Width, 0, 0, width, height); Overlaycopy.getpixels (Laypixels,0, Width, 0, 0, width, height); intpos = 0;  for(inti = 0; i < height; i++)        {             for(intk = 0; K < width; k++) {pos= i * width +K; Pixcolor=Srcpixels[pos]; Laycolor=Laypixels[pos]; PIXR=color.red (Pixcolor); Pixg=Color.green (Pixcolor); PIXB=Color.Blue (Pixcolor); PixA=Color.alpha (Pixcolor); Layr=color.red (Laycolor); LAYG=Color.green (Laycolor); Layb=Color.Blue (Laycolor); LayA=Color.alpha (Laycolor); NEWR= (int) (PIXR * alpha + Layr * (1-Alpha)); NEWG= (int) (PIXG * alpha + LAYG * (1-Alpha)); Newb= (int) (PIXB * alpha + Layb * (1-Alpha)); LayA= (int) (PixA * alpha + LayA * (1-Alpha)); NEWR= Math.min (255, Math.max (0, NEWR)); NEWG= Math.min (255, Math.max (0, NEWG)); Newb= Math.min (255, Math.max (0, newb)); Newa= Math.min (255, Math.max (0, LayA)); Srcpixels[pos]=Color.argb (Newa, NEWR, NEWG, newb); }} bitmap.setpixels (Srcpixels,0, Width, 0, 0, width, height); LongEnd =System.currenttimemillis (); LOG.D ("May", "Overlayameliorate used time=" + (End-start)); returnbitmap; }

Overlay picture of the border is better, but also to control the size of the superimposed picture. The value of alpha variable can be modified according to demand, the proposal or more than 0.5 is better, otherwise the original will not see clearly.

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.