Bitmap copy - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Bitmap copy method.

This code example shows how to use the following methods:copy, getConfig, recycle
 
	// TODO: This function should not be called directly from 
	// DecodeUtils.requestDecode(...), since we don't have the knowledge 
	// if the bitmap will be uploaded to GL. 
	public static Bitmap ensureGLCompatibleBitmap(final Bitmap bitmap) {
		if (bitmap == null || bitmap.getConfig() != null) return bitmap;
		final Bitmap newBitmap = bitmap.copy(Config.ARGB_8888, false);
		bitmap.recycle();
		return newBitmap;
	} 
} 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:copy, createScaledBitmap, getHeight, getWidth
This code example shows how to use the following methods:copy, hasAlpha
	 
	public static Bitmap imageAlpha(Bitmap image, KrollDict args)
	{ 
		if (image != null) {
			// If the image already has an alpha channel then just return 
			if (image.hasAlpha()) {
				return image;
			} 
			 
			// Create a new bitmap that supports alpha 
			Bitmap resultBitmap = image.copy(Bitmap.Config.ARGB_8888, false);
			 
			return resultBitmap;
		} 
		 
		return null; 
	} 
} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:copy, getHeight, getPixels, getWidth, recycle
    public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) {
        // TODO: implement bilinear or bicubic here... for now, just use 
        // canvas to do a simple implementation... 
        // TODO: and be more memory efficient! (do it in native?) 
 
        Bitmap temp = bitmap.copy(mConfig, true);
        Canvas canvas = new Canvas(temp);
        canvas.save();
        Rect bounds = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
        float w = temp.getWidth();
        float h = temp.getHeight();
        float mw = temp.getWidth() / 2.0f;
        float mh = temp.getHeight() / 2.0f;
 
        canvas.scale(mZoomFactor, mZoomFactor, mw, mh);
        canvas.rotate(mRotation, mw, mh);
        canvas.drawBitmap(bitmap, bounds, bounds, new Paint());
        canvas.restore();
 
        int[] pixels = new int[(int) (w * h)];

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:copy, getConfig, recycle
 
    // TODO: This function should not be called directly from 
    // DecodeUtils.requestDecode(...), since we don't have the knowledge 
    // if the bitmap will be uploaded to GL. 
    public static Bitmap ensureGLCompatibleBitmap(Bitmap bitmap) {
        if (bitmap == null || bitmap.getConfig() != null) return bitmap;
        Bitmap newBitmap = bitmap.copy(Config.ARGB_8888, false);
        bitmap.recycle();
        return newBitmap;
    } 
 
    public static BitmapRegionDecoder requestCreateBitmapRegionDecoder(
            JobContext jc, byte[] bytes, int offset, int length,
            boolean shareable) {
        if (offset < 0 || length <= 0 || offset + length > bytes.length) {
            throw new IllegalArgumentException(String.format(
                    "offset = %s, length = %s, bytes = %s", 
                    offset, length, bytes.length));
        } 
 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:copy, getConfig, isMutable, recycle
	// =========================================================== 
	// Methods 
	// =========================================================== 
 
	private Bitmap ensureLoadedBitmapIsMutable(final Bitmap pBitmap) {
		if(pBitmap.isMutable()) {
			return pBitmap;
		} else { 
			final Bitmap mutableBitmap = pBitmap.copy(pBitmap.getConfig(), true);
			pBitmap.recycle();
			return mutableBitmap;
		} 
	} 
 
	// =========================================================== 
	// Inner and Anonymous Classes 
	// =========================================================== 
 
	public static class TextureSourceDecoratorOptions { 
		// =========================================================== 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:copy, getConfig
		view.buildDrawingCache(false);
		Bitmap orig = view.getDrawingCache();
		Bitmap.Config config = null;
 
		if(orig != null) {
			config = orig.getConfig();
		} 
 
		if(config == null) {
			config = Bitmap.Config.ARGB_8888;
		} 
		Bitmap b = orig.copy(config, false);
		view.destroyDrawingCache();
		return b; 
	} 
 
	/** 
	 * Returns a proper filename depending on if name is given or not. 
	 *  
	 * @param name the given name 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:copy, isRecycled
    public void draw(final Canvas canvas) {
        if (isCacheEnabled) {
            if (cache == null || cache.isRecycled()) {
                updateCache(); 
            } 
            if (cache != null && !cache.isRecycled()) {
                canvas.drawBitmap(cache, null, new Rect(0, 0, getWidth(), getHeight()), paint);
            } 
        } else { 
            super.draw(canvas);
        } 
    } 
 
    public void enableCache() { 
        if (!isCacheEnabled && android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
            updateCache(); 
            isCacheEnabled = true;
        } 
    } 
 

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:copy, isRecycled
    } 
 
    @Override 
    public void draw(final Canvas canvas) {
        if (isCacheEnabled) {
            if (cache == null || cache.isRecycled()) {
                updateCache(); 
            } 
            if (cache != null && !cache.isRecycled()) {
                canvas.drawBitmap(cache, null, new Rect(0, 0, getWidth(), getHeight()), paint);
            } 
        } else { 
            super.draw(canvas);
        } 
    } 
 
    public void enableCache() { 
        if (!isCacheEnabled && android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
            updateCache(); 
            isCacheEnabled = true;
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:copy, getHeight, getWidth, hasAlpha
	public static Bitmap imageWithAlpha(Bitmap image)
	{ 
		if (image == null) {
			return null; 
		} 
		if (image.hasAlpha()) {
			return image;
		} 
		return image.copy(Bitmap.Config.ARGB_8888, true);
	} 
 
	/** 
	 * Create a copy of the given image with rounded corners and a transparent border around its edges. 
	 *  
	 * @param image 
	 *            the image to add rounded corners to. 
	 * @param cornerRadius 
	 *            the radius of the rounded corners. 
	 * @param borderSize 
	 *            the size of the border to be added. 

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Bitmap copy Questions & Answers:

copy Method Overview
Tries to make a new bitmap based on the dimensions of this bitmap, setting the new bitmap's config to the one specified, and then copying this bitmap's pixels into the new bitmap.
See Code Examples for other Android Bitmap Methods: