Skip to content

Commit 14b1034

Browse files
committed
float value
1 parent 7a072e9 commit 14b1034

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/com/github/nowelium/titanium/module/thumbnail/ThumbnailModule.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@ public TiBlob resize(TiBlob blob){
5353

5454
@Kroll.method
5555
public TiBlob resizeTo(TiBlob blob, KrollDict args){
56-
int width = args.optInt("width", 320).intValue();
57-
int height = args.optInt("height", 480).intValue();
58-
boolean keepAspect = args.optBoolean("keepAspect", true);
59-
String mimeType = args.optString("mimeType", MIME_JPEG);
56+
final int width = args.optInt("width", 320).intValue();
57+
final int height = args.optInt("height", 480).intValue();
58+
final boolean keepAspect = args.optBoolean("keepAspect", true);
59+
final String mimeType = args.optString("mimeType", MIME_JPEG);
6060

6161
return resizeFromBlob(blob, width, height, keepAspect, mimeType);
6262
}
6363

6464
private TiBlob compress(Bitmap bitmap, CompressFormat format, String mimeType){
65-
ByteArrayOutputStream out = new ByteArrayOutputStream();
65+
final ByteArrayOutputStream out = new ByteArrayOutputStream();
6666
if(bitmap.compress(format, 80, out)){
6767
return TiBlob.blobFromData(context, out.toByteArray(), mimeType);
6868
}
@@ -90,12 +90,14 @@ private TiBlob resizeFromBlob(TiBlob blob, int width, int height, boolean keepAs
9090
}
9191

9292
private Bitmap resizeToSize(Bitmap bitmap, int targetWidth, int targetHeight, boolean preserveAspectRatio){
93-
final int imageWidth = bitmap.getWidth();
94-
final int imageHeight = bitmap.getHeight();
95-
if(imageWidth < 1){
93+
final int originalWidth = bitmap.getWidth();
94+
final int originalHeight = bitmap.getHeight();
95+
final float imageWidth = 0.0f + originalWidth;
96+
final float imageHeight = 0.0f + originalHeight;
97+
if(imageWidth < 1.0f){
9698
return Bitmap.createBitmap(bitmap, 0, 0, 0, 0);
9799
}
98-
if(imageHeight < 1){
100+
if(imageHeight < 1.0f){
99101
return Bitmap.createBitmap(bitmap, 0, 0, 0, 0);
100102
}
101103

@@ -116,7 +118,7 @@ private Bitmap resizeToSize(Bitmap bitmap, int targetWidth, int targetHeight, bo
116118
// Don't preserve the aspect ratio.
117119
projectTo.postScale(targetWidth / imageWidth, targetHeight / imageHeight);
118120
}
119-
return Bitmap.createBitmap(bitmap, 0, 0, imageWidth, imageHeight, projectTo, true);
121+
return Bitmap.createBitmap(bitmap, 0, 0, originalWidth, originalHeight, projectTo, true);
120122
}
121123

122124
}

0 commit comments

Comments
 (0)