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

Adobe AIR Development

Reply
New Developer
Tjitte
Posts: 100
Registered: ‎10-31-2010
My Device: Dev Alpha C and PlayBook
Accepted Solution

View image from applicationStorageDirectory

[ Edited ]

Hello,

 

I want to view an image form the applicationStorageDirectory but I get an URL not found error.

 

var imgLoad:Image = new Image();
imgLoad.setImage(File.applicationStorageDirectory.nativePath + "/test.png");
imgLoad.setSize(1024, 600);

 

The image test.png is present in that directory but I can't load it.

Does anyone have a solution?


My PlayBook app:
DrawBook
Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: View image from applicationStorageDirectory

How did you get that image in the storage directory?  Installed files are only in the applicationDirectory relative to the /src of your project.  If that image was saved there and the File "exists" method is returning true, it might be related to something else.

Please use plain text.
Developer
kdittyr
Posts: 278
Registered: ‎10-27-2010
My Device: Playbook

Re: View image from applicationStorageDirectory

If the file does exist, you can use try this solution using QNX's Image Class ( thanks JRab )

http://supportforums.blackberry.com/t5/Tablet-OS-SDK-for-Adobe-AIR/Native-UI/m-p/681167#M2778

--------------
kdittyr

Accepted PlayBook Applications:
HDB Converter -- Utilities/Calculators
Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: View image from applicationStorageDirectory

jrab's example is for files relative to the project /src directory.  They're trying to load a file from the application storage directory.  I do this in one of my apps and it works fine as an AIR application, but I think there might be a problem on the PB.  I wll double check.

Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: View image from applicationStorageDirectory

Yes, I too am having trouble loading an image from the app storage directory.  I dont have trouble access preference files from the same directory.  This might require a work around by loading the image into memory as a bitmap and then setting that to the image.

Please use plain text.
New Developer
Tjitte
Posts: 100
Registered: ‎10-31-2010
My Device: Dev Alpha C and PlayBook

Re: View image from applicationStorageDirectory

[ Edited ]

Thank you for the quick reactions 

 

The image is created by the application and I checked Its existence. 

 

The "Image" class in the piece of code is already the qnx.ui.display.Image class.


My PlayBook app:
DrawBook
Please use plain text.
Developer
kdittyr
Posts: 278
Registered: ‎10-27-2010
My Device: Playbook

Re: View image from applicationStorageDirectory

"The "Image" class in the piece of code is already the qnx.ui.display.Image class."

 

Yes it was...  :blush: I didn't notice the setImage(...  portion of your code.

--------------
kdittyr

Accepted PlayBook Applications:
HDB Converter -- Utilities/Calculators
Please use plain text.
Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: View image from applicationStorageDirectory

[ Edited ]

hey Tjitte,

 

this was bugging me too but then saw the documentation closer and an assist from harry_dodgson. in the setImage method it requires a URL input not just an absolute path. so do this:

 

change:

 

 

imgLoad.setImage(File.applicationStorageDirectory.nativePath + "/test.png");

 

 

to this:

 

 

imgLoad.setImage("file://" + File.applicationStorageDirectory.nativePath + "/test.png");

 

and you should be golden. hope that helps! good luck!

 

Edit: from the documentation:

 

"... The image parameter can be of type String as a URL to an external image..."

 

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: View image from applicationStorageDirectory

Gotta love the differences between AIR and the simulator.  Worked for me.

Please use plain text.
New Developer
Tjitte
Posts: 100
Registered: ‎10-31-2010
My Device: Dev Alpha C and PlayBook

Re: View image from applicationStorageDirectory

Your solution was perfect J. Rab. Everything is working now.

 

Thank you all for your help!

 

Tjitte


My PlayBook app:
DrawBook
Please use plain text.