diff --git a/frameanimation/src/main/java/com/github/penfeizhou/animation/FrameAnimationDrawable.java b/frameanimation/src/main/java/com/github/penfeizhou/animation/FrameAnimationDrawable.java index ecf91c5b..08b3d80a 100644 --- a/frameanimation/src/main/java/com/github/penfeizhou/animation/FrameAnimationDrawable.java +++ b/frameanimation/src/main/java/com/github/penfeizhou/animation/FrameAnimationDrawable.java @@ -183,15 +183,15 @@ public void draw(Canvas canvas) { @Override public void setBounds(int left, int top, int right, int bottom) { super.setBounds(left, top, right, bottom); - boolean sampleSizeChanged = frameSeqDecoder.setDesiredSize(getBounds().width(), getBounds().height()); + int oldSampleSize = frameSeqDecoder.getSampleSize(); + int sampleSize = frameSeqDecoder.setDesiredSize(getBounds().width(), getBounds().height()); matrix.setScale( - 1.0f * getBounds().width() * frameSeqDecoder.getSampleSize() / frameSeqDecoder.getBounds().width(), - 1.0f * getBounds().height() * frameSeqDecoder.getSampleSize() / frameSeqDecoder.getBounds().height()); - - if (sampleSizeChanged) + 1.0f * getBounds().width() * sampleSize / frameSeqDecoder.getBounds().width(), + 1.0f * getBounds().height() * sampleSize / frameSeqDecoder.getBounds().height()); + if (sampleSize != oldSampleSize) this.bitmap = Bitmap.createBitmap( - frameSeqDecoder.getBounds().width() / frameSeqDecoder.getSampleSize(), - frameSeqDecoder.getBounds().height() / frameSeqDecoder.getSampleSize(), + frameSeqDecoder.getBounds().width() / sampleSize, + frameSeqDecoder.getBounds().height() / sampleSize, Bitmap.Config.ARGB_8888); } diff --git a/frameanimation/src/main/java/com/github/penfeizhou/animation/decode/FrameSeqDecoder.java b/frameanimation/src/main/java/com/github/penfeizhou/animation/decode/FrameSeqDecoder.java index c97bd232..d7189c06 100644 --- a/frameanimation/src/main/java/com/github/penfeizhou/animation/decode/FrameSeqDecoder.java +++ b/frameanimation/src/main/java/com/github/penfeizhou/animation/decode/FrameSeqDecoder.java @@ -435,11 +435,9 @@ public int getSampleSize() { return sampleSize; } - public boolean setDesiredSize(int width, int height) { - boolean sampleSizeChanged = false; + public int setDesiredSize(int width, int height) { final int sample = getDesiredSample(width, height); if (sample != getSampleSize()) { - sampleSizeChanged = true; final boolean tempRunning = isRunning(); workerHandler.removeCallbacks(renderTask); workerHandler.post(new Runnable() { @@ -458,7 +456,7 @@ public void run() { } }); } - return sampleSizeChanged; + return sample; } protected int getDesiredSample(int desiredWidth, int desiredHeight) {