Android实现bmp图片转换成jpg 由于BMP图片太大,imageview控件无法正常显示,所以我想把BMP图片先转换成jpg再进行显示,但由于刚刚接触不甚了解,请大神们帮帮我。。谢谢了bmpandroid图片 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 无论你的图片是什么格式 只要尺寸相同设置相同 在内存里都占同样的大小啊转换格式解决不了你的问题你可以用BitmapFactory创建一个缩小的bitmap用ImageView显示 [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] 发崩了 重发 // 获取图片的宽高 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);} Puzzle.user.CUSTOM_IMAGE[customImage]这里应该是图片文件路径这段代码是读取SD卡中文件的如果是res中的图片文件 需要使用BitmapFactory.decodeResource(res,id,opt);方法来代替BitmapFactory.decodeFile(path,opt);方法 我试过了,不过图片显示不出来,反而我直接BitmapFactory.Options options=new BitmapFactory.Options(); options.inJustDecodeBounds=false; options.inSampleSize=1; Bitmap bitmap=BitmapFactory.decodeStream(is, null, options); chlmapImageView.setImageBitmap(bitmap);显示出来了,有区别么?要是我只想显示一部分,比如以图上某点为中心来显示呢? android消息推送(使用xmpp协议)的一些问题 调用手机自带地图软件定位的问题 分享:Android从入门到精通系列资料~~~持续更新中 ~~~ 大家来说说android各版本硬件配置要求~~~~ 布局文件问题:布局文件eclipse插件显示正常,模拟器中显示不正常 安卓与远程数据的传送 关于Android L最小的sdk版本是什么 Html Input标签date类型 无法弹出日期选择框问题 onTouch事件错误 Android无法使用jsoup 求助 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);显示出来了,有区别么?要是我只想显示一部分,比如以图上某点为中心来显示呢?