private String outputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException {
// Some content: URIs do not map to file paths (e.g. picasa).
String realPath = FileHelper.getRealPath(uri, this.cordova);
// Get filename from uri
String fileName = realPath != null ?
realPath.substring(realPath.lastIndexOf('/') + 1) :
"modified." + (this.encodingType == JPEG ? "jpg" : "png");
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
//String fileName = "IMG_" + timeStamp + (this.encodingType == JPEG ? ".jpg" : ".png");
String modifiedPath = getTempDirectoryPath() + "/" + fileName;
OutputStream os = new FileOutputStream(modifiedPath);
CompressFormat compressFormat = this.encodingType == JPEG ?
CompressFormat.JPEG :
CompressFormat.PNG;
bitmap.compress(compressFormat, this.mQuality, os);
os.close();
if (exifData != null && this.encodingType == JPEG) {
try {
if (this.correctOrientation && this.orientationCorrected) {
exifData.resetOrientation();
}
exifData.createOutFile(modifiedPath);
exifData.writeExifData();
exifData = null;
} catch (IOException e) {
e.printStackTrace();
}
}
return modifiedPath;
}
java类android.graphics.Bitmap.CompressFormat的实例源码
CameraLauncher.java 文件源码
项目:localcloud_fe
阅读 31
收藏 0
点赞 0
评论 0
WXMediaMessage.java 文件源码
项目:boohee_v5.6
阅读 29
收藏 0
点赞 0
评论 0
public final void setThumbImage(Bitmap bitmap) {
try {
OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG, 85, byteArrayOutputStream);
this.thumbData = byteArrayOutputStream.toByteArray();
byteArrayOutputStream.close();
} catch (Throwable e) {
Ln.e(e);
Ln.e("put thumb failed", new Object[0]);
}
}
OnekeyShareThemeImpl.java 文件源码
项目:cniao5
阅读 36
收藏 0
点赞 0
评论 0
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(MobSDK.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);
}
a.java 文件源码
项目:boohee_v5.6
阅读 26
收藏 0
点赞 0
评论 0
private String a(Bitmap bitmap, a aVar) {
try {
File createTempFile = File.createTempFile("bm_tmp", ".png");
OutputStream fileOutputStream = new FileOutputStream(createTempFile);
bitmap.compress(CompressFormat.PNG, 100, fileOutputStream);
fileOutputStream.flush();
fileOutputStream.close();
return a(createTempFile.getAbsolutePath(), aVar);
} catch (Throwable th) {
Ln.e(th);
return null;
}
}
IconsManager.java 文件源码
项目:LaunchEnr
阅读 36
收藏 0
点赞 0
评论 0
private void cacheStoreDrawable(String key, Bitmap bitmap) {
if (isDrawableInCache(key)) return;
File drawableFile = cacheGetFileName(key);
try (FileOutputStream fos = new FileOutputStream(drawableFile)) {
bitmap.compress(CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
MyBitmapUtil.java 文件源码
项目:GCSApp
阅读 27
收藏 0
点赞 0
评论 0
/**
* 把batmap 转file
* @param bitmap
* @param filepath
*/
public static File saveBitmapFile(Bitmap bitmap, String filepath){
File file=new File(filepath);//将要保存图片的路径
try {
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
bitmap.compress(CompressFormat.JPEG, 100, bos);
bos.flush();
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
return file;
}
BaseImageDownloader.java 文件源码
项目:GifImageLoader
阅读 29
收藏 0
点赞 0
评论 0
@TargetApi(Build.VERSION_CODES.FROYO)
private InputStream getVideoThumbnailStream(String filePath) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
Bitmap bitmap = ThumbnailUtils
.createVideoThumbnail(filePath, MediaStore.Images.Thumbnails.FULL_SCREEN_KIND);
if (bitmap != null) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 0, bos);
return new ByteArrayInputStream(bos.toByteArray());
}
}
return null;
}
ImageUtils.java 文件源码
项目:Android-UtilCode
阅读 28
收藏 0
点赞 0
评论 0
/**
* 按质量压缩
*
* @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);
}
ImageUtils.java 文件源码
项目:Android-UtilCode
阅读 36
收藏 0
点赞 0
评论 0
/**
* 按采样大小压缩
*
* @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);
}
ImageUtils.java 文件源码
项目:HeadlineNews
阅读 38
收藏 0
点赞 0
评论 0
/**
* 按质量压缩
*
* @param src 源图片
* @param quality 质量
* @param recycle 是否回收
* @return 质量压缩后的图片
*/
public static Bitmap compressByQuality(final Bitmap src, @IntRange(from = 0, to = 100) final int quality, final boolean recycle) {
if (isEmptyBitmap(src)) return null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
src.compress(CompressFormat.JPEG, quality, baos);
byte[] bytes = baos.toByteArray();
if (recycle && !src.isRecycled()) src.recycle();
return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
}