从 int 数组中检索可绘制对象
Retrieve drawables from an int array
有没有办法从包含可绘制图像列表的 int 数组中获取可绘制 ID?这是我存储它们的方式:
Integer[] imageIDs = {
R.drawable.tssr_1,
R.drawable.tssr_2,
R.drawable.tssr_3,
R.drawable.tssr_4,
R.drawable.tssr_5,
R.drawable.tssr_6
};
这是我需要的地方:
Drawable d = imageIDs[0]; // Type mismatch: cannot convert from Integer to Drawable
Bitmap bitmap = ((BitmapDrawable)d).getBitmap();
您应该将可绘制资源整数 ID 转换为可绘制对象
Drawable d = getResources().getDrawable(imagesIDs[0]);
详情请点击这里Resources|Android Developer
如果您的目的是将可绘制资源 ID 转换为位图:
Bitmap bm = BitmapFactory.decodeResource(mContext.getResources(),
imageIDs[index]);
有没有办法从包含可绘制图像列表的 int 数组中获取可绘制 ID?这是我存储它们的方式:
Integer[] imageIDs = {
R.drawable.tssr_1,
R.drawable.tssr_2,
R.drawable.tssr_3,
R.drawable.tssr_4,
R.drawable.tssr_5,
R.drawable.tssr_6
};
这是我需要的地方:
Drawable d = imageIDs[0]; // Type mismatch: cannot convert from Integer to Drawable
Bitmap bitmap = ((BitmapDrawable)d).getBitmap();
您应该将可绘制资源整数 ID 转换为可绘制对象
Drawable d = getResources().getDrawable(imagesIDs[0]);
详情请点击这里Resources|Android Developer
如果您的目的是将可绘制资源 ID 转换为位图:
Bitmap bm = BitmapFactory.decodeResource(mContext.getResources(),
imageIDs[index]);