I have searched but for some answers but may be my fault couldn't find my desired answer.Now below what i am trying:
I am trying to upload an image like of a status or a post or any profile pic.Profile pic will be small and status or any post image will be big
. Now what i want to do:
1.
I am converting the image to string text and uploading it to datastore and it's limit is 1Mbyte.So i want to check while uploading image that it doesn't cross limit.
2.
I want to check that the image is of png format.If it is not then won't upload.Show a Toast.Can i convert image there?? :(
3.
If user is uploading image of suppose 700kbyte but the profile pic is small i.e 100kbyte will be enough for profile pic then i can compress the pic to my defined size and then upload it to datastore.It may remain 700kbyte if it is for status image.
I am converting image to string and uploading it to datastore and again converting back to image while showing it in my app.My code
:
public static String imageToStringConverter(Bitmap image){
ByteArrayOutputStream stream = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
String imageToString = Base64.encodeToString(byteArray, Base64.NO_WRAP);
return imageToString;
}
public static Bitmap stringToimageConverter(String imageString){
byte[] stringTobyte = Base64.decode(imageString, Base64.NO_WRAP);
Bitmap bmp = BitmapFactory.decodeByteArray(stringTobyte, 0, stringTobyte.length);
return bmp;
}
Now the problem i am facing
:
1
.When i am uploading the image it is taking time.So should i use asynctask while uploading after converting the image to my desired size??
2
.When i first enter into my app ,i have shown profile pic i.e if i log into my account it will fetch an image for profile from datastore.But it is taking much time and my log in seems to be lengthy.