美文网首页
android图片压缩

android图片压缩

作者: Android技术研究 | 来源:发表于2016-02-24 20:37 被阅读415次

1、根据图片宽、高压缩图片

public static Bitmap getBitmap(String filePath) {

final BitmapFactory.Options options =new BitmapFactory.Options();

options.inJustDecodeBounds=true;

BitmapFactory.decodeFile(filePath, options);

// Calculate inSampleSize

options.inSampleSize=calculateInSampleSize1(options, 480, 800);

// Decode bitmap with inSampleSize set

options.inJustDecodeBounds=false;

return BitmapFactory.decodeFile(filePath, options);

}

public static int calculateInSampleSize(BitmapFactory.Options options,

int reqWidth,int reqHeight) {

final int height = options.outHeight;

final int width = options.outWidth;

int inSampleSize = 1;

if (height > reqHeight || width > reqWidth) {

final int heightRatio = Math.round((float) height

/ (float) reqHeight);

final int widthRatio = Math.round((float) width / (float) reqWidth);

inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;

}

return inSampleSize;

}

2、压缩Bitmap质量

public static byte[] Bitmap2Bytes(Bitmap bm)

{

ByteArrayOutputStream baos =new ByteArrayOutputStream();

bm.compress(Bitmap.CompressFormat.JPEG, 80, baos);

return baos.toByteArray();

}

相关文章

  • 图片压缩

    Android应用开发中三种常见的图片压缩方法,分别是:质量压缩法、比例压缩法(根据路径获取图片并压缩)和比例压缩...

  • Android:图片压缩的几种方式

    1、前言 在Android中,图片的压缩对于内存的优化很重要 通过这篇文章对Android中的几种图片压缩方式进行...

  • 图片压缩

    Android图片压缩常用的有质量压缩、尺寸压缩、采样率压缩以及通过JNI调用libjpeg库来进行压缩(尺寸压缩...

  • 【Android开发基础系列】图片专题

    1 图片编辑处理 1.1 图片裁切 转载自:bitmap的六种压缩方式,Android图片压缩 http://bl...

  • 资源图片优化

    tinypng 在线图片压缩 webP android studio选中图片右键Convert to webP

  • Android

    Android常用图片压缩方式 质量压缩 尺寸压缩 1. 质量压缩 质量压缩通过相应算法进行优化Bitmap的位深...

  • bitmap的六种压缩方式,Android图片压缩

    此处分享一个图片的压缩处理方式 : bitmap的六种压缩方式,Android图片压缩 转载链接,点击查看详情 !

  • Android图片压缩

    1.采样率压缩 采样率压缩是改变了图片的像素,他是通过先读取图片的边,然后在自己设定图片的边,然后根据设定,读取图...

  • android图片压缩

    质量压缩 尺寸压缩 缩放法压缩(matrix) RGB_565法(比ARGB_888少一半) createScal...

  • Android图片压缩

    首先,需要注意的是图片在内存中的大小是根据分辨率来决定的,即height*width BitmapFactory这...

网友评论

      本文标题:android图片压缩

      本文链接:https://www.haomeiwen.com/subject/oteikttx.html