2

I have an android app in which I take a photo using the android camera then I view the photo, if I like it then I upload the picture to a website.

Uploading the picture to the website I've noticed that there are a few pixels that are not visible on the phone!!!On the website the picture has a few extra-details that are not visible on the phone screen!!!

The picture on the phone screen is set in an imageview.

This is the layout of the activity:

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

<Button 
android:text="Confirm Photo"
android:layout_toLeftOf="@id/back"
android:id="@+id/confirm"
android:layout_marginTop="530dip"
android:layout_height="wrap_content" 
android:layout_width="165dip"
android:layout_alignParentRight="true"
>
   </Button>

 </RelativeLayout>

This is how I set the picture to the imageview:

Bundle extras = getIntent().getExtras();
    BitmapFactory.Options options=new BitmapFactory.Options();
    options.inSampleSize =2;
    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); 

    Canvas c = new Canvas(bitmapResult);
    drawTextImage(bitmapResult);
    StoreByteImage(this, bitmapResult,100);
ImageView imageView = (ImageView) findViewById(R.id.myPic);
imageView.setImageBitmap(bitmapResult);

For extra code or other details I'm here to give it to you.Thanks

adrian
  • 4,574
  • 17
  • 68
  • 119
  • 1
    what kind of extra details are you referring to? – Shlublu Aug 26 '11 at 14:24
  • Won't `android:scaleType="centerCrop"` explain the cropping? – entonio Aug 26 '11 at 14:25
  • @Shlublu There is the extradetails!I've edited my question – adrian Aug 26 '11 at 14:29
  • @entonio centerCrop should do what I want-rescale the whole image so this fits into my screen...but it doesn't...once uploaded I notice that on the screen some pixels are not visible – adrian Aug 26 '11 at 14:31
  • @entonio yes, this is a bit what I suspect: if the details actually consist in the non-visible part of the image this is due to the `centerCrop`. If it is in the middle of the image this is more likely to be caused by the resolution of the image on the screen of the mobile - too small to see them. – Shlublu Aug 26 '11 at 14:31
  • @Shlublu...the details are on the edge of the image.In other words the image doesn't fits my screen.Is not about details in the middle on the image...Is about the pixels on the edge of the image!!! – adrian Aug 26 '11 at 14:33
  • @george 'crop' means cut off the part that doesn't fit, if combined with 'center' it suggests that all the edges are equally trimmed off. – entonio Sep 14 '11 at 13:35

4 Answers4

7

If you're talking about the image on the website being larger than the one on your phone, then it's because your scale type is set to:

android:scaleType="centerCrop"

and your imageview bound probably doesn't match the image (thus the image is cropped). Try adding this line to the imageview and see if it makes a difference.

android:adjustViewBounds="true"

Lastly change you layout height and width attributes to:

layout_width="fill_parent"
layout_height="wrap_content"
Dennis van Opstal
  • 1,294
  • 1
  • 22
  • 44
NSjonas
  • 10,693
  • 9
  • 66
  • 92
2

If you image size is outside of the bounds of your ImageView when using the scaleType attribute:

android:scaleType="centerCrop"

Then your image will be cropped and only show what fits into your ImageView. To work around this, here's a helper method that you can call to scale your image down to the size that you need. It may need some tweaking on your end to fit your situation, but it should be helpful. It's a slightly modified version found at Strange out of memory issue while loading an image to a Bitmap object:

public static Bitmap decodeFile(File f, int maxSize){
    if (f == null)
        return null;
    try {
        //Decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(new FileInputStream(f),null,o);

        //Find the correct scale value. It should be the power of 2.
        int width_tmp=o.outWidth, height_tmp=o.outHeight;
        int scale=1;
        while(true){
            if(width_tmp/2<maxSize || height_tmp/2<maxSize)
                break;
            width_tmp/=2;
            height_tmp/=2;
            scale*=2;
        }

        //Decode with inSampleSize
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize=scale;
        return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
    } catch (FileNotFoundException e) {}
    return null;
}
Community
  • 1
  • 1
hooked82
  • 6,336
  • 4
  • 41
  • 46
1

According to the comments below your question, this is caused by the android:scaleType="centerCrop" statement. It hides the border of your image as the only part displayed on the device's screen is the part that fits it.

NSJonas gave more detail in this page about how to make the image to fit the screen.

Shlublu
  • 10,917
  • 4
  • 51
  • 70
-1

Sounds like you want scaleType "centerInside" instead of "centerCrop".

juell
  • 4,930
  • 4
  • 18
  • 19