读书人

android:当地图片转换为位图

发布时间: 2012-07-20 10:38:30 作者: rapoo

android:本地图片转换为位图

    /**     * 将本地图片转换为位图     *      * @param pathName 图片本地路径名,如"/mnt/sdcart/a.jpg"     * @param rate 大小比率,如rate=10,则生成位图的width,hight为原图的十分之一     * @return 位图实例     * @throws FileNotFoundException     */    public static Bitmap getBitmapByPath(String pathName, int rate) throws FileNotFoundException {    //读取文件到输入流    FileInputStream fis = new FileInputStream(pathName);        BitmapFactory.Options options = new BitmapFactory.Options();        options.inJustDecodeBounds = false;        options.inSampleSize = rate;    //使用位图工厂类将包含图片信息的输入流转换成位图    return BitmapFactory.decodeStream(fis, null, options);    }

读书人网 >Android

热点推荐