本文整理汇总了Java中android.graphics.Bitmap.CompressFormat.PNG属性的典型用法代码示例。如果您正苦于以下问题:Java CompressFormat.PNG属性的具体用法?Java CompressFormat.PNG怎么用?Java CompressFormat.PNG使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.graphics.Bitmap.CompressFormat
的用法示例。
在下文中一共展示了CompressFormat.PNG属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: a
private Bitmap a(Context context, String str) {
File file = new File(str);
if (file.exists()) {
CompressFormat bmpFormat = BitmapHelper.getBmpFormat(str);
int dipToPx = R.dipToPx(context, 120);
if (CompressFormat.PNG == bmpFormat) {
dipToPx = R.dipToPx(context, 90);
}
Bitmap decodeFile = BitmapFactory.decodeFile(str, new Options());
if (file.length() > this.b) {
Bitmap bitmap = decodeFile;
while (dipToPx > 40 && a(bitmap, bmpFormat) > 32768) {
int i = dipToPx - 5;
int width = bitmap.getWidth();
int height = bitmap.getHeight();
double d = (height > i || width > i) ? height > width ? ((double) i) / ((double) height) : ((double) i) / ((double) width) : PathListView.NO_ZOOM;
bitmap = Bitmap.createScaledBitmap(bitmap, (int) (((double) width) * d), (int) (d * ((double) height)), true);
dipToPx = i;
}
OutputStream fileOutputStream = new FileOutputStream(File.createTempFile("sina_bm_tmp", "." + bmpFormat.name().toLowerCase()));
bitmap.compress(bmpFormat, 100, fileOutputStream);
fileOutputStream.flush();
fileOutputStream.close();
return bitmap;
}
Ln.i("sina weibo decode bitmap size ==>>" + a(decodeFile, bmpFormat), new Object[0]);
return decodeFile;
}
throw new FileNotFoundException();
}
示例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: 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;
}
示例5: getCompressFormat
private static CompressFormat getCompressFormat(String filePath){
CompressFormat compressFormat = CompressFormat.JPEG;
String type = BitmapUtil.getSimpleMimeType(filePath);
if (!TextUtils.isEmpty(type) && type.indexOf("png") != -1){
compressFormat = CompressFormat.PNG;
}
return compressFormat;
}
示例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;
}
示例8: saveBitmap
public static String saveBitmap(Context context, Bitmap bitmap, CompressFormat
compressFormat, int i) throws Throwable {
String cachePath = R.getCachePath(context, SDcard.IMAGES_DIR);
String str = ".jpg";
if (compressFormat == CompressFormat.PNG) {
str = ".png";
}
File file = new File(cachePath, String.valueOf(System.currentTimeMillis()) + str);
OutputStream fileOutputStream = new FileOutputStream(file);
bitmap.compress(compressFormat, i, fileOutputStream);
fileOutputStream.flush();
fileOutputStream.close();
return file.getAbsolutePath();
}
示例9: getImageType
/**
* 判断原始图片格式
* @param data 图片url地址
* @return jpg/png
*/
public CompressFormat getImageType(String data){
CompressFormat type = CompressFormat.PNG;
return type;
}