Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set image size to full screen in android

Tags:

android

image

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:

enter image description 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!!

like image 537
adrian Avatar asked Aug 02 '11 12:08

adrian


2 Answers

You can use ImageView.ScaleType

ImageView.ScaleType="CENTER_CROP"
like image 79
BrainCrash Avatar answered Sep 21 '22 06:09

BrainCrash


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 i.e. 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.

like image 42
James Lim Avatar answered Sep 23 '22 06:09

James Lim