Related processing of bitmap in Android

Source: Internet
Author: User

Load big Picture Options options=new options (); options.injustdecodebounds=true;//do not load pictures, only load file information//load pictures, Get to configuration information Bitmapfactory.decodefile (environment.getexternalstoragedirectory () + "/a.jpg", options); int width= options.outwidth;//gets to the picture's really width int height=options.outheight;//get to the picture of the really height//get to the phone screen show object display = Getwindowmanager (). Getdefaultdisplay (); int h = display.getheight ();//Gets the height of the screen int w = display.getwidth ();//gets to the width of the draw// Calculate scaling ratio int Scale=1;int scaley=width/w;int scalex=height/h;if (scalex<1 && scaley<1) {}else{//If scaled wide, greater than high , the scale ratio of the illuminance is wide, because the high scaling ratio is small, then the width exceeds the width Scale=scalex>scaley?scalex:scaley of the screen according to the high scaling ratio;} options.injustdecodebounds=true;options.insamplesize=scale;//Specify the scaling ratio//regenerate a bitmap object based on the configuration information, This gets the picture after zooming bitmap bitmap = Bitmapfactory.decodefile (environment.getexternalstoragedirectory () + "/a.jpg", options) ; Img.setimagebitmap (bitmap); Doodle 1, first load a picture bitmap bitmap = Bitmapfactory.decodefile (Environment.getexternalstoragedi Rectory () + "/a.jpg"); 2. Create an empty picture, bit = Bitmap.createbitmap (bitmap.getwIdth (), Bitmap.getheight (), Bitmap.getconfig ()); 3. Create a canvas, canvas canvas=new canvas (BIT), 4. Create a brush panint paint=new Paint (); Paint.setcolor (color.red); 5. Draw the loaded picture onto the canvas canvas.drawbitmap (bitmap) 6. Set the touch event on the picture to start the line with a watermark and the same as above, depending on where you press and move. Just add a sentence canvas.drawtext ("Hungry Oh I happen", 100,100, paint);
Save Picture Notification album scan the picture bit.compress (Compressformat.jpeg, New FileOutputStream (Environment.getexternalstoragedirectory ( ) + "/hdksh.jpg"); Intent intent=new Intent (); Intent.setaction ("Android.intent.action.MEDIA_MOUNTED"); Intent.setdata (Uri.fromfile (New File (environment.getexternalstoragedirectory () + "hdksh.jpg")); Sendbroadcast ( intent);//Send broadcast, notify album scan
The rotation of the picture bitmap Bitmap=bitmapfactory.decodefile (environment.getexternalstoragedirectory () + "/mm.jpg"); Bitmap bit = Bitmap.createbitmap (Bitmap.getwidth (), Bitmap.getheight (), Bitmap.getconfig ()); Canvas canvas=new canvas (bit); Matrix Matrix=new Matrix (matrix.setrotate), Bitmap.getwidth (2, Bitmap.getheight ()/2); Paint paint=new Paint ();p aint.setcolor (color.red) canvas.drawbitmap (bitmap, matrix, paint); Img.setimagebitmap (bit)
Mirror effect Bitmap bitmap = Bitmapfactory.decodefile (environment.getexternalstoragedirectory () + "/mm.jpg"); Bitmap bit = Bitmap.createbitmap (Bitmap.getwidth (), Bitmap.getheight (), Bitmap.getconfig ()); Canvas canvas=new canvas (bit); Paint paint=new paint (); Matrix matrix=new Matrix (); Matrix.setscale (-1, 1);//Invert Matrix.posttranslate (Bitmap.getwidth (), 0);// Mobile Canvas.drawbitmap (bitmap, matrix, paint); Img.setimagebitmap (bit);

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.