Java Code Examples for android.graphics.Bitmap.isRecycled()

The following are Jave code examples for showing how to use isRecycled() of the android.graphics.Bitmap class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: SmingZZick_App   File: SmingData.java   View Source Code Vote up 6 votes
public void putNewShot(Bitmap bitmap) {
    if (bitmap == null || bitmap.isRecycled()) {
        return;
    }

    mLastShotMills = System.currentTimeMillis();
    if (startShotBitmap == null) {
        startShotBitmap = bitmap;
        return;
    }

    if (duration == 0 && endShotBitmap != null) {
        if (endSecondShotBitmap != null) {
            endSecondShotBitmap.recycle();
        }

        endSecondShotBitmap = endShotBitmap;
    }

    endShotBitmap = bitmap;
}
 
Example 2
Project: boohee_v5.6   File: ShareCore.java   View Source Code Vote up 6 votes
public boolean share(Platform plat, HashMap<String, Object> data) {
    if (plat == null || data == null) {
        return false;
    }
    try {
        Bitmap viewToShare = (Bitmap) data.get("viewToShare");
        if (!(!TextUtils.isEmpty((String) data.get("imagePath")) || viewToShare == null || viewToShare.isRecycled())) {
            File ss = new File(R.getCachePath(plat.getContext(), "screenshot"), 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());
        }
        ShareParams sp = new ShareParams((HashMap) data);
        if (this.customizeCallback != null) {
            this.customizeCallback.onShare(plat, sp);
        }
        plat.share(sp);
        return true;
    } catch (Throwable t) {
        t.printStackTrace();
        return false;
    }
}
 
