您好我想从设备获取图像并在网格视图中显示它,当我将i更改为3时,它向我显示位置为3的图像五次:
this.renderContent = function() {
if (this.retrievedNewsArticles == null || this.retrievedNewsArticles.length == 0) {
$(contentContainerElement).html('<p class="inline-message">There is currently no data to display.</p>');
} else {
// The loop is here
for (var i = 0; i < this.retrievedNewsArticles.length; i++) {
this.addUnit(this.retrievedNewsArticles[i]);
}
}
};
谢谢!!
答案 0 :(得分:0)
我发现这里的答案是代码: 首先我添加了新功能:
public static Bitmap decodeFile(File f,int WIDTH,int HIGHT){
try {
//Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(new FileInputStream(f),null,o);
//The new size we want to scale to
final int REQUIRED_WIDTH=WIDTH;
final int REQUIRED_HIGHT=HIGHT;
//Find the correct scale value. It should be the power of 2.
int scale=1;
while(o.outWidth/scale/2>=REQUIRED_WIDTH && o.outHeight/scale/2>=REQUIRED_HIGHT)
scale*=2;
//Decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize=scale;
return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
} catch (FileNotFoundException e) {}
return null;
}
并在获取视图中更改
Bitmap b = BitmapFactory.decodeStream(new FileInputStream(file[i]));
使用此代码:Bitmap bitmap = decodeFile(file[i],180,250);
imageView.setImageBitmap(bitmap);