我得到了一些根据图像大小绘制图像的代码。但我想将图像拉伸到全屏。我尝试了很多但没有任何帮助。可以为我做这个吗?提前谢谢
public Bitmap getBitmap(int width, int height, int index) {
Bitmap b = Bitmap.createBitmap(width, height,
Bitmap.Config.ARGB_8888);
b.eraseColor(0xF000FFFF);
Canvas c = new Canvas(b);
Drawable d = getResources().getDrawable(mBitmapIds[index]);
int margin = 1;
int border =1 ;
Rect r = new Rect(margin, margin, width - margin, height - margin);
int imageWidth = r.width() - (border * 2);
int imageHeight = imageWidth * d.getIntrinsicHeight()
/ d.getIntrinsicWidth();
if (imageHeight > r.height() - (border * 2)) {
imageHeight = r.height() - (border * 2);
imageWidth = imageHeight * d.getIntrinsicWidth()
/ d.getIntrinsicHeight();
}
r.left += ((r.width() - imageWidth) / 2) - border;
r.right = r.left + imageWidth + border + border;
r.top += ((r.height() - imageHeight) / 2) - border;
r.bottom = r.top + imageHeight + border + border;
Paint p = new Paint();
p.setColor(0xFFC0C0C0);
c.drawRect(r, p);
r.left += border;
r.right -= border;
r.top += border;
r.bottom -= border;
d.setBounds(r);
d.draw(c);
return b;
}
答案 0 :(得分:0)
查看缩略图的这个................. onClick方法,你可以在全屏模式下开始新的活动:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
将图像uri或指示图像源的内容传递给新活动:
Intent intent = new Intent(YouActivity.this, FullImage.class);
intent.putExtra("imageUri", R.drawable.yourImage); // or the path to your image.
在FullImage活动类
中ImageView icon = (ImageView) findViewById(R.id.myImage);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inTempStorage = new byte[3*1024];
Bitmap ops = BitmapFactory.decodeFile(path, options); // instead path you can get an image from previous activity.
icon.setImageBitmap(ops);