Android examples for Graphics:Bitmap Effect
get Skewed Bitmap
import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; import android.graphics.Bitmap.Config; import android.graphics.BitmapFactory; import android.graphics.BitmapFactory.Options; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.LinearGradient; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.PixelFormat; import android.graphics.PorterDuff.Mode; import android.graphics.PorterDuffXfermode; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.Shader.TileMode; import android.graphics.YuvImage; import android.graphics.drawable.Drawable; public class Main{ //w w w.j ava 2 s . com private static final String TAG = ImgUtil.class.getSimpleName(); public static Bitmap getSkewedBitmap(Bitmap src, float kx, float ky, boolean recycleSrc) { Matrix matrix = new Matrix(); matrix.setSkew(kx, ky); return getTransformedBitmap(src, matrix, recycleSrc); } public static Bitmap getSkewedBitmap(Bitmap src, float kx, float ky, float px, float py, boolean recycleSrc) { Matrix matrix = new Matrix(); matrix.setSkew(kx, ky, px, py); return getTransformedBitmap(src, matrix, recycleSrc); } public static Bitmap getTransformedBitmap(Bitmap src, Matrix matrix, boolean recycleSrc) { if (src == null) { LogUtil.w(TAG, "getTransformedBitmap", "source bitmap is null"); return null; } Bitmap dst = null; try { dst = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true); if (recycleSrc && dst != src) { src.recycle(); } } catch (Exception e) { e.printStackTrace(); } return dst; } }