Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android圖片3D傾斜。如圖

android圖片3D傾斜。如圖

編輯:關於Android編程

 


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; 
  } 
} 

 

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved