Search in sources :

Example 6 with Canvas

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;
}
Also used : Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint)

Example 7 with Canvas

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;
}
Also used : RectF(android.graphics.RectF) Canvas(android.graphics.Canvas)

Example 8 with Canvas

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);
}
Also used : Rect(android.graphics.Rect) Canvas(android.graphics.Canvas) ArrayList(java.util.ArrayList) PopupWindow(android.widget.PopupWindow) Bitmap(android.graphics.Bitmap) ColorDrawable(android.graphics.drawable.ColorDrawable) Resources(android.content.res.Resources) ImageView(android.widget.ImageView) LinearLayout(android.widget.LinearLayout)

Example 9 with Canvas

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;
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) Drawable(android.graphics.drawable.Drawable)

Example 10 with Canvas

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;
    }
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

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