本文整理汇总了Java中android.graphics.Bitmap.CompressFormat.JPEG属性的典型用法代码示例。如果您正苦于以下问题:Java CompressFormat.JPEG属性的具体用法?Java CompressFormat.JPEG怎么用?Java CompressFormat.JPEG使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.graphics.Bitmap.CompressFormat
的用法示例。
在下文中一共展示了CompressFormat.JPEG属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getScaledImageFileWithMD5
public static File getScaledImageFileWithMD5(File imageFile, String mimeType) {
String filePath = imageFile.getPath();
if (!isInvalidPictureFile(mimeType)) {
return null;
}
String tempFilePath = getTempFilePath(FileUtil.getExtensionName(filePath));
File tempImageFile = AttachmentStore.create(tempFilePath);
if (tempImageFile == null) {
return null;
}
CompressFormat compressFormat = CompressFormat.JPEG;
// 压缩数值由第三方开发者自行决定
int maxWidth = 720;
int quality = 60;
if (ImageUtil.scaleImage(imageFile, tempImageFile, maxWidth, compressFormat, quality)) {
return tempImageFile;
} else {
return null;
}
}
示例2: processPicture
/**
* Compress bitmap using jpeg, convert to Base64 encoded string, and return to JavaScript.
*
* @param bitmap
*/
public void processPicture(Bitmap bitmap, int encodingType) {
ByteArrayOutputStream jpeg_data = new ByteArrayOutputStream();
CompressFormat compressFormat = encodingType == JPEG ?
CompressFormat.JPEG :
CompressFormat.PNG;
try {
if (bitmap.compress(compressFormat, mQuality, jpeg_data)) {
byte[] code = jpeg_data.toByteArray();
byte[] output = Base64.encode(code, Base64.NO_WRAP);
String js_out = new String(output);
this.callbackContext.success(js_out);
js_out = null;
output = null;
code = null;
}
} catch (Exception e) {
this.failPicture("Error compressing image.");
}
jpeg_data = null;
}
示例3: saveFile
private void saveFile(Bitmap bitmap, File file, boolean z) {
try {
if (file.exists()) {
file.delete();
}
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
file.createNewFile();
CompressFormat compressFormat = z ? CompressFormat.PNG : CompressFormat.JPEG;
OutputStream fileOutputStream = new FileOutputStream(file);
bitmap.compress(compressFormat, 100, fileOutputStream);
fileOutputStream.flush();
fileOutputStream.close();
} catch (Throwable th) {
if (file.exists()) {
file.delete();
}
}
}
示例4: getScaledImageFileWithMD5
public static File getScaledImageFileWithMD5(File imageFile, String mimeType) {
String filePath = imageFile.getPath();
if (!isInvalidPictureFile(mimeType)) {
LogUtil.i("ImageUtil", "is invalid picture file");
return null;
}
String tempFilePath = getTempFilePath(FileUtil.getExtensionName(filePath));
File tempImageFile = AttachmentStore.create(tempFilePath);
if (tempImageFile == null) {
return null;
}
CompressFormat compressFormat = CompressFormat.JPEG;
// 压缩数值由第三方开发者自行决定
int maxWidth = 720;
int quality = 60;
if (ImageUtil.scaleImage(imageFile, tempImageFile, maxWidth, compressFormat, quality)) {
return tempImageFile;
} else {
return null;
}
}
示例5: outputModifiedBitmap
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;
}
示例6: getCompressFormat
/**
* 根据文件类型获得CompressFormat.
*
* @Description:
* @Date 2014-3-7
*/
private CompressFormat getCompressFormat(String url) {
String lowerUrl = url.toLowerCase(Locale.ENGLISH);
if (lowerUrl.endsWith(".jpg")) {
return CompressFormat.JPEG;
} else if (lowerUrl.endsWith(".png")) {
return CompressFormat.PNG;
}
return CompressFormat.JPEG;
}
示例7: getBmpFormat
public static CompressFormat getBmpFormat(String str) {
String toLowerCase = str.toLowerCase();
if (toLowerCase.endsWith("png") || toLowerCase.endsWith("gif")) {
return CompressFormat.PNG;
}
if (toLowerCase.endsWith("jpg") || toLowerCase.endsWith("jpeg") || toLowerCase.endsWith
("bmp") || toLowerCase.endsWith("tif")) {
return CompressFormat.JPEG;
}
toLowerCase = getMime(str);
return (toLowerCase.endsWith("png") || toLowerCase.endsWith("gif")) ? CompressFormat.PNG
: CompressFormat.JPEG;
}