Skip to content

Commit c3051f6

Browse files
authored
Merge pull request cats-oss#443 from Keheira/master
Get size of rescaled image
2 parents 342297c + 27e9a9e commit c3051f6

File tree

1 file changed

+15
-0
lines changed
  • library/src/main/java/jp/co/cyberagent/android/gpuimage

1 file changed

+15
-0
lines changed

library/src/main/java/jp/co/cyberagent/android/gpuimage/GPUImage.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public enum ScaleType {CENTER_INSIDE, CENTER_CROP}
6767
private GPUImageFilter filter;
6868
private Bitmap currentBitmap;
6969
private ScaleType scaleType = ScaleType.CENTER_CROP;
70+
private int scaleWidth, scaleHeight;
7071

7172
/**
7273
* Instantiates a new GPUImage object.
@@ -251,6 +252,18 @@ public void setScaleType(ScaleType scaleType) {
251252
requestRender();
252253
}
253254

255+
/**
256+
* This gets the size of the image. This makes it easier to adjust
257+
* the size of your imagePreview to the the size of the scaled image.
258+
*
259+
* @param width The bitmap width
260+
* @param height The bitmap height
261+
* @return array with width and height of bitmap image
262+
*/
263+
public int[] getScaleSize() {
264+
return new int[] {scaleWidth, scaleHeight};
265+
}
266+
254267
/**
255268
* Sets the rotation of the displayed image.
256269
*
@@ -729,6 +742,8 @@ private int[] getScaleSize(int width, int height) {
729742
newWidth = outputWidth;
730743
newHeight = (newWidth / width) * height;
731744
}
745+
scaleWidth = Math.round(newWidth);
746+
scaleHeight = Math.round(newHeight);
732747
return new int[]{Math.round(newWidth), Math.round(newHeight)};
733748
}
734749

0 commit comments

Comments
 (0)