use of android.graphics.Canvas in project glide by bumptech.
the class CircleCropTest method createSolidRedBitmap.
private Bitmap createSolidRedBitmap(int width, int height) {
Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(result);
Paint paint = new Paint();
paint.setColor(Color.RED);
Rect rect = new Rect(0, 0, width, height);
canvas.drawRect(rect, paint);
return result;
}
use of android.graphics.Canvas in project SMRadarScanView by asdzheng.
the class RadarScanView method onSizeChanged.
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
Log.i("Radar", w + "");
centerX = w / 2;
centerY = h / 2;
//drawText高度会有偏差,这样的设置会让文字居中显示
textY = centerY - ((mPaintText.descent() + mPaintText.ascent()) / 2);
radarRadius = Math.min(centerX, centerY) - 2 * borderWidth;
layerBitmap = Bitmap.createBitmap(2 * radarRadius, 2 * radarRadius, Bitmap.Config.ARGB_8888);
layerCanvas = new Canvas(layerBitmap);
layerCanvas.drawColor(layerColor);
clearRect = new RectF();
clearRect.bottom = 2 * radarRadius;
clearRect.top = 0;
clearRect.left = 0;
clearRect.right = 2 * radarRadius;
}
use of android.graphics.Canvas in project ADWLauncher2 by boombuler.
the class Launcher method showPreviews.
private void showPreviews(final View anchor, int start, int end) {
final Resources resources = getResources();
final Workspace workspace = mWorkspace;
CellLayout cell = ((CellLayout) workspace.getChildAt(start));
float max = workspace.getChildCount();
final Rect r = new Rect();
resources.getDrawable(R.drawable.preview_background).getPadding(r);
int extraW = (int) ((r.left + r.right) * max);
int extraH = r.top + r.bottom;
int aW = cell.getWidth() - extraW;
float w = aW / max;
int width = cell.getWidth();
int height = cell.getHeight();
int x = cell.getLeftPadding();
int y = cell.getTopPadding();
width -= (x + cell.getRightPadding());
height -= (y + cell.getBottomPadding());
float scale = w / width;
int count = end - start;
final float sWidth = width * scale;
float sHeight = height * scale;
LinearLayout preview = new LinearLayout(this);
PreviewTouchHandler handler = new PreviewTouchHandler(anchor);
ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(count);
for (int i = start; i < end; i++) {
ImageView image = new ImageView(this);
cell = (CellLayout) workspace.getChildAt(i);
final Bitmap bitmap = Bitmap.createBitmap((int) sWidth, (int) sHeight, Bitmap.Config.ARGB_8888);
final Canvas c = new Canvas(bitmap);
c.scale(scale, scale);
c.translate(-cell.getLeftPadding(), -cell.getTopPadding());
cell.dispatchDraw(c);
image.setBackgroundDrawable(resources.getDrawable(R.drawable.preview_background));
image.setImageBitmap(bitmap);
image.setTag(i);
image.setOnClickListener(handler);
image.setOnFocusChangeListener(handler);
image.setFocusable(true);
if (i == mWorkspace.getCurrentScreen())
image.requestFocus();
preview.addView(image, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
bitmaps.add(bitmap);
}
final PopupWindow p = new PopupWindow(this);
p.setContentView(preview);
p.setWidth((int) (sWidth * count + extraW));
p.setHeight((int) (sHeight + extraH));
p.setAnimationStyle(R.style.AnimationPreview);
p.setOutsideTouchable(true);
p.setFocusable(true);
p.setBackgroundDrawable(new ColorDrawable(0));
p.showAsDropDown(anchor, 0, 0);
p.setOnDismissListener(new PopupWindow.OnDismissListener() {
public void onDismiss() {
dismissPreview(anchor);
}
});
anchor.setTag(p);
anchor.setTag(R.id.workspace, preview);
anchor.setTag(R.id.icon, bitmaps);
}
use of android.graphics.Canvas in project ADWLauncher2 by boombuler.
the class IconCache method makeDefaultIcon.
private Bitmap makeDefaultIcon() {
Drawable d = mPackageManager.getDefaultActivityIcon();
Bitmap b = Bitmap.createBitmap(Math.max(d.getIntrinsicWidth(), 1), Math.max(d.getIntrinsicHeight(), 1), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
d.setBounds(0, 0, b.getWidth(), b.getHeight());
d.draw(c);
return b;
}
use of android.graphics.Canvas in project VirtualApp by asLody.
the class DrawableUtils method drawableToBitMap.
public static Bitmap drawableToBitMap(Drawable drawable) {
if (drawable == null) {
return null;
}
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = ((BitmapDrawable) drawable);
return bitmapDrawable.getBitmap();
} else {
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
drawable.draw(canvas);
return bitmap;
}
}
Aggregations