本文整理了Java中android.graphics.Bitmap.recycle()
方法的一些代码示例,展示了Bitmap.recycle()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bitmap.recycle()
方法的具体详情如下:
包路径:android.graphics.Bitmap
类名称:Bitmap
方法名:recycle
暂无
代码示例来源:origin: CarGuo/GSYVideoPlayer
public static void saveBitmap(Bitmap bitmap, File file) {
if (bitmap != null) {
OutputStream outputStream;
try {
outputStream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
bitmap.recycle();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
代码示例来源:origin: stackoverflow.com
@Override
public Bitmap transform(Bitmap source) {
int size = Math.min(source.getWidth(), source.getHeight());
int x = (source.getWidth() - size) / 2;
int y = (source.getHeight() - size) / 2;
source.recycle();
canvas.drawCircle(r, r, r, paint);
squaredBitmap.recycle();
return bitmap;
代码示例来源:origin: stackoverflow.com
if (!(unscaledBitmap.getWidth() <= DESIREDWIDTH && unscaledBitmap.getHeight() <= DESIREDHEIGHT)) {
unscaledBitmap.recycle();
return path;
try {
fos = new FileOutputStream(f);
scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 75, fos);
fos.flush();
fos.close();
scaledBitmap.recycle();
} catch (Throwable e) {
代码示例来源:origin: stackoverflow.com
int height = bitmap.getHeight();
canvas.drawBitmap(bitmap, 0, height, paint);
webView.draw(canvas);
out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 50, out);
out.flush();
out.close();
bitmap.recycle();
} catch (Exception e) {
e.printStackTrace();
代码示例来源:origin: stackoverflow.com
Bitmap bmp = bmps.get(i);
bigcanvas.drawBitmap(bmp, 0, iHeight, paint);
iHeight+=bmp.getHeight();
bmp.recycle();
bmp=null;
代码示例来源:origin: stackoverflow.com
public Bitmap getResizedBitmap(Bitmap bm, int newWidth, int newHeight) {
int width = bm.getWidth();
int height = bm.getHeight();
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// CREATE A MATRIX FOR THE MANIPULATION
Matrix matrix = new Matrix();
// RESIZE THE BIT MAP
matrix.postScale(scaleWidth, scaleHeight);
// "RECREATE" THE NEW BITMAP
Bitmap resizedBitmap = Bitmap.createBitmap(
bm, 0, 0, width, height, matrix, false);
bm.recycle();
return resizedBitmap;
}
代码示例来源:origin: stackoverflow.com
File dir=Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
Bitmap b= BitmapFactory.decodeFile(PATH_ORIGINAL_IMAGE);
Bitmap out = Bitmap.createScaledBitmap(b, 320, 480, false);
File file = new File(dir, "resize.png");
FileOutputStream fOut;
try {
fOut = new FileOutputStream(file);
out.compress(Bitmap.CompressFormat.PNG, 100, fOut);
fOut.flush();
fOut.close();
b.recycle();
out.recycle();
} catch (Exception e) {}
代码示例来源:origin: commonsguy/cw-omnibus
latestBitmap.getWidth() != bitmapWidth ||
latestBitmap.getHeight() != height) {
if (latestBitmap != null) {
latestBitmap.recycle();
width, height);
cropped.compress(Bitmap.CompressFormat.PNG, 100, baos);
代码示例来源:origin: stackoverflow.com
int iHeight = bm.getHeight();
bigcanvas.drawBitmap(bm, 0, iHeight, paint);
webView.draw(bigcanvas);
fOut = new FileOutputStream(file);
bm.compress(Bitmap.CompressFormat.PNG, 50, fOut);
fOut.flush();
fOut.close();
bm.recycle();
} catch (Exception e) {
e.printStackTrace();
代码示例来源:origin: jeasonlzy/ImagePicker
/**
* 将图片按照指定的角度进行旋转
*
* @param bitmap 需要旋转的图片
* @param degree 指定的旋转角度
* @return 旋转后的图片
*/
public static Bitmap rotateBitmapByDegree(Bitmap bitmap, int degree) {
// 根据旋转角度,生成旋转矩阵
Matrix matrix = new Matrix();
matrix.postRotate(degree);
// 将原始图片按照旋转矩阵进行旋转,并得到新的图片
Bitmap newBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
if (!bitmap.isRecycled()) {
bitmap.recycle();
}
return newBitmap;
}
代码示例来源:origin: CarGuo/GSYVideoPlayer
public static void saveBitmap(Bitmap bitmap) throws FileNotFoundException {
if (bitmap != null) {
File file = new File(FileUtils.getPath(), "GSY-" + System.currentTimeMillis() + ".jpg");
OutputStream outputStream;
outputStream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
bitmap.recycle();
}
}
代码示例来源:origin: JessYanCoding/MVPArms
/**
* 改变Bitmap的长宽
*
* @param bitmap
* @return
*/
public static Bitmap getReSizeBitmap(Bitmap bitmap, float targetWidth, float targetheight) {
Bitmap returnBm = null;
int width = bitmap.getWidth();
int height = bitmap.getHeight();
Matrix matrix = new Matrix();
matrix.postScale(targetWidth / width, targetheight / height); //长和宽放大缩小的比例
try {
returnBm = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
} catch (Exception e) {
e.printStackTrace();
}
if (returnBm == null) {
returnBm = bitmap;
}
if (bitmap != returnBm) {
bitmap.recycle();
}
return returnBm;
}
代码示例来源:origin: nostra13/Android-Universal-Image-Loader
@Override
public boolean save(String imageUri, Bitmap bitmap) throws IOException {
File imageFile = getFile(imageUri);
File tmpFile = new File(imageFile.getAbsolutePath() + TEMP_IMAGE_POSTFIX);
OutputStream os = new BufferedOutputStream(new FileOutputStream(tmpFile), bufferSize);
boolean savedSuccessfully = false;
try {
savedSuccessfully = bitmap.compress(compressFormat, compressQuality, os);
} finally {
IoUtils.closeSilently(os);
if (savedSuccessfully && !tmpFile.renameTo(imageFile)) {
savedSuccessfully = false;
}
if (!savedSuccessfully) {
tmpFile.delete();
}
}
bitmap.recycle();
return savedSuccessfully;
}
代码示例来源:origin: frogermcs/InstaMaterial
@Override
public Bitmap transform(Bitmap source) {
int size = Math.min(source.getWidth(), source.getHeight());
int x = (source.getWidth() - size) / 2;
int y = (source.getHeight() - size) / 2;
Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);
if (squaredBitmap != source) {
source.recycle();
}
Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig());
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
paint.setShader(shader);
paint.setAntiAlias(true);
float r = size / 2f;
canvas.drawCircle(r, r, r, paint);
squaredBitmap.recycle();
return bitmap;
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
@Override
public void writeImageFile(OutputStream outStream, String format, ByteBuffer imageData, int width, int height) throws IOException {
Bitmap bitmapImage = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
AndroidScreenshots.convertScreenShot(imageData, bitmapImage);
Bitmap.CompressFormat compressFormat;
if (format.equals("png")) {
compressFormat = Bitmap.CompressFormat.PNG;
} else if (format.equals("jpg")) {
compressFormat = Bitmap.CompressFormat.JPEG;
} else {
throw new UnsupportedOperationException("Only 'png' and 'jpg' formats are supported on Android");
}
bitmapImage.compress(compressFormat, 95, outStream);
bitmapImage.recycle();
}
代码示例来源:origin: pockethub/PocketHub
int width = source.getWidth();
int height = source.getHeight();
canvas.drawBitmap(clipped, 0, 0, paint);
source.recycle();
clipped.recycle();
代码示例来源:origin: bumptech/glide
private static InputStream openBitmapStream(CompressFormat format, int width, int height) {
Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
ByteArrayOutputStream os = new ByteArrayOutputStream();
bitmap.compress(format, 100 /*quality*/, os);
bitmap.recycle();
byte[] data = os.toByteArray();
return new ByteArrayInputStream(data);
}
代码示例来源:origin: crazycodeboy/TakePhoto
/**
* 将图片按照某个角度进行旋转
*
* @param bm 需要旋转的图片
* @param degree 旋转角度
* @return 旋转后的图片
*/
private Bitmap rotateBitmapByDegree(Bitmap bm, int degree) {
Bitmap returnBm = null;
// 根据旋转角度,生成旋转矩阵
Matrix matrix = new Matrix();
matrix.postRotate(degree);
try {
// 将原始图片按照旋转矩阵进行旋转,并得到新的图片
returnBm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true);
} catch (OutOfMemoryError e) {
}
if (returnBm == null) {
returnBm = bm;
}
if (bm != returnBm) {
bm.recycle();
}
return returnBm;
}
}
代码示例来源:origin: square/spoon
private static void writeBitmapToFile(Bitmap bitmap, File file) {
OutputStream fos = null;
try {
fos = new BufferedOutputStream(new FileOutputStream(file));
bitmap.compress(PNG, 100 /* quality */, fos);
chmodPlusR(file);
} catch (FileNotFoundException e) {
throw new RuntimeException("Cannot write screenshot to " + file, e);
} finally {
bitmap.recycle();
if (fos != null) {
try {
fos.close();
} catch (IOException ignored) {
}
}
}
}
代码示例来源:origin: cats-oss/android-gpuimage
private Bitmap scaleBitmap(Bitmap bitmap) {
// resize to desired dimensions
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int[] newSize = getScaleSize(width, height);
Bitmap workBitmap = Bitmap.createScaledBitmap(bitmap, newSize[0], newSize[1], true);
if (workBitmap != bitmap) {
bitmap.recycle();
bitmap = workBitmap;
System.gc();
}
if (scaleType == ScaleType.CENTER_CROP) {
// Crop it
int diffWidth = newSize[0] - outputWidth;
int diffHeight = newSize[1] - outputHeight;
workBitmap = Bitmap.createBitmap(bitmap, diffWidth / 2, diffHeight / 2,
newSize[0] - diffWidth, newSize[1] - diffHeight);
if (workBitmap != bitmap) {
bitmap.recycle();
bitmap = workBitmap;
}
}
return bitmap;
}
内容来源于网络,如有侵权,请联系作者删除!