You Are Here:

Community: Developer Discussion Boards

#1 Old Unhappy out of memory error in image manipulation - 2009-04-13, 08:06

Join Date: Apr 2009
Posts: 13
Location: INDIA
vdx's Avatar
vdx
Offline
Registered User
hello friends,

I am developing an app tht sends image to server with help of http multipart request.
Nw, I want to convert the image in byte array.
Code:
    public static byte[] getByteArray(Image image)
    {
        int raw[] = new int[image.getWidth() * image.getHeight()];
        image.getRGB(raw, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight());
        byte rawByte[] = new byte[image.getWidth() * image.getHeight() * 4];

        int n = 0;
        for(int i = 0; i < raw.length; i++)
        {
            int ARGB = raw[i];
            int a = (ARGB & 0xff000000) >> 24;
            int r = (ARGB & 0xff0000) >> 16;
            int g = (ARGB & 0xff00) >> 8;
            int b = ARGB & 0xff;
            rawByte[n] = (byte)b;
            rawByte[n + 1] = (byte)g;
            rawByte[n + 2] = (byte)r;
            rawByte[n + 3] = (byte)a;
            n += 4;
        }

        raw = null;
        return rawByte;
    }
when the 5th line "byte rawByte[] = new byte[image.getWidth() * image.getHeight() * 4];" got executed, its raising outofmemory exception....

wt should i do ??
Do I have any othe way to convert an image to byte array ??
Reply With Quote

#2 Old Thumbs up Re: out of memory error in image manipulation - 2009-04-13, 10:40

Join Date: Mar 2008
Posts: 2,161
Location: The Capital of I N D I A
Send a message via Skype™ to raj_J2ME
raj_J2ME's Avatar
raj_J2ME
Offline
Forum Nokia Champion
Hi,
Can you make sure that how many times this methods executes?


Thanks

R a j - The K e r n e l
Reply With Quote

#3 Old Re: out of memory error in image manipulation - 2009-04-13, 12:38

Join Date: Jun 2003
Posts: 4,325
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
How big is the image (width and height)?

Why do you want to convert it into an array of pixels?

Cheers,
Graham.
Reply With Quote

#4 Old Smile Re: out of memory error in image manipulation - 2009-04-13, 13:19

Join Date: Apr 2009
Posts: 13
Location: INDIA
vdx's Avatar
vdx
Offline
Registered User
thnx for the replay Raj, Grahamhughes

by doing some R&D and paperwork, finally i have removed the posted code with the below new one,

Code:
    public byte[] getImageBytes(String path)
    {
        byte[] imgData = new byte[0];

        try
        {
            FileConnection fc = (FileConnection) Connector.open(path, Connector.READ);
            InputStream stream = fc.openInputStream();
            long File_Size = fc.fileSize();
            final int CHUNK = 1;

            int length = 0;
            
            while(length < File_Size)
            {
                byte[] data = new byte[CHUNK];
                int readAmount = stream.read(data, 0, CHUNK);
                byte[] newImageData = new byte[imgData.length + CHUNK];
                System.arraycopy(imgData, 0, newImageData, 0, length);
                System.arraycopy(data, 0, newImageData, length, readAmount);
                imgData = newImageData;
                length += readAmount;
            }

        }catch(Exception e) {}
        return imgData;
    }
I want to send the image to an http server. For that I need to convert it into byte array.

nw i can read my image file data chunk by chunk.

by the way thnx lot 4 the replay. thnx 1s again... :)


Good judgment comes from experience, and experience comes from bad judgment.
Last edited by vdx : 2009-04-13 at 13:25.
Reply With Quote

#5 Old Thumbs up Re: out of memory error in image manipulation - 2009-04-13, 14:30

Join Date: Mar 2008
Posts: 2,161
Location: The Capital of I N D I A
Send a message via Skype™ to raj_J2ME
raj_J2ME's Avatar
raj_J2ME
Offline
Forum Nokia Champion
Hi,
Since this is a very important thread/subject asked by the developers,so I would appreciate you if can share the solution.


Thanks

R a j - The K e r n e l
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Image size on 6280 ariekk Mobile Java General 0 2008-09-15 07:42
Using Camera API requires too much memory tote_b5 Symbian Media (Graphics & Sounds) 18 2008-07-31 17:21
Excessive midlet memory consumption paulip Mobile Java General 1 2007-10-09 20:24
--- ???save image problem??? --- ferenn Mobile Java Media (Graphics & Sounds) 6 2007-10-01 15:33
show image on the form from memory aaapigfly Mobile Java Media (Graphics & Sounds) 2 2007-08-27 21:15

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d18645X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZentertainmentQ qfnZtopicQUqfnTopicZj2meQ qfnZtopicQUqfnTopicZjavaQ qfnZtopicQUqfnTopicZmediaQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