Panning and specular and reflection effects for Android images

Source: Internet
Author: User

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

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.