當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。