【问题标题】:Resolution of jpg filejpg文件的分辨率
【发布时间】:2012-07-26 08:22:48
【问题描述】:

我有一个类,在构造函数中我得到一个文件。这个文件是jpeg。如何在此类中获取此 jpeg 文件的分辨率? 这是构造函数的一些代码:

public static Bitmap bitmapSizer(File file) {

        BitmapFactory.Options options = new BitmapFactory.Options();
        Bitmap bitmap = null;

        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(file.getAbsolutePath(), options);

        int imageHeight = options.outHeight;
        int imageWidth = options.outWidth;
        options.inDither = true;
        options.inPreferredConfig = Bitmap.Config.ARGB_4444;
        options.inPurgeable = true;
        options.inSampleSize=8;         
        options.inJustDecodeBounds = false;

【问题讨论】:

    标签: android bitmap jpeg bitmapfactory


    【解决方案1】:

    您需要移动几行代码。
    首先,获取Options 对象:

        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inDither = true;
        options.inPreferredConfig = Bitmap.Config.ARGB_4444;
        options.inPurgeable = true;
        options.inSampleSize=8;         
        options.inJustDecodeBounds = true;
    

    注意options.inJustDecodeBounds =true 这只会读取 jpg 的标题,而不是整个图像。
    接下来,解码您的文件:

        Bitmap bitmap = null;
        BitmapFactory.decodeFile(file.getAbsolutePath(), options);
    

    解码后你会得到结果:

        int imageHeight = options.outHeight;
        int imageWidth = options.outWidth;
    

    【讨论】:

      猜你喜欢
      • 2014-03-23
      • 2018-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多