我有自定义列表视图like this。在我的应用程序中,我可以打开相机并将照片捕捉到SD卡上。我想在小图像视图中显示捕获的照片。但我成了以下消息:位图太大而无法上传到纹理(2448x3264,max = 2048x204) 如何在imageview中显示这样的图像,例如布局宽度/高度为90x90dip和50X50dip?
提前致谢
编辑1:
cursor = myDBHandler.getAllDifferentNames1();
String[] dbColm = new String[] {"n", "d", "p"};
int[] toList = new int[] {R.id.txt_name, R.id.date, R.id.list_userImage};
SimpleCursorAdapter myCursorAdapter
= new SimpleCursorAdapter
(this, R.layout.listrow, cursor, dbColm , toList );
mainList.setAdapter(myCursorAdapter);
答案 0 :(得分:2)
您可以使用 Bitmap.createScaledBitmap()缩放图像。我在这里给你一个程序......跟着这个......我想你会摆脱你的问题。
private Bitmap scaleImage(Bitmap bitmap) {
//required image width and height
int reqImageWidth = 90; //as you mentioned
int reqImageHeight = 90; //as you mentioned
/*Different device has different display density. If you want to show your
* image with same layout_width and layout_height then you should multiply
*something with yourrequired width and height to bring your image in balance.*/
float multiplier = getMultiplierFromDeviceDensity();
Bitmap.createScaledBitmap( bitmap, (int) (reqImageWidth * multiplier),
(int) (reqImageHeight * multiplier), false);
}
private float getMultiplierFromDeviceDensity() {
int d = mContext.getResources().getDisplayMetrics().densityDpi;
float multiplier = 0f;
switch (d) {
case DisplayMetrics.DENSITY_LOW:
multiplier = 0.8f;
break;
case DisplayMetrics.DENSITY_MEDIUM:
multiplier = 1.0f;
break;
case DisplayMetrics.DENSITY_HIGH:
multiplier = 1.2f;
break;
case DisplayMetrics.DENSITY_XHIGH:
multiplier = 1.5f;
break;
case DisplayMetrics.DENSITY_XXHIGH:
multiplier = 2.0f;
break;
}
return multiplier;
}