how to convert an image into qrcode in android - android

Actually, I'am developping an application wich should allow users to get photo from the camera and then convert it into qrcode.
I am trying to use xzing library to generate the qrcode and the Base64 java class to convert the image to String.But when I run this application, the class qrcodewriter handles an exception indicating that the data is too big to be converted.I have tried to get some solutions to this problem and the only way that I found is to subdivise the String generated using the Base64 class into substrings and then convert each of these substrings to a subqrcode and finally concatenate these subqrcodes to get the desired result.Can any one help me to find other method that is easier to implement.

Try to resize and compress the image and then convert the compressed image to base64 encoding. This base64 string will be comparatively small. Now generate QR code based on this string. You have to find the trade-off between quality of image and it's size.

Related

Convert Image object to Base64 String in Android

I've seen a huge number of related questions, but none of them actually answer the question, and many just use code snippets out of context with undefined variables.
I need to store images in a database (which to the best of my knowledge I should do using Base64 encoded strings), and use them as Image objects in the android code.
From what I've worked out, I need to convert the Image to a Bitmap, then Bitmap can be turned into a Base64 string. But I can't for the life of me work out how to convert the Image into a Bitmap. Any help is appreciated.
EDIT: While other questions do convert an image from a file location to a string, I don't have a file location. The image is stored solely as an instance of android.media.Image, and I don't know how to access that using a file path or anything similar.
EDIT 2: Okay, so here's my setup: the images will be stored in Firebase database as Base64 encoded strings. When I need them, I will pull the string from there and convert it into an Image object, which is just a variable I have temporarily. They are never stored locally, the only time they're on the actual app they are the Image object.
Just convert your base64 string into bitmap than load that bitmap into imageview using below code
byte[] decodedString = Base64.decode(encodedImage, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
image.setImageBitmap(decodedByte);

Save Image files and some text together as one file/object

I created an android test app with camera interface in which I want to save a text message and image file as one object. I am able to enter message, call the camera,take a picture and also populate the image in the image view on the app. Now I want to save them as one single record/object so that I can transfer it over network using protocol such as ftp. How to save image file and text together as one single file/object? Could someone please tell me how to do that. Thanks in advance.
There are lots of possibilities, and it depends to some extent on what will be consuming the file after it is transferred. You could, for instance, simply serialize the string and the image data using a DataOutputStream wrapped around a FileOutputStream. As a fancy version of that, you could define a class to contain the text and the image, have that class implement Serializable, and serialize it to a file. Alternatively, you could serialize the image data as a base-64 string and then put the text and the base-64 image data into an XML document or JSON string. Other approaches are also possible.
If you provide more details about what kind of process will consume this file after it has been transferred, perhaps we can provide more focused suggestions.

Android: System.out: "resolveUri failed on bad bitmap Uri:[B#4072aa78" Prompt when resotre image stream to ListView

I have referred couple of similiar articles regarding the message prompted from System.
The image string is a byte array type Bitmap format. It was encoded to string format by using andorid's Base64 class tool. Then it was saved to mysql DB with Blob format.
On my new App, I want reload the Blob image sting to ListView and show the image: I tried two approaches, but all were failed loading image to listview:
a. put the re-loaded Blob imange(it is a string text type) as value of HashMap's key/value pairs. And then,initial an Adaper (ex. SimpleAdapter) to load the key/vales' and then try to show it on ListView(failed).
b. Similar a, but use Base64 decode method to decode the Blob image back to byte array first. And take it as Byte array type as value of hashMap's key/vale pair.(failed)
I have had studied this problem couple of days and no progress for this problem. If I used wrong process before, Please guide me to correct it, thanks !
By the way. the stored Blob image string can be re-loaded and display to ImageView using
imageview.setImageBitmap(bitmap) method without problem. So, the stored image string data is valid bitmap data. However, this method can not be used on ListView.

Include Small Image in JSON for Android App

My app currently requests a JSON file with some text and other data from my server. I want to add functionality so that it also downloads a very small image (like an icon) through the same file [without creating an additional request]. Is it possible to do so, and how would I go about it (base64?)
Should be eminently reasonable: look at http://developer.android.com/reference/android/util/Base64.html. All you'd need to do is:
Read your icon into a byte[] array on the server.
(Assuming your server is in java) Use something like http://iharder.sourceforge.net/current/java/base64/ to write the byte[] array into a StringOutputStream through http://iharder.sourceforge.net/current/java/base64/api/index.html?Base64.OutputStream.html.
Add the contents of the String to the JSON file.
On the android device call http://developer.android.com/reference/android/util/Base64.html#decode%28java.lang.String,%20int%29 to convert the JSON attribute into a byte[] array.
You can then pass the byte array to http://developer.android.com/reference/android/graphics/BitmapFactory.html#decodeByteArray%28byte[],%20int,%20int,%20android.graphics.BitmapFactory.Options%29 or one of its brethren functions (you may have to play with image formats/encodings to get it to swallow your byte array correctly).
Voila! You have a Bitmap you can use.
Let me know how that works out.

how to convert imagebytes to byte[] in android using ksoap?

friends,
i am using ksoap library to call dotnet webservice.
i am getting following webservice reponse
<imageByte>R0lGODlhlgBQAPcAAKPBqfP69Ja0m32hgxdVJdrb28zMzPr+/QRKEdPi1IGliL3PwCFXLP38+YSJhPr7+</imageByte>
<imageByte>R0lGODlhlgBQAPcAAKPBqfP69Ja0m32hgxdVJdrb28zMzPr+/QRKEdPi1IGliL3PwCFXLP38+YSJhPr7+</imageByte>
<imageByte>R0lGODlhlgBQAPcAAKPBqfP69Ja0m32hgxdVJdrb28zMzPr+/QRKEdPi1IGliL3PwCFXLP38+YSJhPr7+</imageByte>
removed some extra bytes from string because it was very lengthy.
1) i dont know which format it is.
2) how to convert it to byte[] to display it in android imageview.
any help would be appreciated.
This may be base64 encoding; at least it looks like the right mix of characters. The specific webservice docs should tell you more about the message format.
Assuming it is, and that one image is broken into multiple <imageByte /> tags, combine the contents into one long string. You can then use Base64.decode to get a byte[], and BitmapFactory.decodeByteArray to get a Bitmap handle, which you pass to ImageView.setImageBitmap
Hope this helps,
Phil Lello

Categories

Resources