i have image in sqlserver db.using ksoap2 client webservice for getting image.there i am converting image into base64 encoding and in mobile i am converting it into base64 decoding but i am unable to get image
whats the problem.how i will get image or any alternative solution for this problem
Thanks in advance
Aswan
finally i got solution for my problem by creating custom base64 class
If you decode from base64 what you get should be technically an image file and cannot be used directly in the code.
Maybe what you are looking for is something like
Image i = BitmapFactory.decodeByteArray(data, offset, length);
Where "data" is a byte array you have after the decoding, offset should be set to 0 and length equal to data.length.
After that, you can use the image with your views.
Related
I am working with a customizable database with pictures. Right now I am taking pictures as it is from the sdcard and encoding it in base64 String and then putting it in the database. but whenever I am trying decoding it and showing it in my view, I am getting Out of memory error. Can any one one tell me what is the best procedure to do it? Shall I change the size of the pictures before encoding it?
I want to re-size all of the pictures into 512*512.
Image to Base64 is very heavy operation in android. Consider saving the images on the external/internal memory and save the file path in the sqlite database.
You can convert your image to byte array then store values in sql by using BLOB type and vice versa.
As you mentioned you want to resize the images to 512*512, you can scale the image using below code,
Create bitmap from captured image and then use below line
Bitmap resizedBitmap = Bitmap.createScaledBitmap(myBitmap, 512, 512, false);
It will give you a smaller image, you can also consider compressing the image to reduce in size,
OutputStream imagefile = new FileOutputStream("/your/file/name.jpg");
// Write 'bitmap' to file using JPEG and 50% quality hint for JPEG:
bitmap.compress(CompressFormat.JPEG, 50, imagefile);
Now, you have two options,
Save the scaled and compressed image into a file and save the path of that file in db. (Better way)
Convert the scaled and compressed image to base64 string and save in db.
Althought base64 is , as many answers said, a heavy operation for android, if done properly, it should not be a problem.
There are many reasons a bitmap could be required to be saved to a DB , (photo of a invoice ticket, for example?), and this is the way i do it.
first, create a new , smaller bitmap like #Swapnil commented.
and second, correctly use the bitmap transformation methods, i've been using these (look below) two so far and haven't had any memory issue on many different devices.
link to my BitmapUtils transformation methods
I have an Android app which uses
URLEncoder.encode(S.getSongArtist(),"UTF-8")
to encode a unicode string that is posted to a AppEngine python (2.7) web service. On the service I use
urllib.unquote_plus(artist)
This is not giving me correct results. I have an input like this:
Marie+Lafor%C3%AAt
which is unquote'd to
Marie Laforêt
If I use a javascript url decode, for instance: http://meyerweb.com/eric/tools/dencoder/
I get
Marie Laforêt
A correct result.
I tried using
urllib.unquote(artist).decode('utf-8')
but this generates an exception. Any hints at all are greatly appreciated.
EDIT
Taxellool had the right answer in the comments:
what you are trying to decode is already decoded. try this:
urllib.unquote_plus(artist.encode('utf-8')).decode('utf-8')
Taxellool had the right answer in the comments:
what you are trying to decode is already decoded. try this:
urllib.unquote_plus(artist.encode('utf-8')).decode('utf-8')
I guess you are decoding before urllib.unquote():
>>> print urllib.unquote_plus('Marie+Lafor%C3%AAt'.decode('utf-8'))
Marie Laforêt
If you decode after unquote, result would be what you want:
>>> print urllib.unquote_plus('Marie+Lafor%C3%AAt').decode('utf-8')
Marie Laforêt
Just make sure you don't pass a unicode to urllib.unquote_plus.
I have a quick question how to receive a jpg image from a web api call.
String result = webApiManager.getBarcode(dataStorageManager.currentUser.CustomerID);
This method returns a jpg image but I am unsure how to handle it and display it in an ImageView. Furthermore, what data type is a jpg image and how do I convert it into an image that I can display using an ImageView. Can someone point me in the right direction on how to accomplish this. Thanks for your time.
Regards,
Ryan
instead of returning the image as a jpg...why not just return the URL to the image and then use AsyncTask in processing it...
It will be easier and faster that way... just my 2cents
I am trying to show byte array of image from server inside the image view of an android activity. I am able to get the byte array correctly as sent from the server, but while converting it into bitmap it is always returning null. I have used the BitmapFactory.decode(byteArray,0, byteArray.length) for converting image byte array to bitmap which is returning null always.
Please help me solving this and tell me if there are any alternative.
Thanks in advance.
Well a better option is to use this. I used it to display images that is present on a server. Pretty fast
URL url = new URL(link);
InputStream picin = url.openStream();
Bitmap myBitmap = BitmapFactory.decodeStream(picin);
pic.setImageBitmap(myBitmap);
Where link points to the jpg image. Works for other image formats also.
I use web service to get image. The service response contains image in base64Binary format. I try to decode response data with Base64.decode() (http://iharder.sourceforge.net/current/java/base64/). See my code below:
byte[] data = Base64.decode(responseString);
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
imageView.setImageBitmap(bmp);
decodeByteArray always return null.
I try to save data in .png file. I can open this file on my PC and in the Android File Manager application. But preview activity of File Manager couldn't open this file.
Then i try to parse this data using .NET client with Convert.Base64() method. And this image have been processing successfully. Then i compare byte array in image created with android client and .NET client. The differences were in sign of bytes. .NET uses unsigned bytes but Java use only signed bytes. Is this is a reason of my problem?
Is anybody have the same problem in decoding of base64Binary?
Here is one solution, and for me is working (knowing that the format in which the image comes from the server through the web service is base64binary)
decodedIcon[] = null;
byte[] bb = (resposeString).getBytes("utf-8");
decodedIcon = Base64.decodeBase64(bb);
Bitmap bitmap = BitmapFactory.decodeByteArray(decodedIcon, 0,
decodedIcon.length);
//then you get the image view and setImageBitmap(bitmap)
PS:
Base64.decodeBase64 comes from the library org.apache.commons.codec.binary.Base64;
You should have commons-codec-1.3.jar included in the assets folder
the version doesn't have to be 1.3
Thanks to one of my friends for this hint.