图片放大缩小旋转左移右移镜像倒影android

图片放大缩小旋转左移右移镜像倒影android,第1张

概述               图片放大缩小旋转左移右移镜像倒影demo:TestImage1.将meinv.jpg图片拷贝到以下目录TestImage\app\src\main\res\mipmap-hdpi1.AndroidManifest.xml<?xmlversion="1.0"encoding="utf-8"?><manifestxmlns:android="h                              图片放大缩小旋转左移右移镜像倒影

demo:

Testimage

1. 将 meinv.jpg 图片拷贝到以下目录Testimage\app\src\main\res\mipmap-hdpi

1.AndroIDManifest.xml

<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID"    package="com.glsite.testimage">    <application        androID:allowBackup="true"        androID:icon="@mipmap/ic_launcher"        androID:label="@string/app_name"        androID:roundIcon="@mipmap/ic_launcher_round"        androID:supportsRtl="true"        androID:theme="@style/Apptheme">        <activity androID:name=".MainActivity">            <intent-filter>                <action androID:name="androID.intent.action.MAIN" />                <category androID:name="androID.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application></manifest>

2.activity_main.xml

<?xml version="1.0" enCoding="utf-8"?><androID.support.constraint.ConstraintLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:app="http://schemas.androID.com/apk/res-auto"    xmlns:tools="http://schemas.androID.com/tools"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    tools:context=".MainActivity">    <ImageVIEw        androID:ID="@+ID/iv"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        app:layout_constraintBottom_toBottomOf="parent"        app:layout_constraintleft_toleftOf="parent"        app:layout_constraintRight_toRightOf="parent"        app:layout_constrainttop_totopOf="parent"        androID:src="@mipmap/meinv"/>    <button        androID:ID="@+ID/button"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_marginStart="8dp"        androID:layout_marginleft="8dp"        androID:layout_margintop="8dp"        androID:onClick="turnBig"        androID:text="放大"        app:layout_constraintStart_toStartOf="parent"        app:layout_constrainttop_totopOf="parent" />    <button        androID:ID="@+ID/button2"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_margintop="8dp"        androID:layout_marginEnd="8dp"        androID:layout_marginRight="8dp"        androID:onClick="turnSmall"        androID:text="缩小"        app:layout_constraintEnd_toEndOf="parent"        app:layout_constrainttop_totopOf="parent" /></androID.support.constraint.ConstraintLayout>

3.activity_main2.xml

<?xml version="1.0" enCoding="utf-8"?><androID.support.constraint.ConstraintLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:app="http://schemas.androID.com/apk/res-auto"    xmlns:tools="http://schemas.androID.com/tools"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    tools:context=".MainActivity">    <ImageVIEw        androID:ID="@+ID/iv"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        app:layout_constraintBottom_toBottomOf="parent"        app:layout_constraintleft_toleftOf="parent"        app:layout_constraintRight_toRightOf="parent"        app:layout_constrainttop_totopOf="parent"        androID:src="@mipmap/meinv"/>    <button        androID:ID="@+ID/button"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_marginStart="8dp"        androID:layout_marginleft="8dp"        androID:layout_margintop="8dp"        androID:onClick="turnleft"        androID:text="左移"        app:layout_constraintStart_toStartOf="parent"        app:layout_constrainttop_totopOf="parent" />    <button        androID:ID="@+ID/button2"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_margintop="8dp"        androID:layout_marginEnd="8dp"        androID:layout_marginRight="8dp"        androID:onClick="turnRight"        androID:text="右移"        app:layout_constraintEnd_toEndOf="parent"        app:layout_constrainttop_totopOf="parent" /></androID.support.constraint.ConstraintLayout>

4.activity_main3.xml

