如何将 imageview 数组传递给以下代码。代码是它从数组中获取所有图像调整大小并将其放入linearlayout
. 目前,我的代码一次只拍摄 1 张图像。
图像视图数组:
private Integer[] Imgid = {
R.drawable.pic1,
R.drawable.pic2,
R.drawable.pic3,
};
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),
Imgid[5]); // currently taking only 1 image
int width = bitmapOrg.getWidth();
int height = bitmapOrg.getHeight();
int newWidth = 200;
int newHeight = 200;
// calculate the scale - in this case = 0.4f
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// createa matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleWidth, scaleHeight);
// rotate the Bitmap
matrix.postRotate(0);
// recreate the new Bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0,
width, height, matrix, true);
// make a Drawable from Bitmap to allow to set the BitMap
// to the ImageView, ImageButton or what ever
BitmapDrawable bmd = new BitmapDrawable(getResources(),resizedBitmap);
LinearLayout linearLayout1 = (LinearLayout) findViewById(R.id.Linear);
for(int x=0;x<25;x++) {
ImageView imageView = new ImageView(this);
imageView.setPadding(2, 0, 9, 5);
imageView.setImageDrawable(bmd);
linearLayout1.addView(imageView);
}