Search in sources :

Example 61 with Canvas

use of android.graphics.Canvas in project Android-Universal-Image-Loader by nostra13.

the class OldRoundedBitmapDisplayer method getRoundedCornerBitmap.

private static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int roundPixels, Rect srcRect, Rect destRect, int width, int height) {
    Bitmap output = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final Paint paint = new Paint();
    final RectF destRectF = new RectF(destRect);
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(0xFF000000);
    canvas.drawRoundRect(destRectF, roundPixels, roundPixels, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, srcRect, destRectF, paint);
    return output;
}
Also used : RectF(android.graphics.RectF) Bitmap(android.graphics.Bitmap) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint)

Example 62 with Canvas

use of android.graphics.Canvas in project weiciyuan by qii.

the class CanvasTransformerBuilder method translate.

public CanvasTransformer translate(final int openedX, final int closedX, final int openedY, final int closedY, final Interpolator interp) {
    initTransformer();
    mTrans = new CanvasTransformer() {

        public void transformCanvas(Canvas canvas, float percentOpen) {
            mTrans.transformCanvas(canvas, percentOpen);
            float f = interp.getInterpolation(percentOpen);
            canvas.translate((openedX - closedX) * f + closedX, (openedY - closedY) * f + closedY);
        }
    };
    return mTrans;
}
Also used : Canvas(android.graphics.Canvas) CanvasTransformer(com.slidingmenu.lib.SlidingMenu.CanvasTransformer)

Example 63 with Canvas

use of android.graphics.Canvas in project platform_frameworks_base by android.

the class Screenshooter method takeScreenshot.

/**
     * Takes a screenshot.
     *
     * @return The screenshot bitmap on success, null otherwise.
     */
static Bitmap takeScreenshot() {
    Display display = DisplayManagerGlobal.getInstance().getRealDisplay(Display.DEFAULT_DISPLAY);
    Point displaySize = new Point();
    display.getRealSize(displaySize);
    final int displayWidth = displaySize.x;
    final int displayHeight = displaySize.y;
    final float screenshotWidth;
    final float screenshotHeight;
    final int rotation = display.getRotation();
    switch(rotation) {
        case ROTATION_FREEZE_0:
            {
                screenshotWidth = displayWidth;
                screenshotHeight = displayHeight;
            }
            break;
        case ROTATION_FREEZE_90:
            {
                screenshotWidth = displayHeight;
                screenshotHeight = displayWidth;
            }
            break;
        case ROTATION_FREEZE_180:
            {
                screenshotWidth = displayWidth;
                screenshotHeight = displayHeight;
            }
            break;
        case ROTATION_FREEZE_270:
            {
                screenshotWidth = displayHeight;
                screenshotHeight = displayWidth;
            }
            break;
        default:
            {
                throw new IllegalArgumentException("Invalid rotation: " + rotation);
            }
    }
    Log.d(TAG, "Taking screenshot of dimensions " + displayWidth + " x " + displayHeight);
    // Take the screenshot
    Bitmap screenShot = SurfaceControl.screenshot((int) screenshotWidth, (int) screenshotHeight);
    if (screenShot == null) {
        Log.e(TAG, "Failed to take screenshot of dimensions " + screenshotWidth + " x " + screenshotHeight);
        return null;
    }
    // Rotate the screenshot to the current orientation
    if (rotation != ROTATION_FREEZE_0) {
        Bitmap unrotatedScreenShot = Bitmap.createBitmap(displayWidth, displayHeight, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(unrotatedScreenShot);
        canvas.translate(unrotatedScreenShot.getWidth() / 2, unrotatedScreenShot.getHeight() / 2);
        canvas.rotate(getDegreesForRotation(rotation));
        canvas.translate(-screenshotWidth / 2, -screenshotHeight / 2);
        canvas.drawBitmap(screenShot, 0, 0, null);
        canvas.setBitmap(null);
        screenShot.recycle();
        screenShot = unrotatedScreenShot;
    }
    // Optimization
    screenShot.setHasAlpha(false);
    return screenShot;
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) Point(android.graphics.Point) Point(android.graphics.Point) Display(android.view.Display)

Example 64 with Canvas

use of android.graphics.Canvas in project platform_frameworks_base by android.

the class RecentsTransitionHelper method composeTaskBitmap.

public static Bitmap composeTaskBitmap(TaskView taskView, TaskViewTransform transform) {
    float scale = transform.scale;
    int fromWidth = (int) (transform.rect.width() * scale);
    int fromHeight = (int) (transform.rect.height() * scale);
    if (fromWidth == 0 || fromHeight == 0) {
        Log.e(TAG, "Could not compose thumbnail for task: " + taskView.getTask() + " at transform: " + transform);
        Bitmap b = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
        b.eraseColor(Color.TRANSPARENT);
        return b;
    } else {
        Bitmap b = Bitmap.createBitmap(fromWidth, fromHeight, Bitmap.Config.ARGB_8888);
        if (RecentsDebugFlags.Static.EnableTransitionThumbnailDebugMode) {
            b.eraseColor(0xFFff0000);
        } else {
            Canvas c = new Canvas(b);
            c.scale(scale, scale);
            taskView.draw(c);
            c.setBitmap(null);
        }
        return b.createAshmemBitmap();
    }
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas)

Example 65 with Canvas

use of android.graphics.Canvas in project platform_frameworks_base by android.

the class RecentsTransitionHelper method composeHeaderBitmap.

private static Bitmap composeHeaderBitmap(TaskView taskView, TaskViewTransform transform) {
    float scale = transform.scale;
    int headerWidth = (int) (transform.rect.width());
    int headerHeight = (int) (taskView.mHeaderView.getMeasuredHeight() * scale);
    if (headerWidth == 0 || headerHeight == 0) {
        return null;
    }
    Bitmap b = Bitmap.createBitmap(headerWidth, headerHeight, Bitmap.Config.ARGB_8888);
    if (RecentsDebugFlags.Static.EnableTransitionThumbnailDebugMode) {
        b.eraseColor(0xFFff0000);
    } else {
        Canvas c = new Canvas(b);
        c.scale(scale, scale);
        taskView.mHeaderView.draw(c);
        c.setBitmap(null);
    }
    return b.createAshmemBitmap();
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas)

Aggregations

Canvas (android.graphics.Canvas)1237 Bitmap (android.graphics.Bitmap)890 Paint (android.graphics.Paint)609 Rect (android.graphics.Rect)257 BitmapDrawable (android.graphics.drawable.BitmapDrawable)192 RectF (android.graphics.RectF)136 PorterDuffXfermode (android.graphics.PorterDuffXfermode)103 Matrix (android.graphics.Matrix)80 Point (android.graphics.Point)76 Drawable (android.graphics.drawable.Drawable)68 BitmapShader (android.graphics.BitmapShader)60 Test (org.junit.Test)46 IOException (java.io.IOException)43 FileOutputStream (java.io.FileOutputStream)40 View (android.view.View)39 Path (android.graphics.Path)38 File (java.io.File)37 SuppressLint (android.annotation.SuppressLint)36 ColorMatrix (android.graphics.ColorMatrix)36 ColorMatrixColorFilter (android.graphics.ColorMatrixColorFilter)33