In the previous article on the introduction of the image rotation and scaling, this article continues to describe the operation of the picture
Panning the picture
Use the following code to shift the horizontal vertical direction of the diagram by 10 pixels
Matrix.settranslate (10, 10);
You can see that the picture is incomplete and you need to modify the code:
// Create a new bitmap Bitmap Alterbitmap = Bitmap.createbitmap (Bitmap1.getwidth () * 2, * 2, Bitmap1.getconfig ());
No other code is changed
The mirror effect of the picture
The code is as follows:
Matrix.setscale ( -1, 10);
The effect of the implementation:
The reflection effect of the picture
The code is as follows:
// Reflection Effect Matrix.setscale (1,-1); Matrix.posttranslate (0, Bitmap1.getheight ());
The effect of the implementation:
The complete code is as follows:
Packagecom.wuyudong.resize;ImportAndroid.os.Bundle;Importandroid.app.Activity;ImportAndroid.graphics.Bitmap;Importandroid.graphics.BitmapFactory;ImportAndroid.graphics.Canvas;ImportAndroid.graphics.Color;ImportAndroid.graphics.Matrix;ImportAndroid.graphics.Paint;ImportAndroid.view.Menu;ImportAndroid.widget.ImageView; Public classMainactivityextendsActivity {PrivateImageView Iv1; PrivateImageView Iv2; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); Iv1=(ImageView) Findviewbyid (r.id.iv_1); Iv2=(ImageView) Findviewbyid (r.id.iv_2); //set the icon for the first bitmapBitmap Bitmap1 =Bitmapfactory.decoderesource (Getresources (), r.drawable.unlock); Iv1.setimagebitmap (BITMAP1); //Create a new bitmapBitmap Alterbitmap = Bitmap.createbitmap (Bitmap1.getwidth () * 2, Bitmap1.getheight ()* 2, Bitmap1.getconfig ()); //Create a new canvas with Alterbitmap as a templateCanvas Canvas =NewCanvas (ALTERBITMAP); //create a new brush and set propertiesPaint paint =NewPaint (); Paint.setcolor (Color.Black); //Create a new matrix and set the zoom valueMatrix Matrix =NewMatrix (); //Mirror Effect//Matrix.setscale (-1, 1); //matrix.posttranslate (bitmap1.getwidth (), 0); //Reflection EffectMatrix.setscale (1,-1); Matrix.posttranslate (0, Bitmap1.getheight ()); //Panning Effect//matrix.settranslate (10, 10); //set up the canvasCanvas.drawbitmap (Bitmap1, Matrix, paint); Iv2.setimagebitmap (ALTERBITMAP); }}
Panning and mirroring and reflection of Android pictures