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
Highlighted
Forums Advisor I
Posts: 501
Registered: ‎03-01-2013
My Device: BlackBerry Z10
Accepted Solution

How to save image in persistent data?

Hi

I am saving the data persistently.

I am getting bytes of image and i will convert it into Bitmap.

But the problem is i don't know how to save the image inn persistent memory??

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

Re: How to save image in persistent data?

I recommend saving it on the SD Card using FIleConnection API.

 

You should save the bytes you download from the Server. 

Forums Advisor I
Posts: 501
Registered: ‎03-01-2013
My Device: BlackBerry Z10

Re: How to save image in persistent data?

Hi thanks for the reply

I have saved the bytes of the image that i am getting form server. But the problem is i have to display the image to the BitmapField everytime i made changes.

 

I am taking the image either form the gallery or capturing through camera.

 

details= PersistentStore.getPersistentObject(detailsKey);
                            
                            data.put("User Id",user_id);
                            data.put("First Name",newFirstName);
                            data.put("Last Name",newLastName);
                            data.put("Email id",newEmail);
                            data.put("Website",newWebsite);
                            data.put("Phone No",newPhone);
                            data.put("Address",newAddress);
                            data.put("Image", path1); //path1 is the bytes that i am getting after changing the image

 

synchronized (details)
                            {
                                details.setContents(data);
                                details.commit();
                            }

 

I am just facing the problem in displaying the image .  

Developer
Posts: 101
Registered: ‎05-31-2013
My Device: q10
My Carrier: reliance

Re: How to save image in persistent data?

Developer
Posts: 101
Registered: ‎05-31-2013
My Device: q10
My Carrier: reliance

Re: How to save image in persistent data?

Developer
Posts: 80
Registered: ‎05-22-2011
My Device: Blackberry Torch
My Carrier: Airtel

Re: How to save image in persistent data?

Where are you facing the issue? Is that for creating bitmap from byte array? If yes, the below code will help.

 

Bitmap.createBitmapFromBytes(bytesArray, 0, bytesArray.length(), 1);

 

New Developer
Posts: 134
Registered: ‎01-11-2011
My Device: curve

Re: How to save image in persistent data?

How you are converting this bytes to images back.

What is problem you are facing in showing images.

 

I did it by creating a class and setMethod(byte []) on its object and store this object in persistence and then getMethod that returns the byte[] and show image.

 

EncodedImage image = EncodedImage.createEncodedImage(
responseData, 0, responseData.length); here responseData is byte array.

 

Bitmap bitmap = image.getBitmap();

Forums Advisor I
Posts: 501
Registered: ‎03-01-2013
My Device: BlackBerry Z10

Re: How to save image in persistent data?

See i am getting the path1 as bytes as i have already mentioned in my code..I am getting the image from the conectServerForImage method..

 

 

 public static Bitmap connectServerForImage(String url)
        {
             HttpConnection httpConnection = null;
             DataOutputStream httpDataOutput = null;
             InputStream httpInput = null;
             int responseCode;
             Bitmap bitmp = null;
             try
             {
                  httpConnection = (HttpConnection) Connector.open(url+String);
                  responseCode= httpConnection.getResponseCode();
                   if (responseCode== HttpConnection.HTTP_OK)
                   {
                       httpInput = httpConnection.openInputStream();
                       InputStream inp = httpInput;
                       byte[] b = IOUtilities.streamToBytes(inp);
                       EncodedImage hai = EncodedImage.createEncodedImage(b, 0, b.length);
                       bitmp=hai.getBitmap();
                   }
                   else
                   {
                       throw new IOException("HTTP response code: " + responseCode);
                   }
              }
             catch (Exception ex)
             {
                  System.out.println("URL Bitmap Error........" + ex.getMessage());
             }
             finally
             {
               try
               {
                   if (httpInput != null)
                       httpInput.close();
                   if (httpDataOutput != null)
                       httpDataOutput.close();
                   if (httpConnection != null)
                         httpConnection.close();

               }
               catch (Exception e)
               {
                   e.printStackTrace();
               }
              }
            return bitmp;
        }

 

The problem is i want after changing the data on the profile page i have saved them on persistent memory. Next time if i see the changes except image i get everything... I am saving the image in bytes form.

So i want to know how do i save the image in persistent memory so that next time if i made any changes any look back again. I can see the new image.

Is there any other method to do??
       

Developer
Posts: 101
Registered: ‎05-31-2013
My Device: q10
My Carrier: reliance

Re: How to save image in persistent data?

are you using BitmapField to show the image???

Developer
Posts: 80
Registered: ‎05-22-2011
My Device: Blackberry Torch
My Carrier: Airtel

Re: How to save image in persistent data?

When you try to save the image to persistent store, use encodedImage.getData() method to extract image byte array.