我有显示位图的问题,我的原始图像640 * 960但是当我在位图中显示时,尺寸变为120 * 240,我如何以原始尺寸显示?
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 8;
Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), Imgid[(int)(Math.random()*Imgid.length)], options);
ImageView iv = (ImageView)findViewById(position)
iv.setImageBitmap(processingBitmap_Brightness(bitmap));
我记录了bitmap.getwidth()和getheight()但没有640 * 960
现在我可以使用此代码获得原始大小,但现在给我outofmemory,所以我可以处理图像?
BitmapFactory.Options options = new BitmapFactory.Options();
//options.inSampleSize = 4;
options.inScaled = false;
ImageView iv = (ImageView)findViewById(position);
bitmap=BitmapFactory.decodeResource(getResources(), Imgid[(int)(Math.random()*Imgid.length)],options);
iv.setImageBitmap(processingBitmap_Brightness(bitmap));
Log.i("ID4",bitmap.getWidth()+" * "+bitmap.getHeight());
我在xml中使用了viewflipper并在代码中调用它,并在viewflipper中使用addview
for (i = 0; i<5;i++) {
FrameLayout a = new FrameLayout(this);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.FILL_PARENT,Gravity.CENTER);
a.setLayoutParams(lp);
b = new ImageView(this);
FrameLayout.LayoutParams lpiv = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT,Gravity.CENTER);
b.setId(i+1);
b.setLayoutParams(lpiv);
a.addView(b);
vf.addView(a);
}
我的onFling功能
public boolean onFling(MotionEvent e1,MotionEvent e2,float velocityX,float velocityY){
try {
if(e1.getX() > e2.getX() && Math.abs(e1.getX() - e2.getX()) > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
vf.setInAnimation(AnimationUtils.loadAnimation(mContext, R.anim.left_in));
vf.setOutAnimation(AnimationUtils.loadAnimation(mContext,R.anim.left_out));
BitmapFactory.Options options = new BitmapFactory.Options();
//options.inSampleSize = 4;
options.inScaled = false;
Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), Imgid[(int)(Math.random()*Imgid.length)], options);
ImageView iv = (ImageView)findViewById(position);
iv.setImageBitmap(processingBitmap_Brightness(bitmap));
vf.showPrevious();
}else if (e1.getX() < e2.getX() && e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
vf.setInAnimation(AnimationUtils.loadAnimation(mContext,
R.anim.right_in));
vf.setOutAnimation(AnimationUtils.loadAnimation(mContext,
R.anim.right_out));
BitmapFactory.Options options = new BitmapFactory.Options();
//options.inSampleSize = 4;
options.inScaled = false;
Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), Imgid[(int)(Math.random()*Imgid.length)], options);
ImageView iv = (ImageView)findViewById(position);
iv.setImageBitmap(processingBitmap_Brightness(bitmap));
vf.showNext();
}
} catch (Exception e) {
// nothing
}
return true;
}
答案 0 :(得分:0)
inSampleSize 假设缩小图片。尝试删除它并添加options.inScaled = false;
答案 1 :(得分:0)
这份官方指南非常有用:
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
基本上你必须设置一个比你需要的更小的SampleSize。然后在下一步中缩小位图以完全适合您想要的度量。
设置options.inSampleSize = 8;表示您要将图像加载宽度的1/8和高度的1/8。因此它更小。