Android圖片處理基礎方式

位圖副本的操作步驟

  1. 得到原始圖片的對象
    * Bitmap srcBitmap = BitmapFactory.decodeFile(“/mnt/sdcard/tu1.jpg”);
  2. 創建圖片對象的副本(空白副本)
    *Bitmap copyedBitmap = Bitmap.createBitmap(srcBitmap.getWidth(), srcBitmap.getHeight(), srcBitmap.getConfig());

  3. 創建畫板對象
    *Canvas canvas = new Canvas(copyedBitmap);

  4. 創建畫筆
    *Paint paint = new Paint();
    *paint.setColor(Color.BLACK);

  5. 作畫

    • canvas.drawBitmap(srcBitmap, matrix, paint);
    • // matrix : 位圖矩陣對象,用來對圖片精選縮放平移等效果的
    • 這裏寫圖片描述

    縮放

    Matrix matrix = new Matrix();
    matrix.setScale(0.6f, 0.6f);//縮放比例

    平移

    Matrix matrix = new Matrix();
    matrix.settranslate(100,100);//平移距離

    旋轉

    Matrix matrix = new Matrix();
    matrix.setRotate(180,srcBitmap.getWidth()/2, srcBitmap.getHeight()/2);/角度和中心點

    鏡面特效

    Matrix matrix = new Matrix();
    matrix.setScale(-1, 1);
    matrix.postTranslate(srcBitmap.getWidth(), 0);

    倒影特效

    Matrix matrix = new Matrix();
    matrix.setScale(1, -1);
    matrix.postTranslate(0, srcBitmap.getHeight());

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章