This article allows you to zoom in on images in Android
First design the layout:
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical"Tools:context=". Mainactivity " > <ImageViewAndroid:id= "@+id/iv_1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content" /> <ImageViewAndroid:id= "@+id/iv_2"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content" /></LinearLayout>
The logic code is as follows:
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.ic_launcher); Iv1.setimagebitmap (BITMAP1); //Create a new bitmapBitmap Alterbitmap =Bitmap.createbitmap (Bitmap1.getwidth (), Bitmap1.getheight (), 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 (); matrix.setvalues ( new float[] { 0.5f, 0, 0, 0, 1, 0, 0, 0, 1 }); //set up the canvasCanvas.drawbitmap (Bitmap1, Matrix, paint); Iv2.setimagebitmap (ALTERBITMAP); }}
If you do not have a clear set of matrices, you can also replace the code in the markup section with the methods provided by the following API:
Matrix.setscale (0.5f, 1);
The final run of the project results in the following:
Scaling of Android images