Example 3
Project: TextEmoji   File: OnekeyShareThemeImpl.java   View Source Code Vote up 6 votes
final ShareParams shareDataToShareParams(Platform plat) {
	if (plat == null || shareParamsMap == null) {
		toast("ssdk_oks_share_failed");
		return null;
	}

	try {
		String imagePath = ResHelper.forceCast(shareParamsMap.get("imagePath"));
		Bitmap viewToShare = ResHelper.forceCast(shareParamsMap.get("viewToShare"));
		if (TextUtils.isEmpty(imagePath) && viewToShare != null && !viewToShare.isRecycled()) {
			String path = ResHelper.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 4
Project: CXJPadProject   File: ConvertUtils.java   View Source Code Vote up 5 votes
/**
 * 把view转化为bitmap(截图)
 * 参见:http://www.cnblogs.com/lee0oo0/p/3355468.html
 */
public static Bitmap toBitmap(View view) {
    int width = view.getWidth();
    int height = view.getHeight();
    if (view instanceof ListView) {
        height = 0;
        // 获取listView实际高度
        ListView listView = (ListView) view;
        for (int i = 0; i < listView.getChildCount(); i++) {
            height += listView.getChildAt(i).getHeight();
        }
    } else if (view instanceof ScrollView) {
        height = 0;
        // 获取scrollView实际高度
        ScrollView scrollView = (ScrollView) view;
        for (int i = 0; i < scrollView.getChildCount(); i++) {
            height += scrollView.getChildAt(i).getHeight();
        }
    }
    view.setDrawingCacheEnabled(true);
    view.clearFocus();
    view.setPressed(false);
    boolean willNotCache = view.willNotCacheDrawing();
    view.setWillNotCacheDrawing(false);
    // Reset the drawing cache background color to fully transparent for the duration of this operation
    int color = view.getDrawingCacheBackgroundColor();
    view.setDrawingCacheBackgroundColor(Color.WHITE);//截图去黑色背景(透明像素)
    if (color != Color.WHITE) {
        view.destroyDrawingCache();
    }
    view.buildDrawingCache();
    Bitmap cacheBitmap = view.getDrawingCache();
    if (cacheBitmap == null) {
        return null;
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawBitmap(cacheBitmap, 0, 0, null);
    canvas.save(Canvas.ALL_SAVE_FLAG);
    canvas.restore();
    if (!bitmap.isRecycled()) {
        LogUtils.verbose("recycle bitmap: " + bitmap.toString());
        bitmap.recycle();
    }
    // Restore the view
    view.destroyDrawingCache();
    view.setWillNotCacheDrawing(willNotCache);
    view.setDrawingCacheBackgroundColor(color);
    return bitmap;
}
 
Example 5
Project: Depth   File: RenderableBear.java   View Source Code Vote up 5 votes
public void destroy() {
    for (Bitmap bitmap : bitmaps) {
        if (bitmap != null && !bitmap.isRecycled()) {
            bitmap.recycle();
        }
    }

}
 
Example 6
Project: RLibrary   File: ImageUtils.java   View Source Code Vote up 5 votes
/**
 * 添加倒影
 *
 * @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(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;
}
 
Example 7
Project: PaoMovie   File: MagicMovieDisplay.java   View Source Code Vote up 5 votes
public void setImageBitmap(Bitmap bitmap) {
	if (bitmap == null || bitmap.isRecycled())
		return;
	mImageWidth = bitmap.getWidth();
	mImageHeight = bitmap.getHeight();
	mOriginBitmap = bitmap;
	adjustImageDisplaySize();
	mMagicSDK.storeBitmap(mOriginBitmap, false);
	refreshDisplay();
}
 
Example 8
Project: BaseCore   File: ImageUtils.java   View Source Code Vote up 5 votes
/**
 * 转为灰度图片
 *
 * @param src     源图片
 * @param recycle 是否回收
 * @return 灰度图
 */
public static Bitmap toGray(Bitmap src, boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    Bitmap grayBitmap = Bitmap.createBitmap(src.getWidth(),
            src.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(grayBitmap);
    Paint paint = new Paint();
    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.setSaturation(0);
    ColorMatrixColorFilter colorMatrixColorFilter = new ColorMatrixColorFilter(colorMatrix);
    paint.setColorFilter(colorMatrixColorFilter);
    canvas.drawBitmap(src, 0, 0, paint);
    if (recycle && !src.isRecycled()) src.recycle();
    return grayBitmap;
}
 
Example 9
Project: zabbkit-android   File: GestureImageView.java   View Source Code Vote up 5 votes
protected boolean isRecycled() {
	if(drawable != null && drawable instanceof BitmapDrawable) {
		Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();
		if(bitmap != null) {
			return bitmap.isRecycled();
		}
	}
	return false;
}
 
Example 10
Project: homunculus   File: BitmapPoolFactory.java   View Source Code Vote up 5 votes
@Override
public void returnBitmap(Bitmap bmp) {
    if (bmp != null && !bmp.isRecycled()) {
        Handler h = new Handler(Looper.getMainLooper());
        h.post(() -> {
            h.post(() -> {
                bmp.recycle();
            });
        });
    }
}
 
Example 11
Project: Fatigue-Detection   File: STUtils.java   View Source Code Vote up 5 votes
public static Bitmap getRotateBitmap(Bitmap bitmap, int rotation){
	if(null == bitmap || bitmap.isRecycled()){
		return null;
	}
	
	Matrix matrix = new Matrix();
	matrix.postRotate(rotation);
	Bitmap cropBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),bitmap.getHeight(), matrix, false);
	return cropBitmap;
}
 
Example 12
Project: boohee_v5.6   File: FollowListPage.java   View Source Code Vote up 5 votes
public View getView(int position, View convertView, ViewGroup parent) {
    FollowListItem item;
    boolean simpleMode = "FacebookMessenger".equals(this.platform.getName());
    if (convertView == null) {
        View llItem = new LinearLayout(parent.getContext());
        item = new FollowListItem();
        llItem.setTag(item);
        convertView = llItem;
        int dp_52 = R.dipToPx(getContext(), 52);
        int dp_10 = R.dipToPx(parent.getContext(), 10);
        int dp_5 = R.dipToPx(parent.getContext(), 5);
        if (!simpleMode) {
            item.aivIcon = new AsyncImageView(getContext());
            LayoutParams lpIcon = new LayoutParams(dp_52, dp_52);
            lpIcon.gravity = 16;
            lpIcon.setMargins(dp_10, dp_5, dp_10, dp_5);
            item.aivIcon.setLayoutParams(lpIcon);
            llItem.addView(item.aivIcon);
        }
        LinearLayout llText = new LinearLayout(parent.getContext());
        llText.setPadding(0, dp_10, dp_10, dp_10);
        llText.setOrientation(1);
        LayoutParams lpText = new LayoutParams(-2, -2);
        lpText.gravity = 16;
        lpText.weight = 1.0f;
        llText.setLayoutParams(lpText);
        llItem.addView(llText);
        item.tvName = new TextView(parent.getContext());
        item.tvName.setTextColor(-16777216);
        item.tvName.setTextSize(1, 18.0f);
        item.tvName.setSingleLine();
        if (simpleMode) {
            item.tvName.setPadding(dp_10, 0, 0, 0);
        }
        llText.addView(item.tvName);
        if (!simpleMode) {
            item.tvSign = new TextView(parent.getContext());
            item.tvSign.setTextColor(2130706432);
            item.tvSign.setTextSize(1, 14.0f);
            item.tvSign.setSingleLine();
            llText.addView(item.tvSign);
        }
        item.ivCheck = new ImageView(parent.getContext());
        item.ivCheck.setPadding(0, 0, dp_10, 0);
        LayoutParams lpCheck = new LayoutParams(-2, -2);
        lpCheck.gravity = 16;
        item.ivCheck.setLayoutParams(lpCheck);
        llItem.addView(item.ivCheck);
    } else {
        item = (FollowListItem) convertView.getTag();
    }
    Following following = getItem(position);
    item.tvName.setText(following.screenName);
    if (!simpleMode) {
        item.tvSign.setText(following.description);
    }
    item.ivCheck.setImageBitmap(following.checked ? this.bmChd : this.bmUnch);
    if (!simpleMode) {
        if (isFling()) {
            Bitmap bm = BitmapProcessor.getBitmapFromCache(following.icon);
            if (bm == null || bm.isRecycled()) {
                item.aivIcon.execute(null, 0);
            } else {
                item.aivIcon.setImageBitmap(bm);
            }
        } else {
            item.aivIcon.execute(following.icon, 0);
        }
    }
    if (position == getCount() - 1) {
        next();
    }
    return convertView;
}
 
Example 13
Project: BaseCore   File: ImageUtils.java   View Source Code Vote up 5 votes
/**
 * 快速模糊图片
 * <p>先缩小原图,对小图进行模糊,再放大回原先尺寸</p>
 *
 * @param src     源图片
 * @param scale   缩放比例(0...1)
 * @param radius  模糊半径
 * @param recycle 是否回收
 * @return 模糊后的图片
 */
public static Bitmap fastBlur(Bitmap src, float scale, float radius, boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    int width = src.getWidth();
    int height = src.getHeight();
    int scaleWidth = (int) (width * scale + 0.5f);
    int scaleHeight = (int) (height * scale + 0.5f);
    if (scaleWidth == 0 || scaleHeight == 0) return null;
    Bitmap scaleBitmap = Bitmap.createScaledBitmap(src, scaleWidth, scaleHeight, true);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG);
    Canvas canvas = new Canvas();
    PorterDuffColorFilter filter = new PorterDuffColorFilter(
            Color.TRANSPARENT, PorterDuff.Mode.SRC_ATOP);
    paint.setColorFilter(filter);
    canvas.scale(scale, scale);
    canvas.drawBitmap(scaleBitmap, 0, 0, paint);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        scaleBitmap = renderScriptBlur(Utils.getContext(), scaleBitmap, radius);
    } else {
        scaleBitmap = stackBlur(scaleBitmap, (int) radius, recycle);
    }
    if (scale == 1) return scaleBitmap;
    Bitmap ret = Bitmap.createScaledBitmap(scaleBitmap, width, height, true);
    if (scaleBitmap != null && !scaleBitmap.isRecycled()) scaleBitmap.recycle();
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
 
Example 14
Project: AndroidUtilCode-master   File: ImageUtils.java   View Source Code Vote up 5 votes
/**
 * 按采样大小压缩
 *
 * @param src        源图片
 * @param sampleSize 采样率大小
 * @param recycle    是否回收
 * @return 按采样率压缩后的图片
 */
public static Bitmap compressBySampleSize(Bitmap src, int sampleSize, boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = sampleSize;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    src.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte[] bytes = baos.toByteArray();
    if (recycle && !src.isRecycled()) src.recycle();
    return BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options);
}
 
Example 15
Project: ViseFace   File: FaceDetectorActivity.java   View Source Code Vote up 5 votes
private Bitmap rotaingImageView(int angle, Bitmap bitmap) {
    Matrix matrix = new Matrix();
    matrix.postRotate((float)angle);
    Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    if(resizedBitmap != bitmap && bitmap != null && !bitmap.isRecycled()) {
        bitmap.recycle();
        bitmap = null;
    }

    return resizedBitmap;
}
 
Example 16
Project: AnimationsDemo   File: ImageUtils.java   View Source Code Vote up 5 votes
public static Bitmap imageWithFixedRotation(Bitmap bm, int degrees) {
    if (bm == null || bm.isRecycled())
        return null;

    if (degrees == 0)
        return bm;

    final Matrix matrix = new Matrix();
    matrix.postRotate(degrees);
    Bitmap result = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true);
    if (result != bm)
        bm.recycle();
    return result;

}
 
