由于BMP图片太大,imageview控件无法正常显示,所以我想把BMP图片先转换成jpg再进行显示,但由于刚刚接触不甚了解,请大神们帮帮我。。谢谢了bmpandroid图片

解决方案 »

  1.   

    无论你的图片是什么格式 只要尺寸相同设置相同 在内存里都占同样的大小啊
    转换格式解决不了你的问题你可以用BitmapFactory创建一个缩小的bitmap用ImageView显示
      

  2.   

    [code=java        // 获取图片的宽高
            BitmapFactory.Options opt = new BitmapFactory.Options();
            opt.inJustDecodeBounds = true;
            try{
                bitmapIn = BitmapFactory.decodeFile(Puzzle.user.CUSTOM_IMAGE[customImage], opt);
            }catch(Exception e){
                if(D) Log.d(TAG,"error");
                return;
            }
            int in_w=opt.outWidth,in_h=opt.outHeight;
            
            // 获取imageview的尺寸 注意imageview的宽高比要与原图相同 否则需要另行计算
            full_w = imageview.getWidth()
            full_h = getHeight()        // 计算缩放比例 带有四舍五入
            int Size_rate=(in_w*in_h*10)/(full_w*full_h);
            if(Size_rate>10){
                Size_rate+=5; 
                Size_rate/=10;
            }else{
                Size_rate=1;
            }        // 重新设置opt 读取图片文件
            opt.inSampleSize=Size_rate;
            opt.inJustDecodeBounds = false;
            opt.inScaled = false;        opt.outWidth=full_w;
            opt.outHeight=full_h;
            bitmapIn = BitmapFactory.decodeFile(Puzzle.user.CUSTOM_IMAGE[customImage], opt);}[/code]
      

  3.   

    发崩了 重发
            // 获取图片的宽高
            BitmapFactory.Options opt = new BitmapFactory.Options();
            opt.inJustDecodeBounds = true;
            try{
                bitmapIn = BitmapFactory.decodeFile(Puzzle.user.CUSTOM_IMAGE[customImage], opt);
            }catch(Exception e){
                if(D) Log.d(TAG,"error");
                return;
            }
            int in_w=opt.outWidth,in_h=opt.outHeight;
            
            // 获取imageview的尺寸 注意imageview的宽高比要与原图相同 否则需要另行计算
            full_w = imageview.getWidth()
            full_h = getHeight()        // 计算缩放比例 带有四舍五入
            int Size_rate=(in_w*in_h*10)/(full_w*full_h);
            if(Size_rate>10){
                Size_rate+=5; 
                Size_rate/=10;
            }else{
                Size_rate=1;
            }        // 重新设置opt 读取图片文件
            opt.inSampleSize=Size_rate;
            opt.inJustDecodeBounds = false;
            opt.inScaled = false;        opt.outWidth=full_w;
            opt.outHeight=full_h;
            bitmapIn = BitmapFactory.decodeFile(Puzzle.user.CUSTOM_IMAGE[customImage], opt);}
      

  4.   

    Puzzle.user.CUSTOM_IMAGE[customImage]
    这里应该是图片文件路径这段代码是读取SD卡中文件的
    如果是res中的图片文件 需要使用
    BitmapFactory.decodeResource(res,id,opt);
    方法来代替
    BitmapFactory.decodeFile(path,opt);
    方法
      

  5.   

    我试过了,不过图片显示不出来,反而我直接BitmapFactory.Options options=new BitmapFactory.Options();
    options.inJustDecodeBounds=false;
    options.inSampleSize=1;
    Bitmap bitmap=BitmapFactory.decodeStream(is, null, options);
    chlmapImageView.setImageBitmap(bitmap);显示出来了,有区别么?要是我只想显示一部分,比如以图上某点为中心来显示呢?