当前位置: 首页>>代码示例>>Java>>正文


Java Bitmap.recycle方法代码示例

本文整理汇总了Java中android.graphics.Bitmap.recycle方法的典型用法代码示例。如果您正苦于以下问题:Java Bitmap.recycle方法的具体用法?Java Bitmap.recycle怎么用?Java Bitmap.recycle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.graphics.Bitmap的用法示例。


在下文中一共展示了Bitmap.recycle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadTexture

import android.graphics.Bitmap; //导入方法依赖的package包/类
public static int loadTexture(final Context context, final int resourceId)
{
	final int[] textureHandle = new int[1];
	
	GLES20.glGenTextures(1, textureHandle, 0);
	
	if (textureHandle[0] != 0)
	{
		final BitmapFactory.Options options = new BitmapFactory.Options();
		options.inScaled = false;	// No pre-scaling

		// Read in the resource
		final Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId, options);
					
		// Bind to the texture in OpenGL
		GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);
		
		// Set filtering
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
		
		// Load the bitmap into the bound texture.
		GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
		
		// Recycle the bitmap, since its data has been loaded into OpenGL.
		bitmap.recycle();						
	}
	
	if (textureHandle[0] == 0)
	{
		throw new RuntimeException("Error loading texture.");
	}
	
	return textureHandle[0];
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:36,代码来源:TextureHelper.java

示例2: drawViewfinder

import android.graphics.Bitmap; //导入方法依赖的package包/类
public void drawViewfinder() {
  Bitmap resultBitmap = this.resultBitmap;
  this.resultBitmap = null;
  if (resultBitmap != null) {
    resultBitmap.recycle();
  }
  invalidate();
}
 
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:9,代码来源:ViewfinderView.java

示例3: run

import android.graphics.Bitmap; //导入方法依赖的package包/类
public void run() {
    ImageView view = mTaskItem.getViewIfValid();
    if (view != null) {
        mTaskItem.putThreadMapping();
        // get bitmap
        mTaskItem.imageProcessor.loadBitmap(mTaskItem);
        Bitmap bitmap = mTaskItem.result.bitmap;

        // debug sleep
        if (mTaskItem.sleep) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }

        // after loading check again if task is valid
        boolean useBitmap = false;
        if (!Thread.interrupted() && mTaskItem.getViewIfValid() != null) {
            useBitmap = true;
            if (mTaskItem.cache != null && bitmap != null) {
                // cache does not like null, so don't put that there
                mTaskItem.cache.put(mTaskItem.key, bitmap);
            }
            mTaskItem.reply.obj = mTaskItem;
            mTaskItem.reply.sendToTarget();
        }
        if (!useBitmap && bitmap != null) {
            bitmap.recycle();
        }

        mTaskItem.removeThreadMapping();
    }
}
 
开发者ID:archos-sa,项目名称:aos-MediaLib,代码行数:36,代码来源:LoadTaskExecutor.java

示例4: doInBackground

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * Crop image in background.
 *
 * @param params ignored
 * @return the decoded bitmap data
 */
@Override
protected BitmapCroppingWorkerTask.Result doInBackground(Void... params) {
    try {
        if (!isCancelled()) {

            BitmapUtils.BitmapSampled bitmapSampled;
            if (mUri != null) {
                bitmapSampled = BitmapUtils.cropBitmap(mContext, mUri, mCropPoints, mDegreesRotated, mOrgWidth, mOrgHeight,
                        mFixAspectRatio, mAspectRatioX, mAspectRatioY, mReqWidth, mReqHeight);
            } else if (mBitmap != null) {
                bitmapSampled = BitmapUtils.cropBitmapObjectHandleOOM(mBitmap, mCropPoints, mDegreesRotated, mFixAspectRatio, mAspectRatioX, mAspectRatioY);
            } else {
                return new Result((Bitmap) null, 1);
            }

            Bitmap bitmap = BitmapUtils.resizeBitmap(bitmapSampled.bitmap, mReqWidth, mReqHeight, mReqSizeOptions);

            if (mSaveUri == null) {
                return new Result(bitmap, bitmapSampled.sampleSize);
            } else {
                BitmapUtils.writeBitmapToUri(mContext, bitmap, mSaveUri, mSaveCompressFormat, mSaveCompressQuality);
                if (bitmap != null) {
                    bitmap.recycle();
                }
                return new Result(mSaveUri, bitmapSampled.sampleSize);
            }
        }
        return null;
    } catch (Exception e) {
        return new Result(e, mSaveUri != null);
    }
}
 
开发者ID:chuch0805,项目名称:Android-Demo_ImageCroper,代码行数:39,代码来源:BitmapCroppingWorkerTask.java

