当前位置: 首页>>代码示例>>Java>>正文


Java CompressFormat.PNG属性代码示例

本文整理汇总了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();
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:30,代码来源:SinaActivity.java

示例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;
}
 
开发者ID:SUTFutureCoder,项目名称:localcloud_fe,代码行数:26,代码来源:CameraLauncher.java

示例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();
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:20,代码来源:BitmapProcessor.java

示例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;
}
 
开发者ID:Andy-Ta,项目名称:COB,代码行数:35,代码来源:CameraLauncher.java

示例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;
}
 
开发者ID:PlutoArchitecture,项目名称:Pluto-Android,代码行数:8,代码来源:BitmapUtil.java

示例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;
}
 
开发者ID:Evan-Galvin,项目名称:FreeStreams-TVLauncher,代码行数:15,代码来源:ImageDiskLruCache.java

示例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;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:13,代码来源:BitmapHelper.java

示例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();
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:14,代码来源:BitmapHelper.java

示例9: getImageType

/**
 * 判断原始图片格式
 * @param data  图片url地址
 * @return jpg/png
 */
public CompressFormat getImageType(String data){
    CompressFormat type = CompressFormat.PNG;
    return type;
}
 
开发者ID:PlutoArchitecture,项目名称:Pluto-Android,代码行数:9,代码来源:BitmapCache.java


注:本文中的android.graphics.Bitmap.CompressFormat.PNG属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。