Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Super Contributor
Posts: 440
Registered: ‎01-13-2011
My Device: Playbook
My Carrier: NA

Width and Height of source image?

I have an image:

 

ImageView* myImg = ImageView::create("asset:///images/hello.png");

 How can I get the width and height of the source image?

--------------------------------------------------------------------------------------------------
BlackBerry Apps: Instruments | ARTPAD | Piano | Drums | Xylophone
Developer
Posts: 526
Registered: ‎05-17-2009
My Device: 9900
My Carrier: ATT

Re: Width and Height of source image?

Unless you are going to display it, why are you loading the image into an imageview? Loading it into a QImage would help you get the size if thats what you really wanted to know. ImageView wont help you get the size of the contents because its size is determined on layout and how the images are scaled. You might be able to get it from myImg->image() but im not sure
Like all of my posts
Regular Contributor
Posts: 56
Registered: ‎08-21-2012
My Device: BB10
My Carrier: RIM

myImg->setPreferredSize(float preferredHeight, float preferredWidth);

[ Edited ]

Hi,

 

float height= myImg->preferredHeight();

float width=  myImg->preferredWidth();

 

Best Regards,

Megha Patel

Super Contributor
Posts: 440
Registered: ‎01-13-2011
My Device: Playbook
My Carrier: NA

Re: myImg->setPreferredSize(float preferredHeight, float preferredWidth);

Preffered width/height are not set until you set them, so this would not work.

--------------------------------------------------------------------------------------------------
BlackBerry Apps: Instruments | ARTPAD | Piano | Drums | Xylophone
Super Contributor
Posts: 440
Registered: ‎01-13-2011
My Device: Playbook
My Carrier: NA

Re: Width and Height of source image?

I am going to display the image. Shoudl I not be using an images on screen that need to recieve touch events. Would QImage be a better way to display them?

--------------------------------------------------------------------------------------------------
BlackBerry Apps: Instruments | ARTPAD | Piano | Drums | Xylophone
Regular Contributor
Posts: 54
Registered: ‎07-15-2010
My Device: Not Specified

Re: Width and Height of source image?

[ Edited ]

I had this problem before. What I did was to create a QImage object with the same image of the ImageView, so this way I could get the proper height and width. Here you have an example:

 

QImage origImage;

origImage.load(aImagePath);

int imageWidth = origImage.width();
int imageHeight = origImage.height();

The part you have to care about here is that aImagePath is the folder relative to the system, not to Cascades (as this class is not from Cascades), so for

 

asset:///images/background.jpg

 

you should use

 

QString aImagePath = QDir::currentPath() + "/app/native/assets/images/background.jpg";

 

I hope this helps,