示例5: addReflection

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * 添加倒影
 *
 * @param src 源图片的
 * @param reflectionHeight 倒影高度
 * @param recycle 是否回收
 * @return 带倒影图片
 */
public static Bitmap addReflection(Bitmap src, int reflectionHeight, boolean recycle) {
    if (isEmptyBitmap(src)) {
        return null;
    }
    // 原图与倒影之间的间距
    final int REFLECTION_GAP = 0;
    int srcWidth = src.getWidth();
    int srcHeight = src.getHeight();
    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);
    Bitmap reflectionBitmap = Bitmap.createBitmap(src, 0, srcHeight -
            reflectionHeight, srcWidth, reflectionHeight, matrix, false);
    Bitmap ret = Bitmap.createBitmap(srcWidth,
            srcHeight + reflectionHeight, src.getConfig());
    Canvas canvas = new Canvas(ret);
    canvas.drawBitmap(src, 0, 0, null);
    canvas.drawBitmap(reflectionBitmap, 0,
            srcHeight + REFLECTION_GAP, null);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    LinearGradient shader = new LinearGradient(0, srcHeight, 0,
            ret.getHeight() +
                    REFLECTION_GAP, 0x70FFFFFF, 0x00FFFFFF, Shader.TileMode.MIRROR);
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.DST_IN));
    canvas.drawRect(0,
            srcHeight + REFLECTION_GAP, srcWidth, ret.getHeight(), paint);
    if (!reflectionBitmap.isRecycled()) {
        reflectionBitmap.recycle();
    }
    if (recycle && !src.isRecycled()) {
        src.recycle();
    }
    return ret;
}
 
开发者ID:imliujun,项目名称:LJFramework,代码行数:44,代码来源:ImageUtils.java

示例6: getCircleBitmap

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * 把bitmap变圆
 *
 * @param bitmap
 * @return
 */
