Java Code Examples for android.graphics.Bitmap#isRecycled()
The following examples show how to use
android.graphics.Bitmap#isRecycled() .
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: BitmapUtils.java From CrawlerForReader with Apache License 2.0 | 6 votes |
/** * 根据给定的宽和高进行拉伸 * * @param origin 原图 * @param newWidth 新图的宽 * @param newHeight 新图的高 * @return new Bitmap */ public static Bitmap scaleBitmap(Bitmap origin, int newWidth, int newHeight) { if (origin == null) { return null; } int height = origin.getHeight(); int width = origin.getWidth(); float scaleWidth = ((float) newWidth) / width; float scaleHeight = ((float) newHeight) / height; Matrix matrix = new Matrix(); matrix.postScale(scaleWidth, scaleHeight);// 使用后乘 Bitmap newBM = Bitmap.createBitmap(origin, 0, 0, width, height, matrix, false); if (!origin.isRecycled()) { origin.recycle(); } return newBM; }
Example 2
Source File: ImgUtils.java From MiPushFramework with GNU General Public License v3.0 | 6 votes |
public static Bitmap scaleImage(Bitmap bm, int newWidth, int newHeight) { if (bm == null) { return null; } int width = bm.getWidth(); int height = bm.getHeight(); float scaleWidth = ((float) newWidth) / width; float scaleHeight = ((float) newHeight) / height; Matrix matrix = new Matrix(); matrix.postScale(scaleWidth, scaleHeight); Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true); if (!bm.isRecycled()) { bm.recycle(); } return newbm; }
Example 3
Source File: WeiboBaseShareInstance.java From SimpleProject with MIT License | 6 votes |
/** * 普通分享,支持文字,链接,图片 注意:微博分享设置title无效,链接应追加在desc后面 * @param activity * @param desc * @param url * @param bitmap */ private void shareMediaByWeibo(Activity activity, String desc, String url, Bitmap bitmap) { WeiboMultiMessage multiMessage = new WeiboMultiMessage(); if (!TextUtils.isEmpty(desc)) { TextObject textObject = new TextObject(); textObject.text = desc + " " + url; multiMessage.textObject = textObject; } if (bitmap != null && !bitmap.isRecycled()) { ImageObject imageObject = new ImageObject(); imageObject.setImageObject(bitmap); multiMessage.imageObject = imageObject; } shareHandler.shareMessage(multiMessage, false); }
Example 4
Source File: RxImageTool.java From RxTools-master with Apache License 2.0 | 6 votes |
/** * 添加颜色边框 * * @param src 源图片 * @param borderWidth 边框宽度 * @param color 边框的颜色值 * @param recycle 是否回收 * @return 带颜色边框图 */ public static Bitmap addFrame(Bitmap src, int borderWidth, int color, boolean recycle) { if (isEmptyBitmap(src)) return null; int newWidth = src.getWidth() + borderWidth >> 1; int newHeight = src.getHeight() + borderWidth >> 1; Bitmap ret = Bitmap.createBitmap(newWidth, newHeight, src.getConfig()); Canvas canvas = new Canvas(ret); Rect rec = canvas.getClipBounds(); Paint paint = new Paint(); paint.setColor(color); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(borderWidth); canvas.drawRect(rec, paint); canvas.drawBitmap(src, borderWidth, borderWidth, null); if (recycle && !src.isRecycled()) src.recycle(); return ret; }
Example 5
Source File: OnekeyShareThemeImpl.java From MyHearts with Apache License 2.0 | 6 votes |
final ShareParams shareDataToShareParams(Platform plat) { if (plat == null || shareParamsMap == null) { toast("ssdk_oks_share_failed"); return null; } try { String imagePath = R.forceCast(shareParamsMap.get("imagePath")); Bitmap viewToShare = R.forceCast(shareParamsMap.get("viewToShare")); if (TextUtils.isEmpty(imagePath) && viewToShare != null && !viewToShare.isRecycled()) { String path = R.getCachePath(plat.getContext(), "screenshot"); File ss = new File(path, String.valueOf(System.currentTimeMillis()) + ".jpg"); FileOutputStream fos = new FileOutputStream(ss); viewToShare.compress(CompressFormat.JPEG, 100, fos); fos.flush(); fos.close(); shareParamsMap.put("imagePath", ss.getAbsolutePath()); } } catch (Throwable t) { t.printStackTrace(); toast("ssdk_oks_share_failed"); return null; } return new ShareParams(shareParamsMap); }
Example 6
Source File: BitmapUtil.java From Android-Application-ZJB with Apache License 2.0 | 5 votes |
/** * 处理高斯模糊效果 * * @param sentBitmap 需要高斯模糊的Bitmap对象 * @param blurWidth 高斯模糊的大小 * @param blurHeight 高斯模糊的大小 * @param radius 高斯模糊的半径 * @return 返回一个高斯模糊的Bitmap对象 */ public static Bitmap fastblur(Bitmap sentBitmap, int blurWidth, int blurHeight, float radius) { if (sentBitmap == null || sentBitmap.isRecycled()) { return sentBitmap; } int bmpWidth = sentBitmap.getWidth(); int bmpHeight = sentBitmap.getHeight(); GaussianBlur blurProcess = new GaussianBlur(); if (bmpWidth <= blurWidth && bmpHeight <= blurHeight) { return blurProcess.blur(sentBitmap, radius); } else { Bitmap scaleBitmap = scaleBitmap(sentBitmap, blurWidth, blurHeight); return blurProcess.blur(scaleBitmap, radius); } }
Example 7
Source File: BitmapUtil.java From HaoReader with GNU General Public License v3.0 | 5 votes |
/** * 检查图片是否超过一定值,是则缩小 */ public static Bitmap convertToThumb(byte[] buffer, float size) { // 获取原图宽度 BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; options.inPurgeable = true; options.inInputShareable = true; Bitmap bm = BitmapFactory.decodeByteArray(buffer, 0, buffer.length, options); // 计算缩放比例 float reSize = options.outWidth / size; if (options.outWidth > options.outHeight) { reSize = options.outHeight / size; } if (reSize <= 0) { reSize = 1; } Log.d(TAG, "convertToThumb, reSize:" + reSize); // 缩放 options.inJustDecodeBounds = false; options.inSampleSize = (int) reSize; if (bm != null && !bm.isRecycled()) { bm.recycle(); bm = null; Log.e(TAG, "convertToThumb, recyle"); } bm = BitmapFactory.decodeByteArray(buffer, 0, buffer.length, options); if (bm == null) { Log.e(TAG, "convertToThumb, decode fail:" + null); return null; } return bm; }
Example 8
Source File: RLWeixinHelper.java From Roid-Library with Apache License 2.0 | 5 votes |
/** * @param title * @param desc * @param url * @param bmp * @param isTimeline * @return */ public boolean sendUrlBmp(String title, String desc, String url, Bitmap bmp, boolean isTimeline) { WXMediaMessage msg = createMediaMsg(title, desc); WXWebpageObject webpageObj = new WXWebpageObject(); webpageObj.webpageUrl = url; msg.mediaObject = webpageObj; if (bmp != null && !bmp.isRecycled()) { setThumbBmpDataToMsg(msg, bmp); } return sendReq(msg, isTimeline); }
Example 9
Source File: ImageDownloader.java From letv with Apache License 2.0 | 5 votes |
static void callback(ImageDownloadStateListener listener, Bitmap bitmap, int status) { if (listener != null) { if (status == 0) { listener.loading(); } else if (status == 1) { if (bitmap != null && bitmap.isRecycled()) { bitmap = null; } listener.loadSuccess(bitmap); } else { listener.loadFailed(); } } }
Example 10
Source File: ImageUtils.java From Android-UtilCode with Apache License 2.0 | 5 votes |
/** * 添加图片水印 * * @param src 源图片 * @param watermark 图片水印 * @param x 起始坐标x * @param y 起始坐标y * @param alpha 透明度 * @param recycle 是否回收 * @return 带有图片水印的图片 */ public static Bitmap addImageWatermark(Bitmap src, Bitmap watermark, int x, int y, int alpha, boolean recycle) { if (isEmptyBitmap(src)) return null; Bitmap ret = src.copy(src.getConfig(), true); if (!isEmptyBitmap(watermark)) { Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); Canvas canvas = new Canvas(ret); paint.setAlpha(alpha); canvas.drawBitmap(watermark, x, y, paint); } if (recycle && !src.isRecycled()) src.recycle(); return ret; }
Example 11
Source File: BitmapUtil.java From AndroidBasicProject with MIT License | 5 votes |
/** * 释放Bitmap * * @param bitmaps */ public static void release(Bitmap... bitmaps) { if (bitmaps != null) { try { for (Bitmap bitmap : bitmaps) { if (bitmap != null && !bitmap.isRecycled()) { bitmap.recycle(); } } } catch (Exception e) { e.printStackTrace(); } } }
Example 12
Source File: ImageUtil.java From QrScan with Apache License 2.0 | 5 votes |
public static void recycleBitmap(Bitmap bitmap){ //回收这个图片的内存 if(bitmap != null && !bitmap.isRecycled()){ bitmap.recycle(); bitmap = null; } }
Example 13
Source File: DragFloatViewHelper.java From MultiItem with Apache License 2.0 | 5 votes |
/** * @param coverView 被覆盖的view,用于生产浮层View * @return 需要跟随手势浮动的 View */ protected View createFloatView(View coverView) { ImageView floatView = new ImageView(coverView.getContext()); coverView.destroyDrawingCache(); coverView.setDrawingCacheEnabled(true); Bitmap bitmap = coverView.getDrawingCache(); if (bitmap != null && !bitmap.isRecycled()) { floatView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); floatView.setImageBitmap(bitmap); } return floatView; }
Example 14
Source File: BitmapUtil.java From RxAndroidBootstrap with Apache License 2.0 | 5 votes |
/** * Recycle the bitmap with null checks. * If the bitmap is already recycled, do nothing. * * @param bitmap to recycle. */ public static void recycle(Bitmap bitmap) { if (bitmap == null || bitmap.isRecycled()) { return; } bitmap.recycle(); }
Example 15
Source File: BitmapUtils.java From imsdk-android with MIT License | 5 votes |
/** * 回收bitmap * * @param bitmap 回收的bitmap */ public static void recycle(Bitmap bitmap) { if (null != bitmap && !bitmap.isRecycled()) { bitmap.recycle(); bitmap = null; } System.gc(); }
Example 16
Source File: ShareCore.java From BigApp_Discuz_Android with Apache License 2.0 | 5 votes |
/** * 向指定平台分享内容 * <p> * <b>注意:</b><br> * 参数data的键值需要严格按照{@link ShareParams}不同子类具体字段来命名, *否则无法反射此字段,也无法设置其值。 */ public boolean share(Platform plat, HashMap<String, Object> data) { if (plat == null || data == null) { return false; } try { String imagePath = (String) data.get("imagePath"); Bitmap viewToShare = (Bitmap) data.get("viewToShare"); if (TextUtils.isEmpty(imagePath) && viewToShare != null && !viewToShare.isRecycled()) { String path = R.getCachePath(plat.getContext(), "screenshot"); File ss = new File(path, String.valueOf(System.currentTimeMillis()) + ".jpg"); FileOutputStream fos = new FileOutputStream(ss); viewToShare.compress(CompressFormat.JPEG, 100, fos); fos.flush(); fos.close(); data.put("imagePath", ss.getAbsolutePath()); } } catch (Throwable t) { t.printStackTrace(); return false; } ShareParams sp = new ShareParams(data); if (customizeCallback != null) { customizeCallback.onShare(plat, sp); } plat.share(sp); return true; }
Example 17
Source File: OnekeyShareThemeImpl.java From fingerpoetry-android with Apache License 2.0 | 4 votes |
final ShareParams shareDataToShareParams(Platform plat) { if (plat == null || shareParamsMap == null) { toast("ssdk_oks_share_failed"); return null; } try { String imagePath = R.forceCast(shareParamsMap.get("imagePath")); Bitmap viewToShare = R.forceCast(shareParamsMap.get("viewToShare")); if (TextUtils.isEmpty(imagePath) && viewToShare != null && !viewToShare.isRecycled()) { String path = R.getCachePath(plat.getContext(), "screenshot"); File ss = new File(path, String.valueOf(System.currentTimeMillis()) + ".jpg"); FileOutputStream fos = new FileOutputStream(ss); viewToShare.compress(CompressFormat.JPEG, 100, fos); fos.flush(); fos.close(); shareParamsMap.put("imagePath", ss.getAbsolutePath()); } } catch (Throwable t) { t.printStackTrace(); toast("ssdk_oks_share_failed"); return null; } return new ShareParams(shareParamsMap); }
Example 18
Source File: FilterShaders.java From Telegram with GNU General Public License v2.0 | 4 votes |
private void loadTexture(Bitmap bitmap, int orientation, int w, int h) { renderBufferWidth = w; renderBufferHeight = h; if (renderFrameBuffer == null) { renderFrameBuffer = new int[3]; GLES20.glGenFramebuffers(3, renderFrameBuffer, 0); GLES20.glGenTextures(3, renderTexture, 0); } if (bitmap != null && !bitmap.isRecycled()) { float maxSize = AndroidUtilities.getPhotoSize(); if (renderBufferWidth > maxSize || renderBufferHeight > maxSize || orientation % 360 != 0) { float scale = 1; if (renderBufferWidth > maxSize || renderBufferHeight > maxSize) { float scaleX = maxSize / bitmap.getWidth(); float scaleY = maxSize / bitmap.getHeight(); if (scaleX < scaleY) { renderBufferWidth = (int) maxSize; renderBufferHeight = (int) (bitmap.getHeight() * scaleX); scale = scaleX; } else { renderBufferHeight = (int) maxSize; renderBufferWidth = (int) (bitmap.getWidth() * scaleY); scale = scaleY; } } if (orientation % 360 == 90 || orientation % 360 == 270) { int temp = renderBufferWidth; renderBufferWidth = renderBufferHeight; renderBufferHeight = temp; } bitmap = createBitmap(bitmap, orientation, renderBufferWidth, renderBufferHeight, scale); } GLES20.glBindTexture(GL10.GL_TEXTURE_2D, renderTexture[1]); GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE); GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0); } else { GLES20.glBindTexture(GL10.GL_TEXTURE_2D, renderTexture[1]); GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE); GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE); GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, renderBufferWidth, renderBufferHeight, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null); } GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, renderTexture[0]); GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE); GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE); GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, renderBufferWidth, renderBufferHeight, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, renderTexture[2]); GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE); GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE); GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, renderBufferWidth, renderBufferHeight, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null); }
Example 19
Source File: PicViewActivity.java From PinchImageView with MIT License | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //获取参数 ImageSource image = (ImageSource) getIntent().getSerializableExtra("image"); String memoryCacheKey = getIntent().getStringExtra("cache_key"); final Rect rect = getIntent().getParcelableExtra("rect"); final ImageView.ScaleType scaleType = (ImageView.ScaleType) getIntent().getSerializableExtra("scaleType"); final ImageObject thumb = image.getThumb(100, 100); ImageLoader imageLoader = Global.getImageLoader(getApplicationContext()); DisplayImageOptions originOptions = new DisplayImageOptions.Builder().build(); //view初始化 setContentView(R.layout.activity_pic_view); mImageView = (PinchImageView) findViewById(R.id.pic); mBackground = findViewById(R.id.background); Bitmap bitmap = imageLoader.getMemoryCache().get(memoryCacheKey); if (bitmap != null && !bitmap.isRecycled()) { mImageView.setImageBitmap(bitmap); } imageLoader.displayImage(image.getThumb(1000, 1000).url, mImageView, originOptions); mImageView.post(new Runnable() { @Override public void run() { mImageView.setAlpha(1f); //背景动画 mBackgroundAnimator = ObjectAnimator.ofFloat(mBackground, "alpha", 0f, 1f); mBackgroundAnimator.setDuration(ANIM_TIME); mBackgroundAnimator.start(); //status bar高度修正 Rect tempRect = new Rect(); mImageView.getGlobalVisibleRect(tempRect); rect.top = rect.top - tempRect.top; rect.bottom = rect.bottom - tempRect.top; //mask动画 mThumbMaskRect = new RectF(rect); RectF bigMaskRect = new RectF(0, 0, mImageView.getWidth(), mImageView.getHeight()); mImageView.zoomMaskTo(mThumbMaskRect, 0); mImageView.zoomMaskTo(bigMaskRect, ANIM_TIME); //图片放大动画 RectF thumbImageMatrixRect = new RectF(); PinchImageView.MathUtils.calculateScaledRectInContainer(new RectF(rect), thumb.width, thumb.height, scaleType, thumbImageMatrixRect); RectF bigImageMatrixRect = new RectF(); PinchImageView.MathUtils.calculateScaledRectInContainer(new RectF(0, 0, mImageView.getWidth(), mImageView.getHeight()), thumb.width, thumb.height, ImageView.ScaleType.FIT_CENTER, bigImageMatrixRect); mThumbImageMatrix = new Matrix(); PinchImageView.MathUtils.calculateRectTranslateMatrix(bigImageMatrixRect, thumbImageMatrixRect, mThumbImageMatrix); mImageView.outerMatrixTo(mThumbImageMatrix, 0); mImageView.outerMatrixTo(new Matrix(), ANIM_TIME); } }); mImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mImageView.playSoundEffect(SoundEffectConstants.CLICK); finish(); } }); }
Example 20
Source File: CacheableBitmapDrawable.java From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Returns true when this wrapper has a bitmap and the bitmap has not been recycled. * * @return true - if the bitmap has not been recycled. */ public synchronized boolean isBitmapValid() { Bitmap bitmap = getBitmap(); return !mReused && null != bitmap && !bitmap.isRecycled(); }