Render themes: PNG scaling, fix #595
This commit is contained in:
@@ -113,10 +113,25 @@ public abstract class CanvasAdapter {
|
||||
*/
|
||||
protected abstract Bitmap decodeBitmapImpl(InputStream inputStream) throws IOException;
|
||||
|
||||
/**
|
||||
* Create {@link Bitmap} from InputStream.
|
||||
*
|
||||
* @param inputStream the input stream
|
||||
* @param width requested width (0: no change)
|
||||
* @param height requested height (0: no change)
|
||||
* @param percent requested scale percent (100: no change)
|
||||
* @return the bitmap
|
||||
*/
|
||||
protected abstract Bitmap decodeBitmapImpl(InputStream inputStream, int width, int height, int percent) throws IOException;
|
||||
|
||||
public static Bitmap decodeBitmap(InputStream inputStream) throws IOException {
|
||||
return g.decodeBitmapImpl(inputStream);
|
||||
}
|
||||
|
||||
public static Bitmap decodeBitmap(InputStream inputStream, int width, int height, int percent) throws IOException {
|
||||
return g.decodeBitmapImpl(inputStream, width, height, percent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create SVG {@link Bitmap} from InputStream.
|
||||
*
|
||||
@@ -182,7 +197,7 @@ public abstract class CanvasAdapter {
|
||||
if (src.toLowerCase(Locale.ENGLISH).endsWith(".svg"))
|
||||
bitmap = decodeSvgBitmap(inputStream, width, height, percent);
|
||||
else
|
||||
bitmap = decodeBitmap(inputStream);
|
||||
bitmap = decodeBitmap(inputStream, width, height, percent);
|
||||
inputStream.close();
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016 Longri
|
||||
* Copyright 2018 devemux86
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@@ -65,4 +66,6 @@ public interface Bitmap {
|
||||
boolean isValid();
|
||||
|
||||
byte[] getPngEncodedData();
|
||||
|
||||
void scaleTo(int width, int height);
|
||||
}
|
||||
|
||||
63
vtm/src/org/oscim/utils/GraphicUtils.java
Normal file
63
vtm/src/org/oscim/utils/GraphicUtils.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2018 devemux86
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.utils;
|
||||
|
||||
/**
|
||||
* Utility class for graphics operations.
|
||||
*/
|
||||
public final class GraphicUtils {
|
||||
|
||||
/**
|
||||
* Given the original image size, as well as width, height, percent parameters,
|
||||
* can compute the final image size.
|
||||
*
|
||||
* @param picWidth original image width
|
||||
* @param picHeight original image height
|
||||
* @param scaleFactor scale factor to screen DPI
|
||||
* @param width requested width (0: no change)
|
||||
* @param height requested height (0: no change)
|
||||
* @param percent requested scale percent (100: no change)
|
||||
*/
|
||||
public static float[] imageSize(float picWidth, float picHeight, float scaleFactor, int width, int height, int percent) {
|
||||
float bitmapWidth = picWidth * scaleFactor;
|
||||
float bitmapHeight = picHeight * scaleFactor;
|
||||
|
||||
float aspectRatio = picWidth / picHeight;
|
||||
|
||||
if (width != 0 && height != 0) {
|
||||
// both width and height set, override any other setting
|
||||
bitmapWidth = width;
|
||||
bitmapHeight = height;
|
||||
} else if (width == 0 && height != 0) {
|
||||
// only width set, calculate from aspect ratio
|
||||
bitmapWidth = height * aspectRatio;
|
||||
bitmapHeight = height;
|
||||
} else if (width != 0 && height == 0) {
|
||||
// only height set, calculate from aspect ratio
|
||||
bitmapHeight = width / aspectRatio;
|
||||
bitmapWidth = width;
|
||||
}
|
||||
|
||||
if (percent != 100) {
|
||||
bitmapWidth *= percent / 100f;
|
||||
bitmapHeight *= percent / 100f;
|
||||
}
|
||||
|
||||
return new float[]{bitmapWidth, bitmapHeight};
|
||||
}
|
||||
|
||||
private GraphicUtils() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user