BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 06-26-2007, 12:22 PM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Aug 2006
Model: 8300
Carrier: Cingular
Posts: 35
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Displaying Sample/User Pictures in Application

Please Login to Remove!

Greetings,


I am trying to load a picture from either the preloaded sample picture folder or the user picture folder and display it within my application running on OS4.2.x. I am able to extract the URI through a FileConnection and searching at "file:///store/samples/pictures/" and "file:///store/home/user/pictures". However, I am unable to find a way to display the picture. Once I have obtained the file path, is there a way to convert it to a Bitmap or Image for displaying? Any alternative methods?


Thank you,
Californium

Last edited by Californium : 06-26-2007 at 12:30 PM.
Offline  
Old 06-26-2007, 12:40 PM   #2 (permalink)
Knows Where the Search Button Is
 
Join Date: Feb 2007
Model: 9000
Carrier: SFR
Posts: 48
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Bitmap myBitmap = Bitmap.getBitmapResource("ProjRoot/Path");
?
Offline  
Old 06-26-2007, 12:42 PM   #3 (permalink)
Knows Where the Search Button Is
 
Join Date: Aug 2006
Model: 8300
Carrier: Cingular
Posts: 35
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

That seems to give an error:

FRIDG: could not find file:///store/samples/pictures/BBTiles-Orange.png
Offline  
Old 06-27-2007, 12:03 AM   #4 (permalink)
Thumbs Must Hurt
 
Rose's Avatar
 
Join Date: Nov 2006
Location: India
Model: 9700
OS: Windows 7
Carrier: Airtel
Posts: 121
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi ,
file:///store/samples/pictures/ is used to read files that are stored in SDCard or device memory..

Bitmap.getBitmapResource("ProjRoot/Path"); this is used to read a file from the jar. To use this code you need to package the image with in the jar.

To display image from the internal memory read the file as bytes and then create
byte[] data;
EncodedImage.createEncodedImage(data,0,data.length );


Then use can draw the encoded image to a bitmapField or you can create a bitmap from the encoded image.
Offline  
Old 06-27-2007, 09:59 AM   #5 (permalink)
Knows Where the Search Button Is
 
Join Date: Aug 2006
Model: 8300
Carrier: Cingular
Posts: 35
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for the information. I will try that out!


Regards,
Californium


Note: If anyone is curious, here's the code to display the image.
Code:
/*
 * PictureViewer.java
 *
 * © <your company here>, 2003-2005
 * Confidential and proprietary.
 */

package pictureviewer;

import java.io.*;
import java.lang.*;
import java.util.*;
import javax.microedition.io.*;
import javax.microedition.io.file.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.system.*;


/**
 * 
 */
class PictureViewer extends UiApplication{
    
    public static void main(String[] args)
    {
        //create a new instance of the application
        //and start the application on the event thread
        PictureViewer theApp = new PictureViewer();
        theApp.enterEventDispatcher();
    }
    
    PictureViewer() {  
        MainScreen main = new MainScreen();

        try {
            FileConnection fconn = (FileConnection)Connector.open("file:///store/samples/pictures/DuskClouds.jpg");
            // If no exception is thrown, then the URI is valid, but the file may or may not exist.
            if (fconn.exists()) {
                InputStream input = fconn.openInputStream();
                int available = input.available();
                byte[] data = new byte[available];
                input.read(data, 0, available);
                EncodedImage image = EncodedImage.createEncodedImage(data,0,data.length);
                Bitmap b = image.getBitmap();
                BitmapField picture = new BitmapField(b);
                main.add(picture);
                main.add(new LabelField("Data Length:" + data.length));
            }
            else {
                main.add(new LabelField("Picture does not exist"));
            }
            fconn.close();
        }
        catch (Exception ioe) {
            main.add(new LabelField("Error"));
        }
        pushScreen(main);
    }
}

Last edited by Californium : 06-28-2007 at 01:04 PM.
Offline  
Old 09-17-2007, 11:44 AM   #6 (permalink)
New Member
 
