如何在android中修改此代码以将图像拉伸到全屏

如何在android中修改此代码以将图像拉伸到全屏,android,image,scale,drawable,Android,Image,Scale,Drawable,我得到了一些代码,它根据图像的大小绘制图像。但是我想把图像扩展到全屏。我试了很多,但没有什么真正的帮助。有人能帮我吗?提前谢谢 public Bitmap getBitmap(int width, int height, int index) { Bitmap b = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); b.eraseColor(0xF000FFF

我得到了一些代码,它根据图像的大小绘制图像。但是我想把图像扩展到全屏。我试了很多,但没有什么真正的帮助。有人能帮我吗?提前谢谢

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;
    }

查看此………..单击缩略图的方法后,您可以在全屏模式下启动新活动:

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); 

尝试设置为背景图像,而不是src图像它将拉伸,但会使图像变形