android圖片3D傾斜。如圖

來源:互聯網
上載者:User

 


Bitmap    bit=Reflect3DImage.skewImage(bit, 50);

package com.maxway.util;   import android.graphics.Bitmap; import android.graphics.Bitmap.Config; import android.graphics.Camera; import android.graphics.Canvas; import android.graphics.LinearGradient; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.PorterDuff; import android.graphics.PorterDuff.Mode; import android.graphics.PorterDuffXfermode; import android.graphics.Shader; import android.graphics.Shader.TileMode; public class Reflect3DImage {   public static Bitmap createReflectedImage(Bitmap paramBitmap, int paramInt)   {     int i = paramBitmap.getWidth();     int j = paramBitmap.getHeight();     Matrix localMatrix = new Matrix();     localMatrix.preScale(1.0F, -1.0F);     Bitmap localBitmap1 = Bitmap.createBitmap(paramBitmap, 0, j - paramInt, i, paramInt, localMatrix, false);     Bitmap localBitmap2 = Bitmap.createBitmap(i, j + paramInt, Bitmap.Config.ARGB_8888);     Canvas localCanvas = new Canvas(localBitmap2);     Paint localPaint1 = new Paint();     localCanvas.drawBitmap(paramBitmap, 0.0F, 0.0F, localPaint1);     localCanvas.drawBitmap(localBitmap1, 0.0F, j, localPaint1);     Paint localPaint2 = new Paint();     localPaint2.setShader(new LinearGradient(0.0F, paramBitmap.getHeight(), 0.0F, localBitmap2.getHeight(), 1895825407, 16777215, Shader.TileMode.MIRROR));     localPaint2.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));     localCanvas.drawRect(0.0F, j, i, localBitmap2.getHeight(), localPaint2);     localBitmap1.recycle();     return localBitmap2;   }    public static Bitmap skewImage(Bitmap paramBitmap, int paramInt)   {     Bitmap localBitmap1 = createReflectedImage(paramBitmap, paramInt);     Camera localCamera = new Camera();     localCamera.save();     Matrix localMatrix = new Matrix();     localCamera.rotateY(15.0F);     localCamera.getMatrix(localMatrix);     localCamera.restore();     localMatrix.preTranslate(-localBitmap1.getWidth() >> 1, -localBitmap1.getHeight() >> 1);     Bitmap localBitmap2 = Bitmap.createBitmap(localBitmap1, 0, 0, localBitmap1.getWidth(), localBitmap1.getHeight(), localMatrix, true);     Bitmap localBitmap3 = Bitmap.createBitmap(localBitmap2.getWidth(), localBitmap2.getHeight(), Bitmap.Config.ARGB_8888);     Canvas localCanvas = new Canvas(localBitmap3);     Paint localPaint = new Paint();     localPaint.setAntiAlias(true);     localPaint.setFilterBitmap(true);     localCanvas.drawBitmap(localBitmap2, 0.0F, 0.0F, localPaint);     localBitmap2.recycle();     return localBitmap3;   } } 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.