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;
}
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;
}
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;
}
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();
}
}
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();
}
Aggregations