rozdoum / social-app-android

Build your social app for Android with the code template that includes the following key features for social networks as likes, comments, posts, image uploads, etc.
Apache License 2.0
450 stars 266 forks source link

inclusion of image size reduction code #96

Closed muhammadkamranlatifraza closed 4 years ago

muhammadkamranlatifraza commented 4 years ago

I think its solution should also be included in

muhammadkamranlatifraza commented 4 years ago

i made it work by googling it myself.......

new code here DataBaseHelper.java........................... // // //

public UploadTask uploadImage(Uri uri, String imageTitle) {
    StorageReference riversRef = getStorageReference().child(IMAGES_STORAGE_KEY + "/" + imageTitle);
    // Create file metadata including the content type
    StorageMetadata metadata = new StorageMetadata.Builder()
            .setCacheControl("max-age=7776000, Expires=7776000, public, must-revalidate")
            .build();
    Bitmap b = null;
    try {
        b = MediaStore.Images.Media.getBitmap(context.getContentResolver(), uri);
    } catch (IOException e) {
        e.printStackTrace();
    }
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    b.compress(Bitmap.CompressFormat.JPEG, 25, os);
    byte[] data = os.toByteArray();
    //uploading the image
    return riversRef.putBytes(data, metadata);
}

as far as i check it... the quality was not that damaged but size was reduced very effectively....