Example 17
Project: tiny   File: BitmapCompressor.java   View Source Code Vote up 4 votes
public static Bitmap compress(Bitmap bitmap, Tiny.BitmapCompressOptions options, boolean isViewMode) {
    if (bitmap == null || bitmap.isRecycled())
        return null;

    if (options == null)
        options = new Tiny.BitmapCompressOptions();

    int compressWidth = options.width;
    int compressHeight = options.height;

    Bitmap result;

    Pair<Integer, Integer> screenPair = CompressKit.getDeviceScreenSizeInPixels();

    boolean hasCustomSize = false;

    if (compressWidth > 0 && compressHeight > 0)
        hasCustomSize = true;

    int baseline;
    if (isViewMode) {
        if (screenPair.second >= CompressKit.DEFAULT_MAX_COMPRESS_SIZE ||
                screenPair.first >= CompressKit.DEFAULT_MAX_COMPRESS_SIZE) {
            baseline = hasCustomSize ? Math.min(CompressKit.DEFAULT_MAX_COMPRESS_SIZE, Math.max(compressWidth, compressHeight)) : CompressKit.DEFAULT_MAX_COMPRESS_SIZE;
            result = matrixCompress(bitmap, baseline, false);
        } else {
            baseline = hasCustomSize ? Math.min(CompressKit.DEFAULT_MAX_COMPRESS_SIZE, Math.max(compressWidth, compressHeight)) : screenPair.second;
            result = matrixCompress(bitmap, baseline, false);
        }
    } else {
        baseline = hasCustomSize ? Math.min(CompressKit.DEFAULT_MAX_COMPRESS_SIZE, Math.max(compressWidth, compressHeight)) : CompressKit.DEFAULT_MAX_COMPRESS_SIZE;
        result = matrixCompress(bitmap, baseline, false);
    }

    if (result == null)
        return null;

    if (hasCustomSize) {
        result = customCompress(result, compressWidth, compressHeight, false);
    }

    return result;
}
 
