开发者社区> 问答> 正文

怎样保存一个图像连同它的thuml然后显示在imageView中

我想保存一个从相机拍摄的照片,然后把照片和 Thumb 保存在 sdCard 中,然后把它们显示在一个 imageView 中。后来给出空指针错误。
imageBitmap = Bitmap.createScaledBitmap(imageBitmap, 40, 40, false);
哪里出错了?
screenshot
screenshot
screenshot

展开
收起
蛮大人123 2016-02-18 10:17:31 2507 0
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪
    public static Bitmap getSmallBitmap(String filePath) {
        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(filePath, options);
    
        // Calculate inSampleSize
        options.inSampleSize = 2;
    
        // Decode bitmap with inSampleSize set
        options.inJustDecodeBounds = false;
    
        Bitmap bm = BitmapFactory.decodeFile(filePath, options);
        if(bm == null){
            return  null;
        }
        ByteArrayOutputStream baos = null ;
        try{
            baos = new ByteArrayOutputStream();
            bm.compress(Bitmap.CompressFormat.JPEG, 100, baos);
        }finally{
            try {
                if(baos != null)
                    baos.close() ;
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return bm ;
    
    }
    

    这样可以从文件中得到图片。

    Intent mediaScanIntent = new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE");
                File f = new File(mCurrentPhotoPath);
                Uri contentUri = Uri.fromFile(f);
                mediaScanIntent.setData(contentUri);
                this.sendBroadcast(mediaScanIntent);

    上面的code可以把图片保存到图片库中

    2019-07-17 18:43:45
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载