android Bitmap旋轉問題

來源:互聯網
上載者:User

標籤:android   style   color   ar   os   java   sp   on   art   

============問題描述============


//畫筆,定義繪製屬性private Paint myPaint;private Paint mBitmapPaint;// 繪製路徑private Path myPath;// 畫布及其底層位元影像private Bitmap myBitmap0;private Bitmap myBitmap1;private Canvas myCanvas;public MyPaintView(Context context, AttributeSet attrs){super(context, attrs);myBitmap0 = BitmapFactory.decodeFile("/storage/sdcard/a.png").copy(Bitmap.Config.ARGB_8888, true);myBitmap1 = Bitmap.createBitmap(myBitmap0);if(i == 0){initialize();}else if(i == 1){initWhite();}//開啟線程new Thread(this).start();}public void initialize(){// 繪製徒手畫用的畫筆myPaint = new Paint();myPaint.setAntiAlias(true);myPaint.setDither(true);myPaint.setColor(RGBColor.getColor());myPaint.setStyle(Paint.Style.STROKE);myPaint.setStrokeJoin(Paint.Join.ROUND);myPaint.setStrokeCap(Paint.Cap.ROUND);myPaint.setStrokeWidth(RGBColor.getFontSize());myPath = new Path();mBitmapPaint = new Paint(Paint.DITHER_FLAG);}@Overrideprotected void onDraw(Canvas canvas){super.onDraw(canvas);// 背景顏色canvas.drawColor(R.color.white); canvas.drawBitmap(myBitmap1, 0, 0, mBitmapPaint);canvas.drawPath(myPath, myPaint);myCanvas = new Canvas(myBitmap1);}/*** 圖片旋轉 * */public void picPost(int nPostExtent){matrix.reset();matrix.postScale(Scale, Scale);matrix.postRotate(nPostExtent);        // 下面這句話如果把myBitmap1都改為myBitmap0的話順時針和逆時針旋轉都沒有問題,現在需要用myBitmap1,是因為在這個位元影像上面先塗鴉了再旋轉的話就會清空以前塗鴉內容,所以選用myBitmap1,但是用它的話只能朝著一個方向旋轉,先順時針完了,逆時針就回不來了myBitmap1 = Bitmap.createBitmap(myBitmap1, 0, 0, myBitmap1.getWidth(), myBitmap1.getHeight(), matrix, true);}

============解決方案1============


哦,不是90度角呀,45度角那回不來了。因為圖片是在不斷變大了,右上方不斷填充了白色地區。
把path存起來,底圖不變,每次畫圖都是底圖+path
或者把path畫在一個canvas上,把底圖在另一個bitmap上,兩個疊加。

android Bitmap旋轉問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.