Reputation: 324
I am using Samsung A52 to take some images with camera not my firebase app and save them, after that i would upload these images to firebase, iam compressing them before upload .
now after images were uploaded i checked and found that they are -90
rotated, not all images rotated , some were rotated and some weren't;
any idea?
or is there any possibly to detect while loading images from firebase if it rotated to retotate is to 90
?
function to upload images after getting them from gallery.
for (uploadCount = 0; uploadCount < ImageList.size(); uploadCount++) {
String imagePath = productRef.child(UID).child("images").push().getKey();
Uri IndividualImage = ImageList.get(uploadCount);
assert imagePath != null;
StorageReference ImageName = productImagesRef.child(UID).child(imagePath);
//Compress Images
Bitmap bmp = null;
try {
bmp = MediaStore.Images.Media.getBitmap(getContentResolver(), IndividualImage);
} catch (IOException e) {
e.printStackTrace();
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
assert bmp != null;
bmp.compress(Bitmap.CompressFormat.JPEG, 25, baos);
byte[] data = baos.toByteArray();
//End of compressing
//start on uploading compressed
ImageName.putBytes(data).addOnSuccessListener(taskSnapshot -> ImageName.getDownloadUrl()
.addOnSuccessListener(uri -> {
String url = String.valueOf(uri);
StoreLink(url, imagePath);
})).addOnProgressListener(snapshot1 -> {
double progress = (100.0* snapshot1.getBytesTransferred()/snapshot1.getTotalByteCount());
loadingDialog.setMessage("صورة رقم " + (count+ 1) + " -->> " +(int) progress + "%");
});
}
Upvotes: 3
Views: 122
Reputation: 324
So i self Solved it and this was my solution:
i added a rotate button to the layout of recyclerView item(Adapter)
, and then created an empty ArrayList to store the value or rotation degree.
i passed the arraylist to adapter which has the rotate button, now when user click on rotate a value of 90f
would be saved to arraylist with the position like this:
imageRotation.set(holder.getAdapterPosition(), "90f");
since arrayList can take (index, value)
Note: if there isn't an exiting value for the Arralist position and you skipped the position to change rotation for other item, it would crash.
and to solve this i made a for loop to populate the Arratlist with 0f
as a rotatiion degree.
for (int i = 0; i <= imageUriList.size(); i++) {
imageRotation.add(i,"0f");
}
then when user click on rotate, it would update the position value:
imageRotation.set(holder.getAdapterPosition(), "90f");
and onActivityResult of the Upload Activity:
i used this:
if (requestCode == LAUNCH_SECOND_ACTIVITY) {
if (resultCode == Activity.RESULT_OK) {
assert data != null;
imageRotationArray = data.getStringArrayListExtra("imageRotationArray");
}
}
and before the Compress image function:
// create new matrix
Matrix matrix = new Matrix();
// setup rotation degree
matrix.postRotate(Float.parseFloat(imageRotationArray.get(countRotateImage)));
bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
countRotateImage++;
Upvotes: 2