use Matrix for scaling, remove one intermediate bitmap
This commit is contained in:
parent
ef5807ba3c
commit
e85ca6463a
1 changed files with 10 additions and 10 deletions
|
@ -23,6 +23,9 @@ import android.graphics.Bitmap.Config;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
|
import android.graphics.RectF;
|
||||||
|
import android.graphics.Matrix;
|
||||||
|
import android.graphics.Matrix.ScaleToFit;
|
||||||
|
|
||||||
|
|
||||||
public class SQLiteTileSource implements ITileSource {
|
public class SQLiteTileSource implements ITileSource {
|
||||||
|
@ -299,16 +302,13 @@ public class SQLiteTileSource implements ITileSource {
|
||||||
int delta_px = scaledSize * offset_x;
|
int delta_px = scaledSize * offset_x;
|
||||||
int delta_py = scaledSize * offset_y;
|
int delta_py = scaledSize * offset_y;
|
||||||
|
|
||||||
Bitmap xn = Bitmap.createBitmap(metaTile,
|
RectF src = new RectF(0.5f, 0.5f,
|
||||||
delta_px,
|
scaledSize + 2 * margin - 0.5f, scaledSize + 2 * margin - 0.5f);
|
||||||
delta_py,
|
RectF dest = new RectF(0, 0, tileSize, tileSize);
|
||||||
scaledSize + 2 * margin,
|
Matrix m = new Matrix();
|
||||||
scaledSize + 2 * margin);
|
m.setRectToRect(src, dest, Matrix.ScaleToFit.FILL);
|
||||||
metaTile.recycle();
|
return Bitmap.createBitmap(metaTile, delta_px, delta_py,
|
||||||
int scaleto = tileSize + ((2 * margin) << n);
|
scaledSize + 2*margin-1, scaledSize + 2*margin-1, m, true);
|
||||||
Bitmap scaled = Bitmap.createScaledBitmap(xn,scaleto,scaleto,true);
|
|
||||||
xn.recycle();
|
|
||||||
return Bitmap.createBitmap(scaled, (margin << n), (margin << n), tileSize, tileSize);
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue