Java Code Examples for android.graphics.Canvas#drawPicture()

The following examples show how to use android.graphics.Canvas#drawPicture() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PXImagePaint.java    From pixate-freestyle-android with Apache License 2.0 6 votes vote down vote up
public void applyFillToPath(Path path, Paint paint, Canvas context) {
    context.save();
    // clip to path
    context.clipPath(path);
    // do the gradient
    Rect bounds = new Rect();
    context.getClipBounds(bounds);
    Picture image = imageForBounds(bounds);
    // draw
    if (image != null) {
        // TODO - Blending mode? We may need to convert the Picture to a
        // Bitmap and then call drawBitmap
        context.drawPicture(image);
    }
    context.restore();
}
 
Example 2
Source File: PictureLayout.java    From geopaparazzi with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unused")
@Override
protected void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(mPicture.beginRecording(getWidth(), getHeight()));
    mPicture.endRecording();

    int x = getWidth() / 2;
    int y = getHeight() / 2;

    if (false) {
        canvas.drawPicture(mPicture);
    } else {
        drawPict(canvas, 0, 0, x, y, 1, 1);
        drawPict(canvas, x, 0, x, y, -1, 1);
        drawPict(canvas, 0, y, x, y, 1, -1);
        drawPict(canvas, x, y, x, y, -1, -1);
    }
}
 
Example 3
Source File: SvgImageView.java    From CustomShapeImageView with Apache License 2.0 6 votes vote down vote up
public static Bitmap getBitmap(Context context, int width, int height, int svgRawResourceId) {
    Bitmap bitmap = Bitmap.createBitmap(width, height,
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.BLACK);

    if (svgRawResourceId > 0) {
        SVG svg = SVGParser.getSVGFromInputStream(
                context.getResources().openRawResource(svgRawResourceId), width, height);
        canvas.drawPicture(svg.getPicture());
    } else {
        canvas.drawRect(new RectF(0.0f, 0.0f, width, height), paint);
    }

    return bitmap;
}
 
Example 4
Source File: PictureLayout.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(mPicture.beginRecording(getWidth(), getHeight()));
    mPicture.endRecording();

    int x = getWidth()/2;
    int y = getHeight()/2;

    if (false) {
        canvas.drawPicture(mPicture);
    } else {
        drawPict(canvas, 0, 0, x, y,  1,  1);
        drawPict(canvas, x, 0, x, y, -1,  1);
        drawPict(canvas, 0, y, x, y,  1, -1);
        drawPict(canvas, x, y, x, y, -1, -1);
    }
}
 
Example 5
Source File: SvgImageView.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
public static Bitmap getBitmap(Context context, int width, int height, int svgRawResourceId) {
    Bitmap bitmap = Bitmap.createBitmap(width, height,
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.BLACK);

    if (svgRawResourceId > 0) {
        SVG svg = SVGParser.getSVGFromInputStream(
                context.getResources().openRawResource(svgRawResourceId), width, height);
        canvas.drawPicture(svg.getPicture());
    } else {
        canvas.drawRect(new RectF(0.0f, 0.0f, width, height), paint);
    }

    return bitmap;
}
 
Example 6
Source File: SvgImageView.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
public static Bitmap getBitmap(Context context, int width, int height, int svgRawResourceId) {
    Bitmap bitmap = Bitmap.createBitmap(width, height,
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.BLACK);

    if (svgRawResourceId > 0) {
        SVG svg = SVGParser.getSVGFromInputStream(
                context.getResources().openRawResource(svgRawResourceId), width, height);
        canvas.drawPicture(svg.getPicture());
    } else {
        canvas.drawRect(new RectF(0.0f, 0.0f, width, height), paint);
    }

    return bitmap;
}
 
Example 7
Source File: Utils.java    From Noyze with Apache License 2.0 6 votes vote down vote up
/**
 * @returns A {@link Bitmap} for a {@link Drawable}.
 */
