小弟是新手中的新手啊,这个问题给个思路或代码也行。就是android手机客户端读取网站一编新闻的文章 ,文章中的不定个数的图片,但这些图片会比较大,怎么在android手机客户端把所有图片压缩后再显示文章所有内容呢(包括图片和文字)Android手机图片压缩
解决方案 »
- java模拟c#中的委托时的反射调用方法问题
- 不科学啊!Canvas使用了矩阵变换后使用drawVertices,保存的view还是原图而不是变换后的图,等好人ing.....
- 关于android客户端与服务器端交互的问题
- 关于URLConnection.setUseCaches(true);
- 学习ApiDemo的参考资料
- ndk引用第三方库错误
- 怎么设置才能让平板连上电脑后 电脑能浏览平板上所有文件
- error: 'jstringToString' was not declared in this scope
- android能调用wcf吗?怎么调用?
- android listview中checkbox控制点击数目。
- android UI控件位置摆放
- ImageButton按钮双向点击效果的实现
如果说图片比较大,是指的是图片尺寸问题,那就修改图片的尺寸咯。给一段参考代码:private Bitmap decodeFile(File file) {
try {
BitmapFactory.Options op = new BitmapFactory.Options();
op.inJustDecodeBounds = true;
BitmapFactory.decodeStream(new FileInputStream(file), null, op); // Find the correct scale value. It should be the power of 2.
final int REQUIRED_SIZE = 70;
int width_tmp = op.outWidth;
int height_tmp = op.outHeight;
int scale = 1;
while (true) {
if (width_tmp / 2 < REQUIRED_SIZE
|| height_tmp / 2 < REQUIRED_SIZE)
break;
width_tmp /= 2;
height_tmp /= 2;
scale *= 2;
} BitmapFactory.Options op2 = new BitmapFactory.Options();
op2.inSampleSize = scale;
return BitmapFactory.decodeStream(new FileInputStream(file), null,
op2); } catch (Exception e) {
e.printStackTrace();
} catch (OutOfMemoryError oom) {
oom.printStackTrace();
}
return null;
}
上面代码中的op2.inSampleSize = scale;就是在调整采样率,以减少内存使用。
当然,也可以通过上面代码的BitmapFactory.Options中的outWidth和outHeight来对尺寸就行修改。