get Transformed Bitmap - Android Graphics

Android examples for Graphics:Bitmap Effect

Description

get Transformed Bitmap

Demo Code


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  .ja v  a2  s. c o m

    private static final String TAG = ImgUtil.class.getSimpleName();
    
    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;
    }
}

Related Tutorials