You Are Here:

Community: Developer Discussion Boards

#1 Old save image into sdcard - 2009-03-04, 08:19

Join Date: Mar 2009
Posts: 18
enezubi
Offline
Registered User
Hello!!
Sorry because my english is not very well. My proble is that I want to save an image in a sd card using j2me. I create a file in sdcard called a.jpg. the file create ok and when I go to the sdcard is there but when I want to open it i can't see the image. the code is this.

private void saveThumbImageToMobile() {
Thread thread = new Thread(){
public void run() {
try {

imagenNueva = getImagen();
raw = getByteArray(imagenNueva);
} catch (Exception e) {
e.printStackTrace();
}



try {
FileConnection fc = (FileConnection) Connector.open("file:///SDCard/a.jpg");
if (!fc.exists()) {
fc.create();
OutputStream out;
out = fc.openOutputStream();
out.write(raw);
out.flush();
out.close();
fc.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
thread.start();
}









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;
}


If you can help me please. Thank you very much!!
Reply With Quote

#2 Old Re: save image into sdcard - 2009-03-04, 11:04

Join Date: Nov 2007
Posts: 2,029
Location: Rome, Italy
Send a message via MSN to jappit Send a message via Skype™ to jappit
jappit's Avatar
jappit
Offline
Forum Nokia Champion
Hi enezubi,

please avoid creating duplicate threads, since it'll be harder to identify the global cause of your problem, and it'll double the work of other DiBo posters ;)

Instead, continue posting on the original thread:

http://discussion.forum.nokia.com/fo...d.php?t=160646

Pit


www.jappit.com - mobile and web blog
Reply With Quote

#3 Old Re: save image into sdcard - 2009-03-09, 08:52

Join Date: Sep 2007
Posts: 874
honest_success's Avatar
honest_success
Offline
Forum Nokia Champion
Quote:
Originally Posted by enezubi View Post
Hello!!
Sorry because my english is not very well. My proble is that I want to save an image in a sd card using j2me. I create a file in sdcard called a.jpg. the file create ok and when I go to the sdcard is there but when I want to open it i can't see the image. the code is this.

private void saveThumbImageToMobile() {
Thread thread = new Thread(){
public void run() {
try {

imagenNueva = getImagen();
raw = getByteArray(imagenNueva);
} catch (Exception e) {
e.printStackTrace();
}



try {
FileConnection fc = (FileConnection) Connector.open("file:///SDCard/a.jpg");
if (!fc.exists()) {
fc.create();
OutputStream out;
out = fc.openOutputStream();
out.write(raw);
out.flush();
out.close();
fc.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
thread.start();
}









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;
}


If you can help me please. Thank you very much!!



Did you check about exception ? First check that weather your code is throwing any exception or not. From your problem description it seems there is something wrong in the path.
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
Save Downloaded Image devdattac Mobile Java General 4 2008-10-10 07:43
Draw and save image shyam9 General Symbian C++ 10 2008-04-08 12:31
save image in mobile using jsr 75 rap81 Mobile Java General 1 2008-03-30 19:56
Save image in record store nim_esh Mobile Java Media (Graphics & Sounds) 2 2008-03-10 00:09
Nokia Image Converter davidpurdie General Discussion 0 2004-02-18 16:31

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