I'm working on android to make an app that able to upload some photos to server. My problem here is when I want to completely remove an image from the list. I can remove the view from image view but when I upload the image. I got two image, one is the previous photo and another is the last photo I set on the image after remove. (Notes : image resources are from gallery). Below are my codes
Code to set a photo to image view
if(image.getDrawable() == null)
{
image.setImageBitmap(imageUpload);
imageUpload.compress(Bitmap.CompressFormat.JPEG, 100, baos);
image_data = baos.toByteArray();
encoded_image_1 = Base64.encodeBytes(image_data);
}
else if(image2.getDrawable() == null)
{
image2.setImageBitmap(imageUpload);
imageUpload.compress(Bitmap.CompressFormat.JPEG, 100, baos);
image_data = baos.toByteArray();
encoded_image_2 = Base64.encodeBytes(image_data);
}
else if(image3.getDrawable() == null)
{
image3.setImageBitmap(imageUpload);
imageUpload.compress(Bitmap.CompressFormat.JPEG, 100, baos);
image_data = baos.toByteArray();
encoded_image_3 = Base64.encodeBytes(image_data);
}
Code to remove image
else if(image3.getDrawable() != null)
{
image3.setImageBitmap(null);
encoded_image_3 = null;
}
else if(image2.getDrawable() != null)
{
image2.setImageBitmap(null);
encoded_image_2 = null;
}
else if(image.getDrawable() != null)
{
image.setImageBitmap(null);
encoded_image_1 = null;
}
Code to upload image
params_p.add(new BasicNameValuePair("image_1", encoded_image_1));
params_p.add(new BasicNameValuePair("image_2", encoded_image_2));
params_p.add(new BasicNameValuePair("image_3", encoded_image_3));
I appreciate any help from everyone, thanks.
FileBodyto send images to server, notBase64, this is much faster and more efficient