View conversion to image for some functionality

Source: Internet
Author: User

Use the scene:
1. Create a custom picture.
2, custom clickable Imagespan, meaning to customize a dynamically generated picture.
Wait a minute

View view = Layoutinflater.from (Mcontext). Inflate (R.layout.xxxxxxxxx,NULL);                     ((ImageView) View.findviewbyid (r.id.xxxxxxxxx)). Setimagebitmap (Result.iconbitmap);                     ((TextView) View.findviewbyid (r.id.xxxxxxxxx)). SetText (Result.equip_name); //measure the size of a view                     intSpec = View.MeasureSpec.makeMeasureSpec (0, View.MeasureSpec.UNSPECIFIED);                     View.measure (spec, spec); //call the layout of the viewView.layout (0, 0, View.getmeasuredwidth (), View.getmeasuredheight ()); //Create paint to draw the interfaceBitmap B =Bitmap.createbitmap (View.getmeasuredwidth (), View.getmeasuredheight (), Bitmap.Config.ARGB_8888); Canvas C=NewCanvas (b); C.translate (-VIEW.GETSCROLLX (),-view.getscrolly ());                     View.draw (c); View.setdrawingcacheenabled (true); //gets the cache of the bitmap and copies a copy of theBitmap cachebmp =View.getdrawingcache (); Bitmap viewbmp= Cachebmp.copy (Bitmap.Config.ARGB_8888,true); //release the drawing's cacheView.destroydrawingcache (); bitmapdrawable BD=Newbitmapdrawable (Mcontext.getresources (), viewbmp); Bd.setbounds (0, 0, Bd.getintrinsicwidth (), Bd.getintrinsicheight ()); //put CacheBitmapcache cache =mbitmapcache.get (source); if(Cache! =NULL&& Cache.bitmap! =NULL) {cache.bitmap.clear (); } Cache=NewBitmapcache (); Cache.bitmap=NewWeakreference<bitmap>(Bd.getbitmap ()); Cache.scale= 1.0f;                                                               Mbitmapcache.put (source, cache); if(Mlistener! =NULL) {Mlistener.onloadingcomplete (NULL,NULL, viewbmp); }

1, drawable is a can be drawn object, it may be a bitmap (bitmapdrawable), it may be a graph (shapedrawable), there may be a layer (layerdrawable), we based on the demand for paint, Create the appropriate object to draw
2, canvas canvas, the destination area of the drawing, for drawing
3, Bitmap bitmap, for the processing of graphs

SetBounds (), this method is to determine the size of the picture, if not set, then the picture is 0 long width! Of course, you can adjust the image size by this method if the effect is too large or too small for you to display.

Android in bitmap and drawable

http://dyh7077063.iteye.com/blog/970672

View conversion to image for some functionality

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.