public static Bitmap drawableToBitmap(final Drawable drawable) {
    if (null == drawable) return null;
    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }

    final Bitmap bitmap = Bitmap.createBitmap(Math.max(0, drawable.getIntrinsicWidth()),
            Math.max(0, drawable.getIntrinsicHeight()), Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(bitmap);

    // PictureDrawable's get handled separately.
    if (drawable instanceof PictureDrawable) {
        canvas.drawPicture(((PictureDrawable) drawable).getPicture());
        return bitmap;
    }

    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);

    return bitmap;
}
 
Example 8
Source File: AndroidSvgBitmap.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
public static android.graphics.Bitmap getResourceBitmap(InputStream inputStream, float scaleFactor, float defaultSize, int width, int height, int percent, int color) throws IOException {
    try {
        SVG svg = SVG.getFromInputStream(inputStream);
        Picture picture;
        if (color != 0) {
            RenderOptions renderOpts = RenderOptions.create().css("* { fill: #" + String.format("%06x", color & 0x00ffffff) + "; }");
            picture = svg.renderToPicture(renderOpts);
        } else {
            picture = svg.renderToPicture();
        }

        double scale = scaleFactor / Math.sqrt((picture.getHeight() * picture.getWidth()) / defaultSize);

        float[] bmpSize = GraphicUtils.imageSize(picture.getWidth(), picture.getHeight(), (float) scale, width, height, percent);

        android.graphics.Bitmap bitmap = android.graphics.Bitmap.createBitmap((int) Math.ceil(bmpSize[0]),
                (int) Math.ceil(bmpSize[1]), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        canvas.drawPicture(picture, new RectF(0, 0, bmpSize[0], bmpSize[1]));

        return bitmap;
    } catch (Exception e) {
        throw new IOException(e);
    }
}
 
Example 9
Source File: Utils.java    From Noyze with Apache License 2.0 6 votes vote down vote up
/**
 * @returns A {@link Bitmap} for a {@link Drawable}.
 */
public static Bitmap drawableToBitmap(final Drawable drawable) {
    if (null == drawable) return null;
    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }

    final Bitmap bitmap = Bitmap.createBitmap(Math.max(0, drawable.getIntrinsicWidth()),
            Math.max(0, drawable.getIntrinsicHeight()), Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(bitmap);

    // PictureDrawable's get handled separately.
    if (drawable instanceof PictureDrawable) {
        canvas.drawPicture(((PictureDrawable) drawable).getPicture());
        return bitmap;
    }

    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);

    return bitmap;
}
 
