這個(gè)博文,是在上一篇的基礎(chǔ)上修改而成,這次是控制圖片左右移動(dòng),上下移動(dòng)類似就不在寫了
創(chuàng)新互聯(lián)成都網(wǎng)站建設(shè)專業(yè)公司,是成都網(wǎng)站推廣公司,為成都酒店設(shè)計(jì)提供網(wǎng)站建設(shè)服務(wù),有成熟的網(wǎng)站定制合作流程,提供網(wǎng)站定制設(shè)計(jì)服務(wù):原型圖制作、網(wǎng)站創(chuàng)意設(shè)計(jì)、前端HTML5制作、后臺(tái)程序開發(fā)等。成都網(wǎng)站建設(shè)熱線:18982081108package com.yuanlp.testp_w_picpath; 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.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.ImageView; public class MainActivity extends AppCompatActivity { private ImageView iv; private int dx=0; //左移的距離 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); iv = (ImageView) findViewById(R.id.iv); } public void turnBig(View view){ Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.meinv); Matrix matrix=new Matrix(); matrix.setScale(2,2); //放大四倍,水平方向2倍,豎直方向2倍 //買一張紙 Bitmap bitmap1 = Bitmap.createBitmap(bitmap.getWidth() * 2, bitmap.getHeight() * 2, bitmap.getConfig()); //買個(gè)畫板 Canvas canvas = new Canvas(bitmap1); //臨摹會(huì)話 Paint paint = new Paint(); paint.setColor(Color.BLACK); canvas.drawBitmap(bitmap,matrix,paint); //傳入新紙 iv.setImageBitmap(bitmap1); } public void turnSmall(View view){ Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.meinv); Matrix matrix=new Matrix(); matrix.setScale(0.5f,0.5f); //買個(gè)紙 Bitmap bitmap1 = Bitmap.createBitmap(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getConfig()); //買個(gè)畫板 Canvas canvas=new Canvas(bitmap1); Paint paint=new Paint(); paint.setColor(Color.BLACK); canvas.drawBitmap(bitmap,matrix,paint); iv.setImageBitmap(bitmap1); } public void turnLeft(View view){ Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.meinv); dx--; //每次點(diǎn)擊,向左移動(dòng) Matrix matrix=new Matrix(); matrix.setTranslate(dx,0); //豎直方向不移動(dòng),只有左邊移動(dòng) //買個(gè)紙 Bitmap bitmap1 = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig()); //買個(gè)畫板 Canvas canvas=new Canvas(bitmap1); Paint paint=new Paint(); canvas.drawColor(Color.WHITE); paint.setColor(Color.BLACK); canvas.drawBitmap(bitmap,matrix,paint); iv.setImageBitmap(bitmap1); } public void turnRight(View view){ Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.meinv); dx++; //每次點(diǎn)擊,向左移動(dòng) Matrix matrix=new Matrix(); matrix.setTranslate(dx,0); //豎直方向不移動(dòng),只有左邊移動(dòng) //買個(gè)紙 Bitmap bitmap1 = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig()); //買個(gè)畫板 Canvas canvas=new Canvas(bitmap1); Paint paint=new Paint(); canvas.drawColor(Color.WHITE); paint.setColor(Color.BLACK); canvas.drawBitmap(bitmap,matrix,paint); iv.setImageBitmap(bitmap1); } }
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。