<?xml version="1.0" enCoding="utf-8"?><androID.support.constraint.ConstraintLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:app="http://schemas.androID.com/apk/res-auto"    xmlns:tools="http://schemas.androID.com/tools"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    tools:context=".MainActivity">    <ImageVIEw        androID:ID="@+ID/iv"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        app:layout_constraintBottom_toBottomOf="parent"        app:layout_constraintleft_toleftOf="parent"        app:layout_constraintRight_toRightOf="parent"        app:layout_constrainttop_totopOf="parent"        androID:src="@mipmap/meinv"/>    <button        androID:ID="@+ID/button"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_marginStart="8dp"        androID:layout_marginleft="8dp"        androID:layout_margintop="8dp"        androID:onClick="turnCircleleft"        androID:text="逆时针旋转"        app:layout_constraintStart_toStartOf="parent"        app:layout_constrainttop_totopOf="parent" />    <button        androID:ID="@+ID/button2"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_margintop="8dp"        androID:layout_marginEnd="8dp"        androID:layout_marginRight="8dp"        androID:onClick="turnCircleRight"        androID:text="顺时针旋转"        app:layout_constraintEnd_toEndOf="parent"        app:layout_constrainttop_totopOf="parent" /></androID.support.constraint.ConstraintLayout>

5.activity_main4.xml

<?xml version="1.0" enCoding="utf-8"?><androID.support.constraint.ConstraintLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:app="http://schemas.androID.com/apk/res-auto"    xmlns:tools="http://schemas.androID.com/tools"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    tools:context=".MainActivity">    <ImageVIEw        androID:ID="@+ID/iv"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        app:layout_constraintBottom_toBottomOf="parent"        app:layout_constraintleft_toleftOf="parent"        app:layout_constraintRight_toRightOf="parent"        app:layout_constrainttop_totopOf="parent"        androID:src="@mipmap/meinv"/>    <button        androID:ID="@+ID/button"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_marginStart="8dp"        androID:layout_marginleft="8dp"        androID:layout_margintop="8dp"        androID:onClick="click01"        androID:text="倒影"        app:layout_constraintStart_toStartOf="parent"        app:layout_constrainttop_totopOf="parent" />    <button        androID:ID="@+ID/button2"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_margintop="8dp"        androID:layout_marginEnd="8dp"        androID:layout_marginRight="8dp"        androID:onClick="click02"        androID:text="镜面"        app:layout_constraintEnd_toEndOf="parent"        app:layout_constrainttop_totopOf="parent" /></androID.support.constraint.ConstraintLayout>

 

6.MainActivity.java