Example 10
Source File: AsyncExporter.java    From Android-Material-Icons with Apache License 2.0 6 votes vote down vote up
private Bitmap getBitmapSvg(Params params, String fileName, int densityIndex) {
    try {
        FileInputStream inputStream = new FileInputStream(mContext.getFilesDir() + MainActivity.ICONS_PATH + fileName);
        SVG svg = SVGParser.getSVGFromInputStream(inputStream);

        // Icon size relative to current processed density
        int fSize = ICONS_SIZE[densityIndex];

        Bitmap bitmap = Bitmap.createBitmap(fSize, fSize, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        canvas.drawPicture(svg.getPicture(), new Rect(0, 0, fSize, fSize));

        Bitmap finalBitmap = createTintedBitmap(bitmap, params.desiredColor);
        bitmap.recycle();
        return finalBitmap;
    } catch (IOException | SVGParseException e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 11
Source File: SvgImageView.java    From ZzBeeLayout with Apache License 2.0 6 votes vote down vote up
public static Bitmap getBitmap(Context context, int width, int height, int svgRawResourceId) {
    Bitmap bitmap = Bitmap.createBitmap(width, height,
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.BLACK);

    if (svgRawResourceId > 0) {
        SVG svg = SVGParser.getSVGFromInputStream(
                context.getResources().openRawResource(svgRawResourceId), width, height);
        canvas.drawPicture(svg.getPicture());
    } else {
        canvas.drawRect(new RectF(0.0f, 0.0f, width, height), paint);
    }

    return bitmap;
}
 
Example 12
Source File: ViewUtils.java    From microMathematics with GNU General Public License v3.0 5 votes vote down vote up
public static Bitmap pictureToBitmap(final Picture picture, final int w, final int h)
{
    final PictureDrawable pd = new PictureDrawable(picture);
    final Bitmap bitmap = Bitmap.createBitmap(w, h, getBitmapConfig());
    final Canvas canvas = new Canvas(bitmap);
    canvas.drawPicture(pd.getPicture());
    return bitmap;
}
 
Example 13
Source File: Widget.java    From PdDroidPublisher with GNU General Public License v3.0 5 votes vote down vote up
public boolean draw(Canvas c, RectF rect) {
	if(svg != null) c.drawPicture(svg.getPicture(), rect);
	else if(bitmap != null) c.drawBitmap(bitmap, null, rect, paint);
	else return true;
	
	return false;
}
 
Example 14
Source File: PdDroidPatchView.java    From PdDroidPublisher with GNU General Public License v3.0 5 votes vote down vote up
private static Bitmap picture2Bitmap(Picture picture){
    PictureDrawable pictureDrawable = new PictureDrawable(picture);
    Bitmap bitmap = Bitmap.createBitmap(pictureDrawable.getIntrinsicWidth(), pictureDrawable.getIntrinsicHeight(), Config.ARGB_8888);
    //Log.e(TAG, "picture size: " + pictureDrawable.getIntrinsicWidth() + " " + pictureDrawable.getIntrinsicHeight());
    Canvas canvas = new Canvas(bitmap);
    canvas.drawPicture(pictureDrawable.getPicture());
    return bitmap;
}
 
Example 15
Source File: SVGRenderActivity.java    From android-opensource-library-56 with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    canvas.save();
    canvas.scale(1.5f, 1.5f);
    canvas.drawPicture(mPict);
    canvas.restore();
}
 
Example 16
Source File: PictureLayout.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
private void drawPict(Canvas canvas, int x, int y, int w, int h,
                      float sx, float sy) {
    canvas.save();
    canvas.translate(x, y);
    canvas.clipRect(0, 0, w, h);
    canvas.scale(0.5f, 0.5f);
    canvas.scale(sx, sy, w, h);
    canvas.drawPicture(mPicture);
    canvas.restore();
}
 
Example 17
Source File: MapLayer.java    From MapView with MIT License 5 votes vote down vote up
@Override
public void draw(Canvas canvas, Matrix currentMatrix, float currentZoom, float
        currentRotateDegrees) {
    canvas.save();
    canvas.setMatrix(currentMatrix);
    if (image != null) {
        canvas.drawPicture(image);
    }
    canvas.restore();
}
 
Example 18
Source File: PictureLayout.java    From geopaparazzi with GNU General Public License v3.0 5 votes vote down vote up
private void drawPict(Canvas canvas, int x, int y, int w, int h,
                      float sx, float sy) {
    canvas.save();
    canvas.translate(x, y);
    canvas.clipRect(0, 0, w, h);
    canvas.scale(0.5f, 0.5f);
    canvas.scale(sx, sy, w, h);
    canvas.drawPicture(mPicture);
    canvas.restore();
}
 
Example 19
Source File: PXShapeView.java    From pixate-freestyle-android with Apache License 2.0 4 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    canvas.getClipBounds(bounds);
    Picture picture = renderToImage(bounds);
    canvas.drawPicture(picture);
}
 
Example 20
Source File: PictureRendererStrategy.java    From SVG-Android with Apache License 2.0 4 votes vote down vote up
private void drawCachedPictureWithAlpha(Canvas canvas, Rect originalBounds) {
    // The Picture's size is the same as the bounds.
    canvas.drawPicture(mCachedPicture, originalBounds);
}