Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix 1059 Converting large image to pdf causes app to crash #1060

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

deepoceansame
Copy link
Contributor

Description

Please include a summary of the change and which issue is fixed. List any dependencies that are required for this change.
If there are any UI change, please include the screenshots also.

Created a new method in ImageUtils called pathToByteStream and compress the image in the method. Then, use the byte stream to get itext.Image.

Fixes #1059

Type of change

Just put an x in the [] which are valid.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

  • ./gradlew assembleDebug assembleRelease
  • ./gradlew checkstyle

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

@codeclimate
Copy link

codeclimate bot commented Apr 23, 2022

Code Climate has analyzed commit 3e5f12b and detected 0 issues on this pull request.

View more on Code Climate.

@codegsaini
Copy link
Contributor

@deepoceansame Issue #1044 and #1059 are same issue but have different solutions through Pull Request #1055 and #1060.

Two different PR for same issue can be described as below -

PR #1055

In this PR scale down feature of Picasso used to display small/scaled version of bitmap in targeted Imageview.

PR #1060

It compress the actual image itself.


I am excited to know -

PROs and CONs of showing scaled down version in Imageview but leaving the actual image as it is.
PROs and CONs of compressing the actual image.
PROs and CONs of both solution if combined.

@deepoceansame
Copy link
Contributor Author

I tried the picasso to do the filter enhancement part of issue #1044 with

Picasso.with(this)
      .load(mImagePaths.get(mCurrentImage))
      .resize(780, 1200)
      .onlyScaleDown()
      .into(photoEditorView.getSource());

and this causes NLP.

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.Bitmap android.graphics.drawable.BitmapDrawable.getBitmap()' on a null object reference
        at ja.burhanrashid52.photoeditor.FilterImageView.getBitmap(FilterImageView.java:127)
        at ja.burhanrashid52.photoeditor.FilterImageView.setImageDrawable(FilterImageView.java:98)
        at com.squareup.picasso.PicassoDrawable.setPlaceholder(PicassoDrawable.java:61)
        at com.squareup.picasso.RequestCreator.into(RequestCreator.java:664)
        at com.squareup.picasso.RequestCreator.into(RequestCreator.java:601)
        at swati4star.createpdf.activity.ImageEditor.changeAndShowImageCount(ImageEditor.java:159)
        at swati4star.createpdf.activity.ImageEditor.initValues(ImageEditor.java:105)
        at swati4star.createpdf.activity.ImageEditor.onCreate(ImageEditor.java:88)
        at android.app.Activity.performCreate(Activity.java:8214)
        at android.app.Activity.performCreate(Activity.java:8202)

Picasso seems to call ImageView.setImageDrawable(null) first.
Unlike other ImageView, FilterImageView.setImageDrawable(null) is called and causes NLP.

   @Override
    public void setImageDrawable(@Nullable Drawable drawable) {
        super.setImageDrawable(drawable);
        if (mOnImageChangedListener != null) {
            mOnImageChangedListener.onBitmapLoaded(getBitmap());
        }
    }

   Bitmap getBitmap() {
        return ((BitmapDrawable) getDrawable()).getBitmap();
    }

It sets drawable to null and call getBitmap of the null drawable.

@deepoceansame
Copy link
Contributor Author

deepoceansame commented Apr 25, 2022

I also tried adding noPlaceholder() or placeholder(photoEditorView.getSource().getDrawable()) to avoid NLP

        Picasso.with(this)
                .load(mImagePaths.get(mCurrentImage))
                .resize(780, 1200)
                .onlyScaleDown()
//             .placeholder(photoEditorView.getSource().getDrawable())
                .noPlaceholder()
                .into(photoEditorView.getSource());

but the filter view only show the first image.(the two adds has same effect)
I will try converting mImagePaths.get(mCurrentImage) to res Id or drawable later

@deepoceansame
Copy link
Contributor Author

PROs and CONs of showing scaled down version in Imageview but leaving the actual image as it is.

pros of using picasso: writing less code
cons: Loading image using picasso can also make image vague. Increasing width or height of resize() can increase quality of the image in imageView. And it is hard to get mid product like bitmap or byteArray using picasso for creating itext.Image object for creating pdf. I didn't find big difference on memory usage between compressing pictures and using picasso.

PROs and CONs of compressing the actual image.

pros: Easy to get bitmap and byteArray to create Image object for creating pdf.
cons: Adding one more function.

PROs and CONs of both solution if combined.

pros: Compressing image can get bitmap and byteArray for creating pdf.
cons: no cons

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Converting large image to pdf causes app to crash
2 participants