Is there any way to reduce the byte[] size in which the camera captured image is stored im encoding the byte array in to base64 binary and trying to send it to server.
or else can anyone suggest an alternative to send image to the server
Is there any way to reduce the byte[] size in which the camera captured image is stored im encoding the byte array in to base64 binary and trying to send it to server.
or else can anyone suggest an alternative to send image to the server
anyone can suggest how to send image to server successfully
Hi,
Base64 alogrithm is more of a encoding rather than compression. Base64 makes sure that there is no loss of data in between.
If you want to reduce the size of images while transferring then one way is to reduce the resolution of the images captured that will automatically reduce the size of the images. Otherwise you may have to implement image compression algorithms such as Run length encoding or Huffman Coding.
In implementing the image compression algorithms make sure that the time taken by the algorithm should not be much otherwise it will be of no use I think.
Hope this information will help you.
Sunil
Mobile Application Developer
Hi Mahesh,
Following the suni post you can move forward with the code,
FileConnection fc = (FileConnection) Connector.open(”file://localhost/root1/path/to/file”);
if (!fc.exists())
{
throw new IOException(”File does not exists”);
}
InputStream fis = fc.openInputStream();
byte[] b = new byte[5000];
int length2 = fis.read(b, 0, 5000);
fis.close();
fc.close();
Now to avoid lose of data, we can apply base64 encoding like
String tempStr2 = new String(Base64.encode(fileBytes));
Note:- you may useany base64 class for this use but encoding and decoding should be synchronized no matter whatever is implementation technology on server
* Now we will build http connection and upload data on it
httpConnection = (HttpConnection) Connector.open(”http://Server/Address/to/target/script”);
httpConnection.setRequestMethod(HttpConnection.POST);
httpConnection.setRequestProperty(”User-Agent”, “Profile/MIDP-2.0 Configuration/CLDC-1.0″);
httpConnection.setRequestProperty(”Content-Language”, “en-US”);
httpConnection.setRequestProperty(”Content-Type”, “application/x-www-form-urlencoded”);
httpConnection.setRequestProperty(”Content-Length”, Integer.toString(data.length));
os = httpConnection.openOutputStream ();
os.write(data);
os.close();
httpConnection.close();
Thanks,
Thanks with Regards,
R a j - The K e r n e l
Join Delhi-NCR Nokia Developer's Community,
Hi raj
i tried the same http code but might some prblm in compatibility as our web service is written in .net also tried encoding the image in base 64 binary but in .net the decoded string is not exactly what we wanted
thnks
Hi Mahesh,
Please discuss the same issue with your server side team,Check wjat they can do for you,in order to solve this issue,
Thanks,
Thanks with Regards,
R a j - The K e r n e l
Join Delhi-NCR Nokia Developer's Community,