简体   繁体   English

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

[英]how to modify this code to stretch the image to full screen in android

I got some code it draws images according to the size of the image.我得到了一些代码,它根据图像的大小绘制图像。 but i want to stretch the image to full screen.但我想将图像拉伸到全屏。 i tried a lot but nothing really helped.我尝试了很多,但没有任何帮助。 Can any do this for me?任何人都可以为我做这件事吗? thanks in advance提前致谢

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

check out this.................onClick method of your thumbnail, you can start a new Activity in fullscreen mode:看看这个........onClick 方法的缩略图,你可以在全屏模式下启动一个新的活动:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

and pass the image uri or something which indicate the image source to the new activity:并将图像 uri 或指示图像源的内容传递给新活动:

Intent intent = new Intent(YouActivity.this, FullImage.class);  
intent.putExtra("imageUri", R.drawable.yourImage); // or the path to your image. 

in FullImage Activity class在 FullImage 活动中 class

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM