如何扩展位图的屏幕尺寸? [英] How to scale bitmap to screen size?

查看:110
本文介绍了如何扩展位图的屏幕尺寸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何扩展位图到屏幕的高度和宽度?

I want to know how to scale bitmap to screen height and width?

任何人都可以请告诉我如何做到这一点。

Can anyone pls tell me how to do this.

谢谢 Monali

推荐答案

试试这个以德$ C C位图$:

Try this to Decode the Bitmap :

其中imagefilepath是图像的路径名,它会在字符串隐蔽,通过使用到文件

Where imagefilepath is the path name of image,it will be in String covert that to File by using

File photos= new File(imageFilePath);

其中照片与图片的文件名,现在您可以根据t在要求设置你的高度和宽度。

Where photo is the File name of the Image,Now you set your height and width according t your requirements.

                Bitmap bitmap = decodeFile(photo);
                bitmap = Bitmap.createScaledBitmap(bitmap,150, 150, true);
                imageView.setImageBitmap(bitmap);

        private Bitmap decodeFile(File f){
        try {
            //decode image size
            BitmapFactory.Options o = new BitmapFactory.Options();
            o.inJustDecodeBounds = true;
            BitmapFactory.decodeStream(new FileInputStream(f),null,o);              
            //Find the correct scale value. It should be the power of 2.
            final int REQUIRED_SIZE=70;
            int width_tmp=o.outWidth, height_tmp=o.outHeight;
            int scale=1;
            while(true){
                if(width_tmp/2<REQUIRED_SIZE || height_tmp/2<REQUIRED_SIZE)
                    break;
                width_tmp/=2;
                height_tmp/=2;
                scale++;
            }

            //decode with inSampleSize
            BitmapFactory.Options o2 = new BitmapFactory.Options();
            o2.inSampleSize=scale;
            return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
        } catch (FileNotFoundException e) {}
        return null;
    }

这篇关于如何扩展位图的屏幕尺寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