package com.glsite.testimage;import androID.graphics.Bitmap;import androID.graphics.BitmapFactory;import androID.graphics.Canvas;import androID.graphics.color;import androID.graphics.Matrix;import androID.graphics.Paint;import androID.support.v7.app.AppCompatActivity;import androID.os.Bundle;import androID.vIEw.VIEw;import androID.Widget.ImageVIEw;public class MainActivity extends AppCompatActivity {    private ImageVIEw mIv;    private int dx = 0;    private int degress = 0;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main4);        mIv = findVIEwByID(R.ID.iv);    }    /**     * 放大     * @param vIEw     */    public voID turnBig(VIEw vIEw) {        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.meinv);        Matrix matrix = new Matrix();        matrix.setScale(2, 2);        // 1.买一张纸        Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWIDth() * 2, bitmap.getHeight() * 2, bitmap.getConfig());        // 2.买一个画板        Canvas canvas = new Canvas(newBitmap);        // 3.临摹绘画        Paint paint = new Paint();        paint.setcolor(color.BLACK);        canvas.drawBitmap(bitmap, matrix, paint);        mIv.setimageBitmap(newBitmap);    }    /**     * 缩小     * @param vIEw     */    public voID turnSmall(VIEw vIEw) {        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.meinv);        Matrix matrix = new Matrix();        matrix.setScale(0.5f, 0.5f);        // 1.买一张纸        Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWIDth() / 2, bitmap.getHeight() / 2, bitmap.getConfig());        // 2.买一个画板        Canvas canvas = new Canvas(newBitmap);        // 3.临摹绘画        Paint paint = new Paint();        paint.setcolor(color.BLACK);        canvas.drawBitmap(bitmap, matrix, paint);        mIv.setimageBitmap(newBitmap);    }    /**     * 左移     * @param vIEw     */    public voID turnleft(VIEw vIEw) {        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.meinv);        Matrix matrix = new Matrix();        dx--;        matrix.setTranslate(dx, 0);        // 1.买一张纸        Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWIDth(), bitmap.getHeight(), bitmap.getConfig());        // 2.买一个画板        Canvas canvas = new Canvas(newBitmap);        // 3.临摹绘画        Paint paint = new Paint();        canvas.drawcolor(color.WHITE);        paint.setcolor(color.BLACK);        canvas.drawBitmap(bitmap, matrix, paint);        mIv.setimageBitmap(newBitmap);    }    /**     * 右移     * @param vIEw     */    public voID turnRight(VIEw vIEw) {        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.meinv);        Matrix matrix = new Matrix();        dx++;        matrix.setTranslate(dx, 0);        // 1.买一张纸        Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWIDth(), bitmap.getHeight(), bitmap.getConfig());        // 2.买一个画板        Canvas canvas = new Canvas(newBitmap);        // 3.临摹绘画        Paint paint = new Paint();        canvas.drawcolor(color.WHITE);        paint.setcolor(color.BLACK);        canvas.drawBitmap(bitmap, matrix, paint);        mIv.setimageBitmap(newBitmap);    }    /**     * 逆时针旋转     * @param vIEw     */    public voID turnCircleleft(VIEw vIEw) {        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.meinv);        Matrix matrix = new Matrix();        matrix.setRotate(--degress, bitmap.getWIDth(), bitmap.getHeight());        matrix.postTranslate(100, 100);        // 1.买一张纸        Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWIDth()*2, bitmap.getHeight()*2, bitmap.getConfig());        // 2.买一个画板        Canvas canvas = new Canvas(newBitmap);        // 3.临摹绘画        Paint paint = new Paint();        canvas.drawcolor(color.WHITE);        paint.setcolor(color.BLACK);        paint.setAntiAlias(true);// 消除锯齿        canvas.drawBitmap(bitmap, matrix, paint);        mIv.setimageBitmap(newBitmap);    }    /**     * 顺时针旋转     * @param vIEw     */    public voID turnCircleRight(VIEw vIEw) {        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.meinv);        Matrix matrix = new Matrix();        matrix.setRotate(++degress, bitmap.getWIDth(), bitmap.getHeight());        matrix.postTranslate(100, 100);        // 1.买一张纸        Bitmap newBitmap = Bitmap.createBitmap((int)(bitmap.getWIDth()*1.5), (int)(bitmap.getHeight()*1.5), bitmap.getConfig());        // 2.买一个画板        Canvas canvas = new Canvas(newBitmap);        // 3.临摹绘画        Paint paint = new Paint();        canvas.drawcolor(color.WHITE);        paint.setcolor(color.BLACK);        paint.setAntiAlias(true);// 消除锯齿        canvas.drawBitmap(bitmap, matrix, paint);        mIv.setimageBitmap(newBitmap);    }    /**     * 倒影     * @param vIEw     */    public voID click01(VIEw vIEw) {        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.meinv);        Matrix matrix = new Matrix();        matrix.setScale(1, -1);        matrix.postTranslate(0, bitmap.getHeight());        // 1.买一张纸        Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWIDth(), bitmap.getHeight(), bitmap.getConfig());        // 2.买一个画板        Canvas canvas = new Canvas(newBitmap);        // 3.临摹绘画        Paint paint = new Paint();        canvas.drawcolor(color.WHITE);        paint.setcolor(color.BLACK);        paint.setAntiAlias(true);// 消除锯齿        canvas.drawBitmap(bitmap, matrix, paint);        mIv.setimageBitmap(newBitmap);    }    /**     * 镜面     * @param vIEw     */    public voID click02(VIEw vIEw) {        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.meinv);        Matrix matrix = new Matrix();        matrix.setScale(-1, 1);        matrix.postTranslate(bitmap.getWIDth(), 0);        // 1.买一张纸        Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWIDth(), bitmap.getHeight(), bitmap.getConfig());        // 2.买一个画板        Canvas canvas = new Canvas(newBitmap);        // 3.临摹绘画        Paint paint = new Paint();        canvas.drawcolor(color.WHITE);        paint.setcolor(color.BLACK);        paint.setAntiAlias(true);// 消除锯齿        canvas.drawBitmap(bitmap, matrix, paint);        mIv.setimageBitmap(newBitmap);    }}

 

 

 

总结

以上是内存溢出为你收集整理的图片放大缩小旋转左移右移镜像倒影android全部内容,希望文章能够帮你解决图片放大缩小旋转左移右移镜像倒影android所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1104916.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存