Join Date: Sep 2007
Model: 7100
PIN: N/A
Carrier: Vodafone
Posts: 10
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is there any version 4.0 alternative code for the above because package

Code:
javax.microedition.io.file.*
is missing and hence no FileConnection.
Offline  
Old 10-19-2007, 03:40 AM   #7 (permalink)
Knows Where the Search Button Is
 
Join Date: Oct 2007
Model: 8700
PIN: N/A
Carrier: none
Posts: 23
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

is there any method to display a txt file(text.txt) once u have obtained the file path..

would appreciate for response thanks in advance
Offline  
Old 06-24-2008, 05:48 PM   #8 (permalink)
Talking BlackBerry Encyclopedia
 
Smiley8's Avatar
 
Join Date: May 2008
Location: Calgary, AB
Model: Torch
Carrier: Fido
Posts: 226
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have Pearl 8100 with OS 4.2.1.109 and the code wont run. It returns Error. do you know why?
__________________
Visit our website www.toysoft.ca for Cool BlackBerry Apps.

Follow us @ http://twitter.com/toysoft
Offline  
Old 06-27-2008, 09:46 AM   #9 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

It seems that the access to the "embedded" image files is completely disallowed...
I had the same problem when I needed an image file for testing the code and was too lazy to copy my own to the device. However the code worked with "normal" images but not with those provided with the device
Offline  
Old 09-22-2008, 11:05 AM   #10 (permalink)
New Member
 
Join Date: Sep 2008
Model: 8120
PIN: N/A
Carrier: T-mobile
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is their is a way to get the h t t p:// instead a file:// I need help . Please reply
__________________
Thanks and Regards,
Michymouse.
Offline  
Old 10-01-2008, 08:22 AM   #11 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hum I try this way but my program throw an error when :

Bitmap b = image.getBitmap();

I know that the path is correct and my byteArray too because I'm successful to send it to a web service.

What's wrong??

I use the code given excatly
Offline  
Old 10-02-2008, 11:11 AM   #12 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here there is my code

Code:
FileConnection fconn = (FileConnection)Connector.open(cheminPhoto1);
                
System.out.println("Connexion établie");
// If no exception is thrown, then the URI is valid, but the file may or may not exist.
if (fconn.exists()) 
{

                    InputStream input = fconn.openInputStream();

                    int available = input.available();

                    byteArray = new byte[available];

                    input.read(byteArray, 0, available);

                    //I know that the pb comes from this line but I don't know why
                    EncodedImage image = EncodedImage.createEncodedImage(byteArray,0,byteArray.length);

                    Bitmap b = image.getBitmap();

                    BitmapField picture = new BitmapField(b);

                    add(picture);
}
Is someone can tell me what's wrong??

I know that my byteArray is correct because I send it to a web service and this last recover the correct picture
Offline  
Old 10-03-2008, 02:45 AM   #13 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

No one can tell me what's wrong???
Offline  
Old 10-06-2008, 02:23 AM   #14 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

not sure if it applies but at least pictures stored with a contact are encoded in base64.

Code:
byte[] photoEncoded = blackberryContact.getBinary(BlackBerryContact.PHOTO, 0);
byte[] photoDecoded = Base64InputStream.decode(photoEncoded, 0, photoEncoded.length);
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 10-06-2008, 02:43 AM   #15 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

But it's not a picture stored with a contact.

The picture comes from the camera.
Offline  
Old 10-06-2008, 09:58 AM   #16 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hum I found a solution.

the problem seems to come from

byteArray = new byte[available];
input.read(byteArray, 0, available);

I don't know what but it doesn't wrok my byte Array is allways null.

So I do this :

ByteArrayOutputStream baos = new ByteArrayOutputStream();
int j = 0;
while((j=input.read())!=-1)
{
baos.write(j);
}
byteArray = baos.toByteArray();

I know that is not a very fast an elegant operation but it works
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright © 2004-2014 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.