Android中缩列图的使用
来源:互联网 发布:java时间排序函数 编辑:程序博客网 时间:2024/06/05 10:12
import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageView;
public class MainActivity extends Activity {
private ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView) findViewById(R.id.imageView);
imageView.setImageBitmap(decodeBitmap(getResources(), R.drawable.a, 50,
50));
}
// 得到缩放比
public int getSampleSize(BitmapFactory.Options options, int requestWidth,
int requestHeight) {
// 原图片的宽高
int width = options.outWidth;
int height = options.outHeight;
int sampleSize = 1;
if (width > requestWidth || height > requestHeight) {
if (width > height) {
sampleSize = Math.round((float) height / (float) (requestHeight)) ;
} else {
sampleSize = Math.round((float) width / (float) (requestWidth));
}
}
}
return sampleSize;
}
public Bitmap decodeBitmap(Resources res, int resid, int requestWidth,
int requestHeight) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, resid, options);
options.inSampleSize = getSampleSize(options, requestWidth,
requestHeight);
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res, resid, options);
}
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageView;
public class MainActivity extends Activity {
private ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView) findViewById(R.id.imageView);
imageView.setImageBitmap(decodeBitmap(getResources(), R.drawable.a, 50,
50));
}
// 得到缩放比
public int getSampleSize(BitmapFactory.Options options, int requestWidth,
int requestHeight) {
// 原图片的宽高
int width = options.outWidth;
int height = options.outHeight;
int sampleSize = 1;
if (width > requestWidth || height > requestHeight) {
if (width > height) {
sampleSize = Math.round((float) height / (float) (requestHeight)) ;
} else {
sampleSize = Math.round((float) width / (float) (requestWidth));
}
}
}
return sampleSize;
}
public Bitmap decodeBitmap(Resources res, int resid, int requestWidth,
int requestHeight) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, resid, options);
options.inSampleSize = getSampleSize(options, requestWidth,
requestHeight);
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res, resid, options);
}
}
布局文件仅包含一个ImageView,在此不再列出。
0 0
- Android中缩列图的使用
- 【Android】Android对话框的使用
- 【Android】android Fragment的使用
- Android TabHost的使用
- Android Logcat的使用
- Android ArrayAdapter的使用
- android ndk的使用
- android keystore的使用
- Android PopupWindow的使用
- Android PopupWindow的使用
- Android-Notification的使用
- Android TabHost的使用
- Android GridView的使用
- Android Menu的使用
- Android的SDcard使用
- android ListView的使用
- Android WebView的使用
- Android ProgressDialog的使用
- Cocoapods安装步骤整理
- java 查找目录下指定文件名的文件
- Android: .java文件转.dex和java字节码
- iOS使用UIMenuController调用系统自带的复制、粘贴、剪切
- ListView图片加载缓慢、局部更新失败等问题你遇到了吗?
- Android中缩列图的使用
- centOS下制作RPM包
- BootStrap--CSS布局--表单
- bash之shopt
- CCF 201409_4 最优配餐 讲解
- 表单POST请求服务器,通过多条件查询获取数据库数据
- 编程的乐趣
- Android开发-自定义View-AndroidStudio(三)扇形多级菜单
- Ubuntu 16.04安装 openssh-server问题