简体   繁体   中英

set image size to full screen in android

I'm having an android app in which I'm taking a picture using the android camera. This picture is taken in the activity A and after that is sent to activity B where is edited.

This is how I receive my image in activity B :

Bundle extras = getIntent().getExtras();
BitmapFactory.Options options=new BitmapFactory.Options();
        options.inSampleSize = 5;
        byte[] imageData = extras.getByteArray("imageData");
        Bitmap myImage = BitmapFactory.decodeByteArray(imageData , 0, imageData.length,options);

        Matrix mat=new Matrix();
        mat.postRotate(90);
        bitmapResult = Bitmap.createBitmap(myImage, 0, 0, myImage.getWidth(), myImage.getHeight(), mat, true); 
 ImageView imageView = (ImageView) findViewById(R.id.myPic);
        imageView.setImageBitmap(bitmapResult);

As you can see I'm rotating the bitmap I receive with 90 using this:

Matrix mat=new Matrix();
            mat.postRotate(90);

And here is my imageView in xml file:

<ImageView  
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_gravity="center"
    android:id="@+id/myPic"
    />

The problem that I'm facing is that my picture is not full screen...it's almoust full screnn but not entirly.As you can see here:

在此输入图像描述

If you could help me to increase a little bit its size I would really apreciate it.Thanks

EDIT:I wanna increase the width of my image only.Sorry!!

您可以使用ImageView.ScaleType

ImageView.ScaleType="CENTER_CROP"

You might have to crop the image. Because the image is not at its full height, the width of the image is proportionately scaled down, hence the black strips at the sides.

To be more specific, images taken using the phone's camera are probably intended to fit the screen exactly ie width-height ratio of image = width-height ratio of the screen. However, in your app the height of the image is constrained by the buttons at the top, so in order to maintain the width-height ratio of the image, the width of the image is scaled down proportionately.

Please refer to setScaleType

You could use CENTER_CROP to get full screen image and maintain the image's aspect ratio.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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