亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Android開發實現圖片平移、縮放、倒影及旋轉功能的方法

發布時間:2020-09-21 14:36:25 來源:腳本之家 閱讀:272 作者:CharlinGod 欄目:移動開發

本文實例講述了Android開發實現圖片平移、縮放、倒影及旋轉功能的方法。分享給大家供大家參考,具體如下:

解析:

1)根據原來的圖片創建新的圖片

Bitmap modBm = Bitmap.createBitmap(bm.getWidth()+20, bm.getHeight()+20, bm.getConfig());

2)設置到畫布

Canvas canvas = new Canvas(modBm);

3)使用矩陣進行平移…

Matrix matrix = new Matrix();
matrix.setRotate(90, bm.getWidth()/2, bm.getHeight()/2);

4)把改變后圖片設置到

canvas.drawBitmap(bm, matrix, paint);
imageView2.setImageBitmap(modBm);

示例代碼:

1、平移:

public class TranslateImageActivity extends Activity {
  private ImageView imageView1;
  private ImageView imageView2;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_image_rotate);
    initViews();
  }
  private void initViews() {
    imageView1 = (ImageView) findViewById(R.id.imageView1);
    imageView2 = (ImageView) findViewById(R.id.imageView2);
    Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.mm0);
    imageView1.setImageBitmap(bm);
    Bitmap modBm = Bitmap.createBitmap(bm.getWidth()+20, bm.getHeight()+20, bm.getConfig());
    Canvas canvas = new Canvas(modBm);
    Paint paint = new Paint();
    paint.setColor(Color.BLACK);
    paint.setAntiAlias(true);
    Matrix matrix = new Matrix();
    //matrix.setRotate(90, bm.getWidth()/2, bm.getHeight()/2);
    matrix.setTranslate(20, 20);
    matrix.postTranslate(20, 20);
    canvas.drawBitmap(bm, matrix, paint);
    imageView2.setImageBitmap(modBm);
  }
}

2、縮放

public class ScaleImageActivity extends BaseActivity {
  private static final int DOUBLE = 2;
  private ImageView iv1, iv2;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_scale_iamge);
    iv1 = (ImageView) findViewById(R.id.imageView1);
    iv2 = (ImageView) findViewById(R.id.imageView2);
    Bitmap b1 = BitmapFactory.decodeResource(getResources(), R.drawable.p1);
    iv1.setImageBitmap(b1);
    Bitmap b2 = Bitmap.createBitmap(b1.getWidth()*DOUBLE, b1.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(b2);
    Matrix matrix = new Matrix();
    matrix.setValues(new float[]{
        DOUBLE * 1.0f, 0,    0,//x
        0,       1.0f,  0,//y
        0,       0,    1.0f//z
    });
    canvas.drawBitmap(b1, matrix, new Paint());
    iv2.setImageBitmap(b2);
  }
}

3、倒影

public class ShadeImageActivity extends Activity {
  private ImageView imageView1;
  private ImageView imageView2;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_image_rotate);
    initViews();
  }
  private void initViews() {
    imageView1 = (ImageView) findViewById(R.id.imageView1);
    imageView2 = (ImageView) findViewById(R.id.imageView2);
    Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.mm3);
    imageView1.setImageBitmap(bm);
    Bitmap modBm = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), bm.getConfig());
    Canvas canvas = new Canvas(modBm);
    Paint paint = new Paint();
    paint.setColor(Color.BLACK);
    paint.setAntiAlias(true);
    Matrix matrix = new Matrix();
    //matrix.setRotate(90, bm.getWidth()/2, bm.getHeight()/2);
    //matrix.setTranslate(20, 20);
    //鏡子效果
    matrix.setScale(1, -1);
    matrix.postTranslate(0, bm.getHeight());
    canvas.drawBitmap(bm, matrix, paint);
    imageView2.setImageBitmap(modBm);
  }
}

4、旋轉

public class RotateImageActivity extends Activity {
  private ImageView imageView1;
  private ImageView imageView2;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_image_rotate);
    initViews();
  }
  private void initViews() {
    imageView1 = (ImageView) findViewById(R.id.imageView1);
    imageView2 = (ImageView) findViewById(R.id.imageView2);
    Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.mm0);
    imageView1.setImageBitmap(bm);
    Bitmap modBm = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), bm.getConfig());
    Canvas canvas = new Canvas(modBm);
    Paint paint = new Paint();
    paint.setColor(Color.BLACK);
    paint.setAntiAlias(true);
    Matrix matrix = new Matrix();
    matrix.setRotate(90, bm.getWidth()/2, bm.getHeight()/2);
    canvas.drawBitmap(bm, matrix, paint);
    imageView2.setImageBitmap(modBm);
  }
}

更多關于Android相關內容感興趣的讀者可查看本站專題:《Android圖形與圖像處理技巧總結》、《Android開發入門與進階教程》、《Android調試技巧與常見問題解決方法匯總》、《Android基本組件用法總結》、《Android視圖View技巧總結》、《Android布局layout技巧總結》及《Android控件用法總結》

希望本文所述對大家Android程序設計有所幫助。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

吉首市| 东宁县| 墨江| 宝坻区| 金寨县| 梨树县| 蚌埠市| 北票市| 司法| 东安县| 庆城县| 浦东新区| 德钦县| 侯马市| 株洲县| 澄江县| 喀喇沁旗| 临澧县| 南安市| 兴仁县| 锡林浩特市| 横山县| 迁安市| 平舆县| 富平县| 万源市| 五华县| 呼玛县| 碌曲县| 开平市| 淮北市| 海兴县| 乐至县| 宁海县| 南江县| 广东省| 高唐县| 黄浦区| 南和县| 四平市| 方山县|