public boolean cropBitmap(int whichWallpaper) {
Bitmap crop = mStreamProvider.readCroppedBitmap(
mCropBounds, mOutWidth, mOutHeight, mRotation);
if (crop == null) {
return false;
}
boolean failure = false;
// Compress to byte array
ByteArrayOutputStream tmpOut = new ByteArrayOutputStream(2048);
if (crop.compress(CompressFormat.JPEG, DEFAULT_COMPRESS_QUALITY, tmpOut)) {
// Set the wallpaper
try {
byte[] outByteArray = tmpOut.toByteArray();
WallpaperManagerCompat.getInstance(mContext).setStream(
new ByteArrayInputStream(outByteArray),
null, true, whichWallpaper);
if (mOnBitmapCroppedHandler != null) {
mOnBitmapCroppedHandler.onBitmapCropped(outByteArray);
}
} catch (IOException e) {
Log.w(TAG, "cannot write stream to wallpaper", e);
failure = true;
}
} else {
Log.w(TAG, "cannot compress bitmap");
failure = true;
}
return !failure; // True if any of the operations failed
}
CropAndSetWallpaperTask.java 文件源码
java
阅读 41
收藏 0
点赞 0
评论 0
项目:FlickLauncher
作者:
评论列表
文章目录