由于BMP图片太大,imageview控件无法正常显示,所以我想把BMP图片先转换成jpg再进行显示,但由于刚刚接触不甚了解,请大神们帮帮我。。谢谢了bmpandroid图片
解决方案 »
- android tablelayout 设置单元格间距
- 新手求指教
- 跪求android ndk1.6编译libcurl方法
- 热烈祝贺Android板块开业
- android小白的测试程序频频出错
- Paint.setTextSize与TextView.setTextSize传入的单位一致否?
- [color=#FF0000]用过actionbarsherlock的进来看看,关于修改actionbarsherlock标题栏[/color]
- 如何实现单点登录
- 怎么可以监听到系统的闹铃广播,用com.android.alarmclock.ALARM_ALERT怎么收不到
- 请教如何将apk安装 到 system/app下
- 求助 FrameLayout.LayoutParams 隐藏方法
- android 百度地图 初学问题。
转换格式解决不了你的问题你可以用BitmapFactory创建一个缩小的bitmap用ImageView显示
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]
// 获取图片的宽高
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);}
这里应该是图片文件路径这段代码是读取SD卡中文件的
如果是res中的图片文件 需要使用
BitmapFactory.decodeResource(res,id,opt);
方法来代替
BitmapFactory.decodeFile(path,opt);
方法
options.inJustDecodeBounds=false;
options.inSampleSize=1;
Bitmap bitmap=BitmapFactory.decodeStream(is, null, options);
chlmapImageView.setImageBitmap(bitmap);显示出来了,有区别么?要是我只想显示一部分,比如以图上某点为中心来显示呢?