Android examples for Graphics:Bitmap Effect
get Mirrored 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{ //ww w . ja v a 2 s .co m private static final String TAG = ImgUtil.class.getSimpleName(); public static Bitmap getMirroredBitmap(Bitmap src, int flag, boolean recycleSrc) { Matrix matrix = new Matrix(); switch (flag) { case 0: // matrix.setScale(-1, 1); break; case 1: // matrix.setScale(1, -1); break; } 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; } }