Example 18
Project: pc-android-controller-android   File: ScreentShotUtil.java   View Source Code Vote up 4 votes
/**
 * Takes Reboot screenshot of the current display and shows an animation.
 */
@SuppressLint("NewApi")
public void takeScreenshot(Context context, String fileFullPath)
{
    if(fileFullPath == ""){
        format = new SimpleDateFormat("yyyyMMddHHmmss");
        String fileName = format.format(new Date(System.currentTimeMillis())) + ".png";
        fileFullPath = "/data/local/tmp/" + fileName;
    }

    if(ShellUtils.checkRootPermission()){
        if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH){
            ShellUtils.execCommand("/system/bin/screencap -p "+ fileFullPath,true);
        }
    }
    else {
        if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2 && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH){
            wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
            mDisplay = wm.getDefaultDisplay();
            mDisplayMatrix = new Matrix();
            mDisplayMetrics = new DisplayMetrics();
            // We need to orient the screenshot correctly (and the Surface api seems to take screenshots
            // only in the natural orientation of the device :!)
            mDisplay.getRealMetrics(mDisplayMetrics);
            float[] dims =
                    {
                            mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels
                    };
            float degrees = getDegreesForRotation(mDisplay.getRotation());
            boolean requiresRotation = (degrees > 0);
            if (requiresRotation)
            {
                // Get the dimensions of the device in its native orientation
                mDisplayMatrix.reset();
                mDisplayMatrix.preRotate(-degrees);
                mDisplayMatrix.mapPoints(dims);
                dims[0] = Math.abs(dims[0]);
                dims[1] = Math.abs(dims[1]);
            }

            Bitmap mScreenBitmap = screenShot((int) dims[0], (int) dims[1]);
            if (requiresRotation)
            {
                // Rotate the screenshot to the current orientation
                Bitmap ss = Bitmap.createBitmap(mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels,
                        Bitmap.Config.ARGB_8888);
                Canvas c = new Canvas(ss);
                c.translate(ss.getWidth() / 2, ss.getHeight() / 2);
                c.rotate(degrees);
                c.translate(-dims[0] / 2, -dims[1] / 2);
                c.drawBitmap(mScreenBitmap, 0, 0, null);
                c.setBitmap(null);
                mScreenBitmap = ss;
                if (ss != null && !ss.isRecycled())
                {
                    ss.recycle();
                }
            }

            // If we couldn't take the screenshot, notify the user
            if (mScreenBitmap == null)
            {
                Toast.makeText(context, "screen shot fail", Toast.LENGTH_SHORT).show();
            }

            // Optimizations
            mScreenBitmap.setHasAlpha(false);
            mScreenBitmap.prepareToDraw();

            saveBitmap2file(context, mScreenBitmap, fileFullPath);
        }
    }

}
 
Example 19
Project: AndroidCollection   File: IOActivity.java   View Source Code Vote up 4 votes
@Override
protected void onPostExecute(Bitmap bitmap) {
    if(bitmap != null && !bitmap.isRecycled() && imageView != null)
        imageView.setImageBitmap(bitmap);
    super.onPostExecute(bitmap);
}
 
Example 20
Project: RLibrary   File: ImageUtils.java   View Source Code Vote up 3 votes
/**
 * 缩放图片
 *
 * @param src         源图片
 * @param scaleWidth  缩放宽度倍数
 * @param scaleHeight 缩放高度倍数
 * @param recycle     是否回收
 * @return 缩放后的图片
 */
public static Bitmap scale(Bitmap src, float scaleWidth, float scaleHeight, boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    Matrix matrix = new Matrix();
    matrix.setScale(scaleWidth, scaleHeight);
    Bitmap ret = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}