private Bitmap getCircleBitmap(Bitmap bitmap) {
    //创建一个Bitmap,准备在上面作画
    Bitmap base = Bitmap.createBitmap(getMeasuredWidth(), getMeasuredHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(base);

    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    //防抖动
    paint.setDither(true);

    //先在base上画一个圆
    canvas.drawCircle(getMeasuredWidth() / 2
            , getMeasuredHeight() / 2
            , getMeasuredWidth() / 2, paint);
    //设置为SRC_IN
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

    //再在base上画上传进来的bitmap,注意坐标对应(这里从原点开始)
    canvas.drawBitmap(bitmap, 0, 0, paint);

    //回收
    bitmap.recycle();
    bitmap = null;
    return base;
}
 
开发者ID:chengkun123,项目名称:ReadMark,代码行数:33,代码来源:DotView.java

示例7: getImageThumbnail

import android.graphics.Bitmap; //导入方法依赖的package包/类
private static Bitmap getImageThumbnail(String imagePath, int width, int height) {
    Bitmap bitmap = null;
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;

    try {
        bitmap = BitmapFactory.decodeFile(imagePath, options);

        int h = options.outHeight;
        int w = options.outWidth;
        int beWidth = w / width;
        int beHeight = h / height;
        int be;
        if (beWidth < beHeight) {
            be = beWidth;
        } else {
            be = beHeight;
        }
        if (be <= 0) {
            be = 1;
        }
        options.inSampleSize = be;
        options.inJustDecodeBounds = false;

        bitmap = BitmapFactory.decodeFile(imagePath, options);
        bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height,
                ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
    } catch (OutOfMemoryError e) {
        if (bitmap != null) {
            bitmap.recycle();
        }
    }

    return bitmap;
}
 
开发者ID:WeiMei-Tian,项目名称:editor-sql,代码行数:36,代码来源:FeThumbUtils.java

示例8: compressByQuality

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * 按质量压缩
 *
 * @param src         源图片
 * @param maxByteSize 允许最大值字节数
 * @param recycle     是否回收
 * @return 质量压缩压缩过的图片
 */
public static Bitmap compressByQuality(Bitmap src, long maxByteSize, boolean recycle) {
    if (isEmptyBitmap(src) || maxByteSize <= 0) return null;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int quality = 100;
    src.compress(CompressFormat.JPEG, quality, baos);
    while (baos.toByteArray().length > maxByteSize && quality > 0) {
        baos.reset();
        src.compress(CompressFormat.JPEG, quality -= 5, baos);
    }
    if (quality < 0) return null;
    byte[] bytes = baos.toByteArray();
    if (recycle && !src.isRecycled()) src.recycle();
    return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
}
 
开发者ID:pan2yong22,项目名称:AndroidUtilCode-master,代码行数:23,代码来源:ImageUtils.java

示例9: TransformToRounded

import android.graphics.Bitmap; //导入方法依赖的package包/类
public static Bitmap TransformToRounded(Bitmap source, Context mContext, int width, int heigth) {
    // Create the RoundedBitmapDrawable.
    RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(mContext.getResources(), source);
    drawable.setCircular(true);
    //drawable.setCornerRadius(mContext.getCornerRadius(source));
    Bitmap output = Bitmap.createBitmap(width, heigth, source.getConfig());
    Canvas canvas = new Canvas(output);
    drawable.setAntiAlias(true);
    drawable.setBounds(0, 0, width, heigth);
    drawable.draw(canvas);
    if (source != output) {
        source.recycle();
    }
    return output;
}
 
开发者ID:malah-code,项目名称:Open-Quran-Radio,代码行数:16,代码来源:ImageHelper.java

示例10: getScaledImage

import android.graphics.Bitmap; //导入方法依赖的package包/类
public static String getScaledImage(Context paramContext, String paramString, int paramInt)
{
	File localFile1 = new File(paramString);
	if (localFile1.exists())
	{
		long l = localFile1.length();
		if (l > 102400L*5)
		{
			Bitmap localBitmap = decodeScaleImage(paramString, SCALE_IMAGE_WIDTH, SCALE_IMAGE_HEIGHT);
			try
			{
				File localFile2 = new File(paramContext.getExternalCacheDir(), "eaemobTemp" + paramInt + ".jpg");
				FileOutputStream localFileOutputStream = new FileOutputStream(localFile2);
				localBitmap.compress(Bitmap.CompressFormat.JPEG, 60, localFileOutputStream);
				localFileOutputStream.close();
				return localFile2.getAbsolutePath();
			}
			catch (Exception localException)
			{
				localException.printStackTrace();
			}
			finally{
				if ( localBitmap != null && !localBitmap.isRecycled()) {
					localBitmap.recycle();
					localBitmap = null ;
				}
			}
		}
	}
	return paramString;
}
 
开发者ID:ebridfighter,项目名称:GongXianSheng,代码行数:32,代码来源:ImageUtils.java

示例11: resultProcess

import android.graphics.Bitmap; //导入方法依赖的package包/类
public static void resultProcess(Context context, Bitmap bitmap, String fileName) throws Exception {
    String text = WATERMARK;
    for (int i = 0; i < 700; i++) {
        text += " " + WATERMARK;
    }
    Bitmap newBitmap = Util.getOverlayBitmap(context, bitmap, text);
    bitmap.recycle();
    newBitmap = Util.getOverlayBitmap2(context, newBitmap, "Hello. Capture with Android Screenshot Service :)");
    Util.saveImage(context, newBitmap, fileName);
    newBitmap.recycle();
}
 
开发者ID:SinsangMarket,项目名称:ASS,代码行数:12,代码来源:ScreenShotContentObserver.java

示例12: free

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * Frees the bitmap
 * @param value the bitmap to free
 */
@Override
protected void free(Bitmap value) {
  Preconditions.checkNotNull(value);
  value.recycle();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:BitmapPool.java

示例13: scaleAndSaveImageInternal

import android.graphics.Bitmap; //导入方法依赖的package包/类
private static TLRPC.PhotoSize scaleAndSaveImageInternal(Bitmap bitmap, int w, int h, float photoW, float photoH, float scaleFactor, int quality, boolean cache, boolean scaleAnyway) throws Exception {
    Bitmap scaledBitmap;
    if (scaleFactor > 1 || scaleAnyway) {
        scaledBitmap = Bitmaps.createScaledBitmap(bitmap, w, h, true);
    } else {
        scaledBitmap = bitmap;
    }

    TLRPC.TL_fileLocation location = new TLRPC.TL_fileLocation();
    location.volume_id = Integer.MIN_VALUE;
    location.dc_id = Integer.MIN_VALUE;
    location.local_id = UserConfig.lastLocalId;
    UserConfig.lastLocalId--;
    TLRPC.PhotoSize size = new TLRPC.TL_photoSize();
    size.location = location;
    size.w = scaledBitmap.getWidth();
    size.h = scaledBitmap.getHeight();
    if (size.w <= 100 && size.h <= 100) {
        size.type = "s";
    } else if (size.w <= 320 && size.h <= 320) {
        size.type = "m";
    } else if (size.w <= 800 && size.h <= 800) {
        size.type = "x";
    } else if (size.w <= 1280 && size.h <= 1280) {
        size.type = "y";
    } else {
        size.type = "w";
    }

    String fileName = location.volume_id + "_" + location.local_id + ".jpg";
    final File cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
    FileOutputStream stream = new FileOutputStream(cacheFile);
    scaledBitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream);
    if (cache) {
        ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
        scaledBitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream2);
        size.bytes = stream2.toByteArray();
        size.size = size.bytes.length;
        stream2.close();
    } else {
        size.size = (int) stream.getChannel().size();
    }
    stream.close();
    if (scaledBitmap != bitmap) {
        scaledBitmap.recycle();
    }

    return size;
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:50,代码来源:ImageLoader.java

示例14: getImageThumbnail

import android.graphics.Bitmap; //导入方法依赖的package包/类
public static Bitmap getImageThumbnail(String path, int mMaxWidth, int mMaxHeight){
    Bitmap.Config mDecodeConfig = Bitmap.Config.RGB_565;
    ImageView.ScaleType mScaleType = ImageView.ScaleType.CENTER_CROP;

    File bitmapFile = new File(path);
    Bitmap bitmap = null;

    if (!bitmapFile.exists() || !bitmapFile.isFile()) {
        return bitmap;
    }

    BitmapFactory.Options decodeOptions = new BitmapFactory.Options();
    decodeOptions.inInputShareable = true;
    decodeOptions.inPurgeable = true;
    decodeOptions.inPreferredConfig = mDecodeConfig;
    if (mMaxWidth == 0 && mMaxHeight == 0) {

        bitmap = BitmapFactory.decodeFile(bitmapFile.getAbsolutePath(), decodeOptions);
    } else {
        // If we have to resize this image, first get the natural bounds.
        decodeOptions.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(bitmapFile.getAbsolutePath(), decodeOptions);
        int actualWidth = decodeOptions.outWidth;
        int actualHeight = decodeOptions.outHeight;

        // Then compute the dimensions we would ideally like to decode to.
        int desiredWidth = getResizedDimension(mMaxWidth, mMaxHeight,
                actualWidth, actualHeight, mScaleType);
        int desiredHeight = getResizedDimension(mMaxHeight, mMaxWidth,
                actualHeight, actualWidth, mScaleType);

        // Decode to the nearest power of two scaling factor.
        decodeOptions.inJustDecodeBounds = false;
        decodeOptions.inSampleSize = ImageUtils.findBestSampleSize(actualWidth, actualHeight, desiredWidth, desiredHeight);
        Bitmap tempBitmap = BitmapFactory.decodeFile(bitmapFile.getAbsolutePath(), decodeOptions);
        // If necessary, scale down to the maximal acceptable size.
        if (tempBitmap != null
                && (tempBitmap.getWidth() > desiredWidth || tempBitmap.getHeight() > desiredHeight)) {
            bitmap = Bitmap.createScaledBitmap(tempBitmap, desiredWidth,
                    desiredHeight, true);
            tempBitmap.recycle();
        } else {
            bitmap = tempBitmap;
        }

    }
    return bitmap;
}
 
开发者ID:gigabytedevelopers,项目名称:FireFiles,代码行数:49,代码来源:ImageUtils.java

示例15: scaleAndSaveImageInternal

import android.graphics.Bitmap; //导入方法依赖的package包/类
private static PhotoSize scaleAndSaveImageInternal(Bitmap bitmap, int w, int h, float photoW,
        float photoH, float scaleFactor, int quality, boolean cache, boolean scaleAnyway)
        throws Exception {
    Bitmap scaledBitmap;
    if (scaleFactor > 1 || scaleAnyway) {
        scaledBitmap = Bitmaps.createScaledBitmap(bitmap, w, h, true);
    } else {
        scaledBitmap = bitmap;
    }

    FileLocation.TL_fileLocation location = new FileLocation.TL_fileLocation();
    location.volume_id = Integer.MIN_VALUE;
    location.dc_id = Integer.MIN_VALUE;
    PhotoSize size = new PhotoSize.TL_photoSize();
    size.location = location;
    size.w = scaledBitmap.getWidth();
    size.h = scaledBitmap.getHeight();
    if (size.w <= 100 && size.h <= 100) {
        size.type = "s";
    } else if (size.w <= 320 && size.h <= 320) {
        size.type = "m";
    } else if (size.w <= 800 && size.h <= 800) {
        size.type = "x";
    } else if (size.w <= 1280 && size.h <= 1280) {
        size.type = "y";
    } else {
        size.type = "w";
    }

    String fileName = location.volume_id + "_" + location.local_id + ".jpg";
    final File cacheFile = new File(
            FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
    FileOutputStream stream = new FileOutputStream(cacheFile);
    scaledBitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream);
    if (cache) {
        ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
        scaledBitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream2);
        size.bytes = stream2.toByteArray();
        size.size = size.bytes.length;
        stream2.close();
    } else {
        size.size = (int) stream.getChannel().size();
    }
    stream.close();
    if (scaledBitmap != bitmap) {
        scaledBitmap.recycle();
    }

    return size;
}
 
开发者ID:chengzichen,项目名称:KrGallery,代码行数:51,代码来源:ImageLoader.java


注:本文中的android.graphics.Bitmap.recycle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。