BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 06-26-2007, 12:22 PM   #1
Californium
Knows Where the Search Button Is
 
Join Date: Aug 2006
Model: 8300
Carrier: Cingular
Posts: 35
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
egalexe
Knows Where the Search Button Is
 
Join Date: Feb 2007
Model: 9000
Carrier: SFR
Posts: 48
Default

Bitmap myBitmap = Bitmap.getBitmapResource("ProjRoot/Path");
?
Offline  
Old 06-26-2007, 12:42 PM   #3
Californium
Knows Where the Search Button Is
 
Join Date: Aug 2006
Model: 8300
Carrier: Cingular
Posts: 35
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
Rose
Thumbs Must Hurt
 
Rose's Avatar
 
Join Date: Nov 2006
Location: India
Model: 9700
OS: Windows 7
Carrier: Airtel
Posts: 121
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
Californium
Knows Where the Search Button Is
 
Join Date: Aug 2006
Model: 8300
Carrier: Cingular
Posts: 35
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
Pook
New Member
 
Join Date: Sep 2007
Model: 7100
PIN: N/A
Carrier: Vodafone
Posts: 10
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
banu_berry
Knows Where the Search Button Is
 
Join Date: Oct 2007
Model: 8700
PIN: N/A
Carrier: none
Posts: 23
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
Smiley8
Talking BlackBerry Encyclopedia
 
Smiley8's Avatar
 
Join Date: May 2008
Location: Calgary, AB
Model: Torch
Carrier: Fido
Posts: 226
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
Ivanov
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
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
mickymouse
New Member
 
Join Date: Sep 2008
Model: 8120
PIN: N/A
Carrier: T-mobile
Posts: 4
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
goulamass
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
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
goulamass
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
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
goulamass
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Default

No one can tell me what's wrong???
Offline  
Old 10-06-2008, 02:23 AM   #14
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
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
goulamass
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
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
goulamass
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
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



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


Unifi Talk UVP Touch VOIP IP Phone Unlocked picture

Unifi Talk UVP Touch VOIP IP Phone Unlocked

$139.99



Unifi Talk UVP Touch VOIP IP Phone Unlocked picture

Unifi Talk UVP Touch VOIP IP Phone Unlocked

$150.00



Vtech ErisTerminal VSP861 Touchscreen Color Desktop - Voice-Over-IP VOIP Phone picture

Vtech ErisTerminal VSP861 Touchscreen Color Desktop - Voice-Over-IP VOIP Phone

$14.99



"NEW" RingCentral Polycom VVX 311 6-Line VoIP IP SIP Business Media Phone

$12.95



Cisco CP-8811-K9 Unified Office IP VoIP PoE Business Phone w/ Stand & Handset picture

Cisco CP-8811-K9 Unified Office IP VoIP PoE Business Phone w/ Stand & Handset

$14.99



Polycom Vvx 601 VoIP 16 Line Business Phone 4.3

Polycom Vvx 601 VoIP 16 Line Business Phone 4.3" HD Touchscreen PoE With Stand

$28.95







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