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