preoblem with retrieving height and width of an image

All your problems with Audio, Video and Images.

preoblem with retrieving height and width of an image

Postby vpachawa » Tue Nov 09, 2010 10:31 pm

Hi,

I am displaying an image from the res/drawable, I am able to display the image but when i try to retrieve the height and width of the image, I get 0 and 0.

My xml is:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3.  xmlns:android="http://schemas.android.com/apk/res/android"
  4.  android:layout_width="wrap_content"
  5.  android:layout_height="wrap_content"
  6.  android:orientation="vertical" >
  7.  
  8.   <ImageView
  9.  android:id="@+id/baseImg"
  10.  android:layout_width="fill_parent"
  11.  android:layout_height="fill_parent"
  12.  android:src="@drawable/buffaloradar"
  13.  />
  14. </LinearLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


and my code is:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import android.app.Activity;
  2. import android.os.Bundle;
  3. import android.util.Log;
  4. import android.widget.ImageView;
  5. import android.widget.ImageView.ScaleType;
  6.  
  7. public class ImgDisplay extends Activity{
  8.  
  9.         public void onCreate(Bundle savedInstanceState){
  10.                 super.onCreate(savedInstanceState);
  11.                 setContentView(R.layout.imgdisplay);
  12.                
  13.                 ImageView baseImg = (ImageView) findViewById(R.id.baseImg);
  14.                 baseImg.setImageResource(R.drawable.buffalorada);
  15.                 baseImg.setScaleType(ScaleType.FIT_XY);
  16.                
  17.                 Log.i(this.getLocalClassName(), "Image height = "+baseImg.getHeight());
  18.                 Log.i(this.getLocalClassName(), "Image width = "+baseImg.getWidth());
  19.         }
  20. }
  21.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


My image is a JPG image.

I was wondering if do I have to change the image to BMP format or can I use the same image, but am doing something wrong!

Can you help me in figuring out where I did wrong?

Thank you.

Appreciate your help.
Regards,
Venkata Pachawa
vpachawa
Developer
Developer
 
Posts: 47
Joined: Tue Jun 08, 2010 8:54 pm
Location: St Catharines, Ontario, Canada

Top

Re: preoblem with retrieving height and width of an image

Postby blundell » Wed Nov 10, 2010 5:40 pm

Has the image been drawn to the screen at this point? Try chaning it to a png or moving your log output to a button press and see if it can be resolved there. If not it is 0 because it is fill_parent .. something I vaguely remember
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: preoblem with retrieving height and width of an image

Postby vpachawa » Thu Nov 11, 2010 6:13 pm

Hi Blundell,

Thank you and appreciate your response.

The image is being displayed on the phone.
As am drawing it fill parent on width and height is it giving me the height and width as 0?

I also wanted to retrieve the ARGB of a pixel in the image, how can I do that?

Thanks.
Regards,
Venkata Pachawa
vpachawa
Developer
Developer
 
Posts: 47
Joined: Tue Jun 08, 2010 8:54 pm
Location: St Catharines, Ontario, Canada

Re: preoblem with retrieving height and width of an image

Postby vpachawa » Tue Nov 16, 2010 5:08 pm

I tried changing the image to PNG format and tried too but it was not giving me the width and height of the image. still gives me 0, 0.
I have also changed the layout width and height parameters to wrap_content, but still the image width and height are being returned as 0, 0.

Thanks.
Regards,
Venkata Pachawa
vpachawa
Developer
Developer
 
Posts: 47
Joined: Tue Jun 08, 2010 8:54 pm
Location: St Catharines, Ontario, Canada

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 14 guests