0

I'm new to android. I am able to retrieve the image from my phone. However I'm not getting the height and width needed as defined in the xml file. The image still appeared rectangle instead of a square (its simply a scale down of my original photo. However, i just need a square crop of the image (part of the image without scaling).

XML file (image view):

<ImageView 
    android:id="@+id/photo"
    android:layout_width="=100dp"
    android:layout_height="100dp" 
    android:scaleType="center"
    android:adjustViewBounds="false" 
    android:gravity="center"/>

Code:

public View getView(final int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
        convertView = l_Inflater.inflate(R.layout.item_view, null);
        holder = new ViewHolder();
        holder.itemImage = (ImageView) convertView.findViewById(R.id.photo);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    Uri fileURI = Uri.parse(itemArrayList.get(position).getPhoto());
    holder.itemImage.setImageURI(fileURI);
    return convertView;
}
Kate Gregory
  • 18,808
  • 8
  • 56
  • 85
iceraven
  • 225
  • 1
  • 5
  • 16
  • See http://stackoverflow.com/questions/13596500/android-image-resizing-and-preserving-exif-data-orientation-rotation-etc – Gaurav Agarwal Dec 26 '12 at 16:18
  • hi, the above is an image stored on my phone. i would like to retrieve it and display it with the height and width of 100. even if the image is 200X180, i would only want 100X100 which is a crop of the image. i do not think it has got anything to do with exif data. – iceraven Dec 26 '12 at 16:25
  • Check this http://stackoverflow.com/search?q=android+crop+an+image – Gaurav Agarwal Dec 26 '12 at 16:29

1 Answers1

1

You've set your ImageView layout_width and layout_height in dp not pixels. So on hdpi devices 100dp is actually 150px and 200 on xhdpi. This can be the reason of your problem. You can set width and height in px and put your image in drawable-nodpi folder(to perform no scaling). Also you can use createBitmap (Bitmap source, int x, int y, int width, int height) method to get a part of image that you want.

amukhachov
  • 5,822
  • 1
  • 41
  • 60