Bitmap recycle - 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 recycle method.

This code example shows how to use the following methods:getHeight, getWidth, recycle
     * @param source 
     * @param radius 
     * @return rounded corner bitmap 
     */ 
    public static Bitmap roundCorners(final Bitmap source, final float radius) {
        int width = source.getWidth();
        int height = source.getHeight();
 
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setColor(WHITE);
 
        Bitmap clipped = Bitmap.createBitmap(width, height, ARGB_8888);
        Canvas canvas = new Canvas(clipped);
        canvas.drawRoundRect(new RectF(0, 0, width, height), radius, radius,
                paint);
        paint.setXfermode(new PorterDuffXfermode(DST_IN));
 
        Bitmap rounded = Bitmap.createBitmap(width, height, ARGB_8888);
        canvas = new Canvas(rounded);

9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:recycle
This code example shows how to use the following methods:createBitmap, getHeight, getWidth, recycle
    Matrix matrixMirrorY=new Matrix();
 
    matrixMirrorY.setValues(mirrorY);
    matrix.postConcat(matrixMirrorY);
 
    Bitmap mirrored=
        Bitmap.createBitmap(workingCopy, 0, 0, workingCopy.getWidth(),
                            workingCopy.getHeight(), matrix, true);
 
    workingCopy.recycle();
    workingCopy=mirrored;
    data=null;
  } 
 
  void applyFlip() { 
    synchronizeModels(true, false); 
 
    float[] mirrorY= { -1, 0, 0, 0, 1, 0, 0, 0, 1 };
    Matrix matrix=new Matrix();
    Matrix matrixMirrorY=new Matrix();
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:copyPixelsFromBuffer, copyPixelsToBuffer, getConfig, getHeight, getRowBytes
			// android:name="android.permission.WRITE_EXTERNAL_STORAGE" 
			// into AndroidManifest.xml file 
			RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");
 
			// get the width and height of the source bitmap. 
			int width = imgIn.getWidth();
			int height = imgIn.getHeight();
			Config type = imgIn.getConfig();
 
			// Copy the byte to the file 
			// Assume source bitmap loaded using options.inPreferredConfig = 
			// Config.ARGB_8888; 
			FileChannel channel = randomAccessFile.getChannel();
			MappedByteBuffer map = channel.map(MapMode.READ_WRITE, 0,
					imgIn.getRowBytes() * height);
			imgIn.copyPixelsToBuffer(map);
			// recycle the source bitmap, this will be no longer used. 
			imgIn.recycle();
			System.gc();// try to force the bytes from the imgIn to be released
 

8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:createScaledBitmap, getHeight, getWidth, recycle
     * @param height   preferred height of the new image 
     * @param upsample if true smaller images than the preferred size are increased, if false the origin bitmap is returned 
     * @return new bitmap if size has changed, otherwise original bitmap. 
     */ 
    public Bitmap scaleBitmap(Bitmap b, int width, int height, boolean upsampling) {
        int imageHeight = b.getHeight();
        int imageWidth = b.getWidth();
        if (!upsampling && imageHeight <= height && imageWidth <= width) {
            return b;
        } 
        int finalWidth = width;
        int finalHeight = height;
        if (imageHeight > imageWidth) {
            float factor = ((float) height) / ((float) imageHeight);
            finalHeight = new Float(imageHeight * factor).intValue();
            finalWidth = new Float(imageWidth * factor).intValue();
        } else { 
            float factor = ((float) width) / ((float) imageWidth);
            finalHeight = new Float(imageHeight * factor).intValue();
            finalWidth = new Float(imageWidth * factor).intValue();

8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getHeight, getWidth, recycle
     * @param source 
     * @param radius 
     * @return rounded corner bitmap 
     */ 
    public static Bitmap roundCorners(final Bitmap source, final float radius) {
        int width = source.getWidth();
        int height = source.getHeight();
 
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setColor(WHITE);
 
        Bitmap clipped = Bitmap.createBitmap(width, height, ARGB_8888);
        Canvas canvas = new Canvas(clipped);
        canvas.drawRoundRect(new RectF(0, 0, width, height), radius, radius,
                paint);
        paint.setXfermode(new PorterDuffXfermode(DST_IN));
 
        Bitmap rounded = Bitmap.createBitmap(width, height, ARGB_8888);
        canvas = new Canvas(rounded);

8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:createScaledBitmap, getHeight, getWidth, recycle
    } 
 
    public static Bitmap scale(Bitmap bmp, int w, int h) {
        Bitmap b = null;
        if (bmp != null) {
            Log.v(TAG, "Scaling bitmap from " + bmp.getWidth() + "x" + bmp.getHeight() + " to " + w + "x" + h);
 
            // We're going to need some memory 
            System.gc();
            Runtime.getRuntime().gc();
 
            // Scale it! 
            b=Bitmap.createScaledBitmap(bmp, w, h, true);
 
            // Release original bitmap 
            bmp.recycle();
        } 
        return b;
    } 
 
    private void loadTextureImpl(Bitmap bitmap) {
8
CodeRank
Experience pair programming with AI  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(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
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:recycle
			mTextureFront.recycle();
		} 
		mTextureFront = Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565);
		mTextureFront.eraseColor(mColorFront);
		if (mTextureBack != null) {
			mTextureBack.recycle();
		} 
		mTextureBack = Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565);
		mTextureBack.eraseColor(mColorBack);
		mTexturesChanged = false;
	} 
 
	/** 
	 * Resets this CurlPage into its initial state. 
	 */ 
	public void reset() { 
		mColorBack = Color.WHITE;
		mColorFront = Color.WHITE;
		recycle(); 
	} 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:extractAlpha, getHeight, getWidth, recycle
        // We start by removing most of the alpha channel so as to ignore shadows, and 
        // other types of partial transparency when defining the shape of the object 
        if (alphaClipPaint == null) {
            alphaClipPaint = mAlphaClipPaint;
        } 
        Bitmap glowShape = srcDst.extractAlpha(alphaClipPaint, mTempOffset);
 
        // calculate the outer blur first 
        BlurMaskFilter outerBlurMaskFilter;
        switch (thickness) {
            case EXTRA_THICK:
                outerBlurMaskFilter = sExtraThickOuterBlurMaskFilter;
                break; 
            case THICK:
                outerBlurMaskFilter = sThickOuterBlurMaskFilter;
                break; 
            case MEDIUM:
                outerBlurMaskFilter = sMediumOuterBlurMaskFilter;
                break; 
            default: 

7
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Bitmap recycle Questions & Answers:

Other Bitmap recycle Examples

40:	        // recyle unused bitmaps
41:	        if (bitmap != null) {
42:	          bitmap.recycle();
43:	        }
44:	        stream = getContentResolver().openInputStream(data.getData());

Read More

recycle Method Overview
Free the native object associated with this bitmap, and clear the reference to the pixel data.
See Code Examples for other Android Bitmap Methods: