关于如何从图像或视频图像中获取位图?

时间:2014-04-29 08:24:52

标签: android android-bitmap

我是一个新的android我正在研究图像位图, 如果我遗失的话,请添加一些信息..

我的学习! 1.从已经是图像的文件解码位图时,

String pathName = Environment.getExternalStorageDirectory()
                + "/download/" + "ZG4T5vzQSPQ.png";
imgView.setImageBitmap(decodeSampledBitmap(pathName, 100, 120));
public static Bitmap decodeSampledBitmap(String pathName, int reqWidth,
            int reqHeight) {

        // First decode with inJustDecodeBounds=true to check dimensions
        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(pathName, options);

        // Calculate inSampleSize
        options.inSampleSize = calculateInSampleSize(options, reqWidth,
                reqHeight);

        // Decode bitmap with inSampleSize set
        options.inJustDecodeBounds = false;
        return BitmapFactory.decodeFile(pathName, options);
    }

    public static int calculateInSampleSize(BitmapFactory.Options options,
            int reqWidth, int reqHeight) {
        android.util.Log.d("calculateInSampleSize()", "H:" + options.outHeight
                + " W:" + options.outWidth);
        // Raw height and width of image
        final int height = options.outHeight;
        final int width = options.outWidth;
        int inSampleSize = 1;

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

            final int halfHeight = height / 2;
            final int halfWidth = width / 2;

            // Calculate the largest inSampleSize value that is a power of 2 and
            // keeps both
            // height and width larger than the requested height and width.
            while ((halfHeight / inSampleSize) > reqHeight
                    && (halfWidth / inSampleSize) > reqWidth) {
                inSampleSize *= 2; // 1 = 1 * 2
            }
        }
        android.util.Log.d("calculateInSampleSize()", "inSampleSize:"
                + inSampleSize);
        return inSampleSize;
    }

如果要将图像解码为位图,则需要单个路径 如果你想解码一个视频并获得它的videoThumbnail,为什么没有单一的路径 足够?你需要像这样创建一个videoThumbnail!

Bitmap bmp = ThumbnailUtils.createVideoThumbnail(pathName,
                MediaStore.Images.Thumbnails.MINI_KIND);

0 个答案:

没有答案