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
Developer
Posts: 1,627
Registered: ‎07-14-2008
My Device: Z10
My Carrier: Fido

How to set external picture for ImageButton?

I have a ImageButton and want to set a external image for the defaultImage.

 

I'm able to set the default image if I reference it from the asset folder but not externally.

 

// this works

 

        image_button->setDefaultImageSource(QUrl("asset:///images/picture_template.png"));

// this does not.  I also tried adding file:/// to the url and it doesn't work

 

        image_button->setDefaultImageSource(QUrl("shared/camera/IMG_00000017.jpg"));

 

 

 

Regular Contributor
Posts: 76
Registered: ‎07-31-2012
My Device: Blackberry
My Carrier: Vodafone

Re: How to set external picture for ImageButton?

Hi smiley,

 

Have you given permission in bar descriptor file to accsess Shared Files?

If yes then I guess it may be because the image would be too large to fit in. Max dimensions of an image which can be handled by cascade ImageView is 2048 & I assume it would be same for ImageButton

Copy the same image to assets & try setting it from there. If it doesn't work from asstes too, you may have to use QPainter & ImageData class to replicate that image. Look at the below given link. It may help:
http://supportforums.blackberry.com/t5/Cascades-Development/ImageView-cascades-noob-question/m-p/170...

Do note that the PixelBufferData Class which is mentioned in above post, has been replaced by ImageData class since release of beta 3 SDK.

 

Regards,

Nishant Shah

Developer
Posts: 1,627
Registered: ‎07-14-2008
My Device: Z10
My Carrier: Fido

Re: How to set external picture for ImageButton?

[ Edited ]

Thanks for the reply.  Shared access is ok.  I can read the picture file.

 

No matter how I set the defaultimage for ImageButton it just won't load.  When this happens the imageButton control doesn't even display on the screen.  However if I change it to a Button control the picture will load fine.

 

I copied the same file and included in the assets folder and it works but NOT when I try to set it to a shared file path.

 

        imageButton->setDefaultImageSource(QUrl("../../shared/camera/test_pic.jpg"));


is the above the correct way to set the default image?

Highlighted
Contributor
Posts: 13
Registered: ‎11-30-2012
My Device: Alpha
My Carrier: Pepephone

Re: How to set external picture for ImageButton?

Did you solved this problem?

I have a similir issue. I take a pictura with the camara, and want to display it in a ImageButton. I have access to the file, because the file is sent by post to the server, and it's correct saved, but when I try 

imageButton->setDefaultImageSource(QUrl(fileName));

 where fileName is something similar to (carama result)

/accounts/1000/appdata/com.example.myapp.testDev_xample_myapp30836967/shared/camera//IMG_00000028.jpg

 the defaultImage is always black

 

BlackBerry Development Advisor
Posts: 683
Registered: ‎11-29-2011
My Device: PRIV
My Carrier: Rogers

Re: How to set external picture for ImageButton?

another post already mentioned this, but is your image smaller than 2048x2048?