Skip to content

Commit

Permalink
fix when sampleSize changed cannot use value immediately
Browse files Browse the repository at this point in the history
  • Loading branch information
penfeizhou committed Feb 23, 2024
1 parent 46b4e55 commit 3d3d304
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -458,7 +456,7 @@ public void run() {
}
});
}
return sampleSizeChanged;
return sample;
}

protected int getDesiredSample(int desiredWidth, int desiredHeight) {
Expand Down

0 comments on commit 3d3d304

Please sign in to comment.