Is there any way to store image files in firebase using Java api to be used for android application?
I have read this thread Can I store image files in firebase using Java API and still there is no answer. I know that there is an official api for it, called firepano here is the link https://github.com/firebase/firepano but it is for Javascript library.
is there any solution for Java library??
I used this code and now it's working:
Bitmap bmp = BitmapFactory.decodeResource(getResources(),
R.drawable.chicken);//your image
ByteArrayOutputStream bYtE = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, bYtE);
bmp.recycle();
byte[] byteArray = bYtE.toByteArray();
String imageFile = Base64.encodeToString(byteArray, Base64.DEFAULT);
Related
I was wondering if it's possible to upload an image on the "search by image" page using JSON or JSOUP in Android without using any Google API. Thanks in advance
Yes it is possible to convert an image in Base64 string and send to server using Json or any other way.
e.g.
Bitmap bitmap=BitmapFactory.decodeResource(getResources(),R.drawable.facebook);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 70, stream); byte[] byteArray = stream.toByteArray();
String encodedImage = Base64.encodeToString(byteArray,Base64.DEFAULT);
Currently, I'm working in an Android application project at my University, that post image to a web-service and using OpenCV to process this image in some way. In android, I convert a bitmap to byte array like this:
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG, 100, byteArrayOutputStream);
byte[] byteData = byteArrayOutputStream.toByteArray();
Then, how can I convert that byteData into bitmap again in C++ in web-service in order to use it in image processing?
I'm not so good in C++, please help.
I need to store in Database images chosen from gallery. My firt idea was convert Bitmap to String and store String in Database, but now I am reading other post: saving image clicked from camera or loaded from gallery in database and retrieving it and there is suggested using byte array.
Could someone explain me diffrence, which idea is better? Maybe something else?
I just start, but I would like to write it possibly correctly.
The standard way to store an image as a byte[] in a BLOB field. Another possibility - with some overhead - is to store a Base64-encoded string.
You can use the Base64 Android class:
String encodedImage = Base64.encodeToString(byteArrayImage, Base64.DEFAULT);
You'll have to convert your image into a byte array though. Here's an example:
Bitmap bm = BitmapFactory.decodeFile("/path/to/image.jpg");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); //bm is the bitmap object
byte[] b = baos.toByteArray();
If you're using an older SDK library (because you want it to work on phones with older versions of the OS) you won't have the Base64 class packaged in (since it just came out in API level 8 aka version 2.2).
Check this article out for a work-around:
http://androidcodemonkey.blogspot.com/2010/03/how-to-base64-encode-decode-android.html
I'm uploading JPG image as byte[] but Bitmap strips of EXIF before converting to byte[]. How do I upload raw jpg without converting it to Bitmap?
File imagefile = new File(filepath + "DSC00021.jpg");
FileInputStream fis = new FileInputStream(imagefile);
Bitmap bi = BitmapFactory.decodeStream(fis); // EXIF info lost
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPG, 100, baos);
byte[] data = baos.toByteArray();
p.s. I don't want to use any 3rd party library. ExifInterface can only write to file and not streams/byte arrays.
Above code will not work most cases. In case if you want to decode large size image you will get "out of memory error". Decode using bitmpafactory options.
Convert the file to bitmap by
Bitmap bi = BitmapFactory.decode(filepath + "DSC00021.jpg");
You can specify options too, look at API documentation
Or if you want to exchange the meta data from one file to another, sanselan will probably be the best choice. This would be much helpful when you manipulating the image, for example re-size.
The sample code will guide you in a right direction.
I want to upload an image to my website via my android app so for that i want to convert my image to Byte[].
i have used the following code but not work for me..
ByteArrayOutputStream bos=new ByteArrayOutputStream();
bm.compress(CompressFormat.JPEG,0, bos);
byte[] data=bos.toByteArray();
So please share with me any other way to convert an Image to Byte[]..
Use ByteBuffer:
array = new byte[w*h*4];
Buffer dst = ByteBuffer.wrap(array);
bmp.copyPixelsToBuffer(dst);
and use array the way you want...