Display Method Summary of transparent Images

Source: Internet
Author: User
Display Method Summary of transparent ImagesMethod 1: Use the drawargb method of canvas.
@ Overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); // create an image. Bitmap Bm = bitmap. createbitmap (20, 20, config. argb_4444); // color the image. The first parameter is the transparency setting. Canvas CVS = new canvas (BM); cvs. drawargb (127,255,); // create an imageview object. Imageview IMV = new imageview (this); // load the image to an imageview object. IMV. setimagebitmap (BM); // display the image on the screen. Setcontentview (IMV );}

Method 2: Use drawargb of canvas and erasecolor of Bitmap.

Public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); // create an image. Bitmap Bm = bitmap. createbitmap (20, 20, config. argb_4444); // color the image. The first parameter is the transparency setting. Canvas CVS = new canvas (BM); cvs. drawargb (127,255,); // use the bitmap method to erase the red color, which is transparent. BM. erasecolor (0xff0000); // create an imageview object. Imageview IMV = new imageview (this); // load the image to an imageview object. IMV. setimagebitmap (BM); // display the image on the screen. Setcontentview (IMV );}

Method 3: Use the setalpha method of imageview.
Public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); // create an image. Bitmap Bm = bitmap. createbitmap (20, 20, config. argb_4444); // color the image. The first parameter is the transparency setting. Canvas CVS = new canvas (BM); cvs. drawargb (255,255,); // create an imageview object. Imageview IMV = new imageview (this); // load the image to an imageview object. IMV. setimagebitmap (BM); // sets the image transparency. IMV. setalpha (127); // display the image on the screen. Setcontentview (IMV );}

Method 4: Use the getpaint (). setcolor method of drawable.

Public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); // create an image. Bitmap Bm = bitmap. createbitmap (20, 20, config. argb_4444); // beautify the image. Canvas CVS = new canvas (BM); cvs. drawargb (255,255,); // create an imageview. Imageview IMV = new imageview (this); // sets the image transparency. The first two values are the transparency values. Bitmapdrawable BD = new bitmapdrawable (BM); Bd. getpaint (). setcolor (0x00ffffff); // load the image to the imageview object. IMV. setimagebitmap (BM); // display the image on the screen. Setcontentview (IMV );}

Note: These four methods have been found for the moment. If I find a new method, I will edit this article.

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.