Image processing in Android

Source: Internet
Author: User

Large picture Processing

Large picture processing is to convert the original pixel high into a low-pixel picture, such as the original picture is 1024x768, and the phone screen is 800*600, this time it is necessary to convert. The simple way to convert is to scale proportionally.

 PackageXidian.dy.com.chujia;ImportAndroid.graphics.Bitmap;Importandroid.graphics.BitmapFactory;ImportAndroid.os.Bundle;Importandroid.os.Environment;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.view.Display;ImportAndroid.view.View;ImportAndroid.widget.ImageView;ImportJava.io.File; Public classMainactivityextendsappcompatactivity {@Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);    Setcontentview (R.layout.main); }     Public voidload (View v) {bitmapfactory.options Options=Newbitmapfactory.options (); File File=NewFile (Environment.getexternalstoragedirectory (), "A.dog"); Options.injustdecodebounds=true;        Bitmapfactory.decodefile (File.tostring (), options); //Get picture Width height        intImgWidth =Options.outwidth; intImgHeight =Options.outheight; //Get screen width heightDisplay DSP =Getwindowmanager (). Getdefaultdisplay (); intScreanwidth =dsp.getwidth (); intScreanheight =dsp.getheight (); //Calculating the zoom ratio        intScaleWidth = imgwidth/Screanwidth; intScaleHeight = imgheight/Screanheight; intScale = ScaleHeight >= scalewidth?Scaleheight:scalewidth; if(Scale < 1) Scale= 1; //Set the zoom scale (the scale should be greater than 1 scaling to function)Options.insamplesize =Scale ; Options.injustdecodebounds=false; Bitmap BM=Bitmapfactory.decodefile (File.tostring (), options); ImageView img=(ImageView) Findviewbyid (R.ID.IV); if(img! =NULL) Img.setimagebitmap (BM); }}
Picture copy

Create a copy of the picture to make changes to the picture, the following code reverses the picture horizontally

 PackageXidian.dy.com.chujia;ImportAndroid.graphics.Bitmap;Importandroid.graphics.BitmapFactory;ImportAndroid.graphics.Canvas;ImportAndroid.graphics.Matrix;ImportAndroid.graphics.Paint;ImportAndroid.os.Bundle;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.widget.ImageView; Public classMainactivityextendsappcompatactivity {@Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.main); Bitmap BM= Bitmapfactory.decodefile ("/sdcard/a.dog"); //Create a Bitmap object that is as wide as the original, and can be viewed as a paperBitmap bmcpy =Bitmap.createbitmap (Bm.getwidth (), Bm.getheight (), Bm.getconfig ()); //Create a Brush objectPaint paint =NewPaint (); //create an Artboard object and lay the drawing paper on the artboardCanvas Canvas =NewCanvas (bmcpy); //Start Painting//Flip the picture horizontallyMatrix MT =NewMatrix (); Mt.setscale (-1, 1); Mt.posttranslate (Bmcpy.getwidth (),0);        Canvas.drawbitmap (BM, MT, paint); ImageView IV=(ImageView) Findviewbyid (R.ID.IV2);        Iv.setimagebitmap (bmcpy); ImageView Iv1=(ImageView) Findviewbyid (R.ID.IV1);    Iv1.setimagebitmap (BM); }}

Image processing in Android

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.