Search in sources :

Example 46 with Canvas

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

the class DessertCaseView method convertToAlphaMask.

private static Bitmap convertToAlphaMask(Bitmap b) {
    Bitmap a = Bitmap.createBitmap(b.getWidth(), b.getHeight(), Bitmap.Config.ALPHA_8);
    Canvas c = new Canvas(a);
    Paint pt = new Paint();
    pt.setColorFilter(new ColorMatrixColorFilter(MASK));
    c.drawBitmap(b, 0.0f, 0.0f, pt);
    return a;
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint)

Example 47 with Canvas

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

the class GlobalScreenshot method takeScreenshot.

/**
     * Takes a screenshot of the current display and shows an animation.
     */
void takeScreenshot(Runnable finisher, boolean statusBarVisible, boolean navBarVisible, int x, int y, int width, int height) {
    // We need to orient the screenshot correctly (and the Surface api seems to take screenshots
    // only in the natural orientation of the device :!)
    mDisplay.getRealMetrics(mDisplayMetrics);
    float[] dims = { mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels };
    float degrees = getDegreesForRotation(mDisplay.getRotation());
    boolean requiresRotation = (degrees > 0);
    if (requiresRotation) {
        // Get the dimensions of the device in its native orientation
        mDisplayMatrix.reset();
        mDisplayMatrix.preRotate(-degrees);
        mDisplayMatrix.mapPoints(dims);
        dims[0] = Math.abs(dims[0]);
        dims[1] = Math.abs(dims[1]);
    }
    // Take the screenshot
    mScreenBitmap = SurfaceControl.screenshot((int) dims[0], (int) dims[1]);
    if (mScreenBitmap == null) {
        notifyScreenshotError(mContext, mNotificationManager, R.string.screenshot_failed_to_capture_text);
        finisher.run();
        return;
    }
    if (requiresRotation) {
        // Rotate the screenshot to the current orientation
        Bitmap ss = Bitmap.createBitmap(mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels, Bitmap.Config.ARGB_8888);
        Canvas c = new Canvas(ss);
        c.translate(ss.getWidth() / 2, ss.getHeight() / 2);
        c.rotate(degrees);
        c.translate(-dims[0] / 2, -dims[1] / 2);
        c.drawBitmap(mScreenBitmap, 0, 0, null);
        c.setBitmap(null);
        // Recycle the previous bitmap
        mScreenBitmap.recycle();
        mScreenBitmap = ss;
    }
    if (width != mDisplayMetrics.widthPixels || height != mDisplayMetrics.heightPixels) {
        // Crop the screenshot to selected region
        Bitmap cropped = Bitmap.createBitmap(mScreenBitmap, x, y, width, height);
        mScreenBitmap.recycle();
        mScreenBitmap = cropped;
    }
    // Optimizations
    mScreenBitmap.setHasAlpha(false);
    mScreenBitmap.prepareToDraw();
    // Start the post-screenshot animation
    startAnimation(finisher, mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels, statusBarVisible, navBarVisible);
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas)

Example 48 with Canvas

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

the class Allocation method copy2DRangeFrom.

/**
     * Copy a {@link android.graphics.Bitmap} into an Allocation.  The height
     * and width of the update will use the height and width of the {@link
     * android.graphics.Bitmap}.
     *
     * @param xoff X offset of the region to update in this Allocation
     * @param yoff Y offset of the region to update in this Allocation
     * @param data the Bitmap to be copied
     */
public void copy2DRangeFrom(int xoff, int yoff, Bitmap data) {
    try {
        Trace.traceBegin(RenderScript.TRACE_TAG, "copy2DRangeFrom");
        mRS.validate();
        if (data.getConfig() == null) {
            Bitmap newBitmap = Bitmap.createBitmap(data.getWidth(), data.getHeight(), Bitmap.Config.ARGB_8888);
            Canvas c = new Canvas(newBitmap);
            c.drawBitmap(data, 0, 0, null);
            copy2DRangeFrom(xoff, yoff, newBitmap);
            return;
        }
        validateBitmapFormat(data);
        validate2DRange(xoff, yoff, data.getWidth(), data.getHeight());
        mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, data);
    } finally {
        Trace.traceEnd(RenderScript.TRACE_TAG);
    }
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas)

Example 49 with Canvas

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

the class BitmapRegionTileSource method getTileWithoutReusingBitmap.

private Bitmap getTileWithoutReusingBitmap(int level, int x, int y, int tileSize) {
    int t = tileSize << level;
    mWantRegion.set(x, y, x + t, y + t);
    mOverlapRegion.set(0, 0, mWidth, mHeight);
    mOptions.inSampleSize = (1 << level);
    Bitmap bitmap = mDecoder.decodeRegion(mOverlapRegion, mOptions);
    if (bitmap == null) {
        Log.w(TAG, "fail in decoding region");
    }
    if (mWantRegion.equals(mOverlapRegion)) {
        return bitmap;
    }
    Bitmap result = Bitmap.createBitmap(tileSize, tileSize, Config.ARGB_8888);
    if (mCanvas == null) {
        mCanvas = new Canvas();
    }
    mCanvas.setBitmap(result);
    mCanvas.drawBitmap(bitmap, (mOverlapRegion.left - mWantRegion.left) >> level, (mOverlapRegion.top - mWantRegion.top) >> level, null);
    mCanvas.setBitmap(null);
    return result;
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint)

Example 50 with Canvas

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

the class BitmapRegionTileSource method decodeRegion.

public Bitmap decodeRegion(Rect wantRegion, BitmapFactory.Options options) {
    if (mTempCanvas == null) {
        mTempCanvas = new Canvas();
        mTempPaint = new Paint();
        mTempPaint.setFilterBitmap(true);
    }
    int sampleSize = Math.max(options.inSampleSize, 1);
    Bitmap newBitmap = Bitmap.createBitmap(wantRegion.width() / sampleSize, wantRegion.height() / sampleSize, Bitmap.Config.ARGB_8888);
    mTempCanvas.setBitmap(newBitmap);
    mTempCanvas.save();
    mTempCanvas.scale(1f / sampleSize, 1f / sampleSize);
    mTempCanvas.drawBitmap(mBuffer, -wantRegion.left, -wantRegion.top, mTempPaint);
    mTempCanvas.restore();
    mTempCanvas.setBitmap(null);
    return newBitmap;
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

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