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

Java Development

Reply
BlackBerry Development Advisor
MSohm
Posts: 14,757
Registered: ‎07-09-2008
My Device: BlackBerry Passport

can't load PNG/JPG from SD Card

Quote from the previous forums:


Smiley

Posts: 29
From: Canada
Registered: May, 2008

can't load PNG/JPG from SD Card
Posted: Jul 4, 2008 7:33 PM
 
I'm getting really frustrated with this.

I have taken some pictures with the camera and have copied some jpg files to the sd card. why i can not read them with me app? i can read the pics in main memory fine.

thanks

 


mdw66

Posts: 121
From: Newport News, VA
Registered: May, 2007

Re: can't load PNG/JPG from SD Card
Posted: Jul 7, 2008 11:10 AM
 
It is certainly possible, what error are you getting when you try to read the files? What line of code is the error occurring on?

Mike Walker
CellAvant, Inc.

 

Guest: Shubhangi
Re: can't load PNG/JPG from SD Card
Posted: Jul 8, 2008 3:09 AM
 
Can you please povide code snippet for this?

I am also not able to load data from jpeg file stored into sdcard.

Regards,
Shubhagi

 

Guest: Shubhangi
Re: can't load PNG/JPG from SD Card
Posted: Jul 8, 2008 7:14 AM
 
Hi,

Try following code:
FileConnection oInputFileConnection = (FileConnection)Connector.open("file://" + m_oFileSystemJournalListener.m_strFilePath, Connector.READ);

InputStream oInputStream = null;

// If no exception is thrown, then the URI is valid, but the file may or may not exist.
if(oInputFileConnection.exists())
{
// Open inputstream.
oInputStream = oInputFileConnection.openInputStream();
}

// Read the data from the inputstream.
byte[] arrData = new byte[(int)oInputFileConnection.fileSize()];
int nCode = oInputStream.read(arrData, 0, arrData.length);

// Close inputstream.
oInputStream.close();

// Close input file connection.
oInputFileConnection.close();

// Create bitmap image.
m_oBitmapField.setBitmap(Bitmap.createBitmapFromB ytes(arrData, 0, -1, 5));

Regards,
Shubhangi

 

Smiley

Posts: 29
From: Canada
Registered: May, 2008

Re: can't load PNG/JPG from SD Card
Posted: Jul 8, 2008 10:33 AM
 
in debug it failed in the connection().

After moving some code around and changing it abite it is working now. thanks

 

yog123

Posts: 3
From: mumbai
Registered: Apr, 2007

Re: can't load PNG/JPG from SD Card
Posted: Jul 16, 2008 5:07 AM
 
hi
In my case when ever i read image from device memory code works fine but when i tried to read image from memory card
inputstream contains zero bytes so no image is displayed in my app.. i dnt know wht problem happening in my case....

HOPE SOMEBODY KNOWS...

thanks in advance

Have you verified that the images you are reading are valid? What BlackBerry model and handheld software version are you testing on?  You can find this under Options, About on the BlackBerry.  Can you post some sample code of your implementation?

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
New Developer
pablo_
Posts: 9
Registered: ‎12-02-2008
My Device: Not Specified

Re: can't load PNG/JPG from SD Card

hi, I am having a similar problem.  I am able to successfully load and display a png file from the store/samples/pictures directory, but I have had no luck with images taken with the camera on the SD card.

 

The code is below.  I am using the eclipse plugin with version 4.5 of the component pack and testing on version 2.9.0.52 of the 8300 simulator.  Thank you much if you have any ideas!  

 



  private String filePath; 
  public ImageDemo2(String path) {
        this.filePath = path;
         try {
             System.out.println("file://" + filePath);
            FileConnection fconn = (FileConnection)Connector.open("file://" + filePath, Connector.READ);
            // FileConnection fconn = (FileConnection)Connector.open("file://" + "/store/samples/pictures/Ascension.png", Connector.READ);
           
            if (fconn.exists()) {
                InputStream input = fconn.openInputStream();
               
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                int j = 0;
                while((j=input.read()) != -1) {
                    baos.write(j);
                }
                byte[] data = baos.toByteArray();
               
                input.close();
                fconn.close();
               
                System.out.println("data[].length:  " + data.length);
                System.out.println("PROBLEM MUST HAPPEN After Encoding this point 1");
                EncodedImage image = EncodedImage.createEncodedImage(data,0,data.length);
                System.out.println("PROBLEM MUST HAPPEN After here point 2");
                Bitmap b = image.getBitmap();
                System.out.println("PROBLEM MUST HAPPEN After here point 3");
                BitmapField picture = new BitmapField(b);
                System.out.println("PROBLEM MUST HAPPEN AFTER THIS POINT point 4");
                add(picture);
                add(new LabelField("Data Length:" + data.length));
            }
            else {
                add(new LabelField("Picture does not exist"));
            }
            fconn.close();
        }
        catch (Exception ioe) {
           
            add(new LabelField("Error:   " + ioe.toString() + "\n" + ((FileIOException)ioe).getMessage()));
        }
    }

 



 

This is the console output:

 

 

file:///SDCard/BlackBerry/pictures/IMG00030.jpg
data[].length:  49712
PROBLEM MUST HAPPEN After Encoding this point 1
PROBLEM MUST HAPPEN After here point 2
everytrailBB
RX=7.8K,RF=527.1K,FF=25.6M,OF=153.6K,OS=16.5M,ON=103.3K,OR=0,FR=392,TR=31.5K,RR=0,IS=13.1K
RA=23.8M,RS=14.5M,RN=62.6K
TA=375.7K,TS=346.6K,TN=3.6K
PA=1.6M,PS=1.6M,PN=7K
R0=3.3M,2=16K,3=56K,7=41K,8=3K,9=20M,10=7.8K,11=23.8K,12=173K,13=83.4K,15=130.3K
SHUTTING DOWN SIM SERVER
Exit net_rim_bb_simphonebook(123)
Exit everytrailBB(121)
OutOfMemoryError
No detail message
net_rim_cldc-6
 JPEGEncodedImage
 getBitmapImpl
 0xB8C9
net_rim_cldc-6

...

 

BlackBerry Development Advisor
MSohm
Posts: 14,757
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: can't load PNG/JPG from SD Card

It appears that the resolution of the image you are using is too large for the application to handle.

 

You can specify a lower resolution in the Camera application's options.

 

In BlackBerry handheld software version 4.6.0 and higher you can specify the camera resolution using the steps outlined here:

 

How To - Take a snapshot using the built-in camera of a BlackBerry smartphone
Article Number: DB-00667

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/1089414/How_To...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
LSphone
Posts: 140
Registered: ‎02-08-2010
My Device: Torch 9800, Storm 9530, Curve 8330

Re: can't load PNG/JPG from SD Card

Am having same problem as yog123. 

 

Picture loads fine in Media, but in my app it shows as zero bytes. 

 

 

      FileConnection fconn = (FileConnection)Connector.open("file:///"+path);
      if (fconn.exists()) {
        InputStream input = fconn.openInputStream();
        int available = input.available();

 

Path is from a file selection dialog,  "SDcard/BlackBerry/pictures/IMG0001.JPG".

 

 

Thank you

 

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: can't load PNG/JPG from SD Card

available() only guarantees to show the number of bytes available without blocking, so is not useful for determining file size.  Use fconn.fileSize() instead. 

Developer
LSphone
Posts: 140
Registered: ‎02-08-2010
My Device: Torch 9800, Storm 9530, Curve 8330

Re: can't load PNG/JPG from SD Card

Yes, that does solve it... thank you!