From daa0d913f792939cdf546db7f962b40cc82bd867 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 7 Jul 2013 16:39:54 +0200 Subject: [PATCH 1/3] Fix icon rendering --- .../osmand/plus/render/RenderingIcons.java | 47 ++++++++++++------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/render/RenderingIcons.java b/OsmAnd/src/net/osmand/plus/render/RenderingIcons.java index 177775d272..e5d5197d10 100644 --- a/OsmAnd/src/net/osmand/plus/render/RenderingIcons.java +++ b/OsmAnd/src/net/osmand/plus/render/RenderingIcons.java @@ -1,8 +1,7 @@ package net.osmand.plus.render; -import java.io.ByteArrayOutputStream; -import java.io.InputStream; import java.lang.reflect.Field; +import java.nio.ByteBuffer; import java.util.LinkedHashMap; import java.util.Map; @@ -14,6 +13,7 @@ import org.apache.commons.logging.Log; import android.content.Context; import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.graphics.drawable.Drawable; import android.util.DisplayMetrics; import android.view.WindowManager; @@ -42,20 +42,30 @@ public class RenderingIcons { return null; try { - final InputStream inputStream = ctx.getResources().openRawResource(resId.intValue()); - final ByteArrayOutputStream proxyOutputStream = new ByteArrayOutputStream(1024); - final byte[] ioBuffer = new byte[1024]; - int bytesRead; - while ((bytesRead = inputStream.read(ioBuffer)) >= 0) { - proxyOutputStream.write(ioBuffer, 0, bytesRead); + Bitmap ic = getIcon(ctx, s); + if(ic == null) { + return null; } - inputStream.close(); - final byte[] bitmapData = proxyOutputStream.toByteArray(); - log.info("Icon data length is " + bitmapData.length); //$NON-NLS-1$ - - //if(android.graphics.BitmapFactory.decodeByteArray(bitmapData, 0, bitmapData.length) == null) - // throw new Exception(); - return bitmapData; + ByteBuffer buf = ByteBuffer.allocate(ic.getByteCount()); + ic.copyPixelsToBuffer(buf); + return buf.array(); +// final InputStream inputStream = ctx.getResources().openRawResource(resId.intValue()); +// final ByteArrayOutputStream proxyOutputStream = new ByteArrayOutputStream(1024); +// final byte[] ioBuffer = new byte[1024]; +// int bytesRead; +// while ((bytesRead = inputStream.read(ioBuffer)) >= 0) { +// proxyOutputStream.write(ioBuffer, 0, bytesRead); +// } +// inputStream.close(); +// final byte[] bitmapData = proxyOutputStream.toByteArray(); +// log.info("Icon data length is " + bitmapData.length); //$NON-NLS-1$ +// Bitmap dm = android.graphics.BitmapFactory.decodeByteArray(bitmapData, 0, bitmapData.length) ; +// if(dm != null){ +// System.out.println("IC " + dm.getHeight() + " " + dm.getWidth()); +// } +// //if(android.graphics.BitmapFactory.decodeByteArray(bitmapData, 0, bitmapData.length) == null) +// // throw new Exception(); +// return bitmapData; } catch(Throwable e) { log.error("Failed to get byte stream from icon", e); //$NON-NLS-1$ return null; @@ -87,7 +97,12 @@ public class RenderingIcons { WindowManager wmgr = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE); wmgr.getDefaultDisplay().getMetrics(dm); } - Bitmap bmp = UnscaledBitmapLoader.loadFromResource(ctx.getResources(), resId.intValue(), null, dm); +// BitmapFactory.Options options = new BitmapFactory.Options(); +// options.inScaled = false; +// options.inTargetDensity = dm.densityDpi; +// options.inDensity = dm.densityDpi; + Bitmap bmp = BitmapFactory.decodeResource(ctx.getResources(), resId, null); +// Bitmap bmp = UnscaledBitmapLoader.loadFromResource(ctx.getResources(), resId.intValue(), null, dm); iconsBmp.put(s, bmp); } else { iconsBmp.put(s, null); From 8ebf3870c898c73b40548db63df9cf49668f8fcd Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 7 Jul 2013 16:40:02 +0200 Subject: [PATCH 2/3] Fix icon rendering --- .../osmand/plus/render/RenderingIcons.java | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/render/RenderingIcons.java b/OsmAnd/src/net/osmand/plus/render/RenderingIcons.java index e5d5197d10..b044b6526c 100644 --- a/OsmAnd/src/net/osmand/plus/render/RenderingIcons.java +++ b/OsmAnd/src/net/osmand/plus/render/RenderingIcons.java @@ -1,7 +1,8 @@ package net.osmand.plus.render; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; import java.lang.reflect.Field; -import java.nio.ByteBuffer; import java.util.LinkedHashMap; import java.util.Map; @@ -42,30 +43,30 @@ public class RenderingIcons { return null; try { - Bitmap ic = getIcon(ctx, s); - if(ic == null) { - return null; +// Bitmap ic = getIcon(ctx, s); +// if(ic == null) { +// return null; +// } +// ByteBuffer buf = ByteBuffer.allocate(ic.getByteCount()); +// ic.copyPixelsToBuffer(buf); +// return buf.array(); + final InputStream inputStream = ctx.getResources().openRawResource(resId.intValue()); + final ByteArrayOutputStream proxyOutputStream = new ByteArrayOutputStream(1024); + final byte[] ioBuffer = new byte[1024]; + int bytesRead; + while ((bytesRead = inputStream.read(ioBuffer)) >= 0) { + proxyOutputStream.write(ioBuffer, 0, bytesRead); } - ByteBuffer buf = ByteBuffer.allocate(ic.getByteCount()); - ic.copyPixelsToBuffer(buf); - return buf.array(); -// final InputStream inputStream = ctx.getResources().openRawResource(resId.intValue()); -// final ByteArrayOutputStream proxyOutputStream = new ByteArrayOutputStream(1024); -// final byte[] ioBuffer = new byte[1024]; -// int bytesRead; -// while ((bytesRead = inputStream.read(ioBuffer)) >= 0) { -// proxyOutputStream.write(ioBuffer, 0, bytesRead); -// } -// inputStream.close(); -// final byte[] bitmapData = proxyOutputStream.toByteArray(); -// log.info("Icon data length is " + bitmapData.length); //$NON-NLS-1$ -// Bitmap dm = android.graphics.BitmapFactory.decodeByteArray(bitmapData, 0, bitmapData.length) ; -// if(dm != null){ -// System.out.println("IC " + dm.getHeight() + " " + dm.getWidth()); -// } -// //if(android.graphics.BitmapFactory.decodeByteArray(bitmapData, 0, bitmapData.length) == null) -// // throw new Exception(); -// return bitmapData; + inputStream.close(); + final byte[] bitmapData = proxyOutputStream.toByteArray(); + log.info("Icon data length is " + bitmapData.length); //$NON-NLS-1$ + Bitmap dm = android.graphics.BitmapFactory.decodeByteArray(bitmapData, 0, bitmapData.length) ; + if(dm != null){ + System.out.println("IC " + dm.getHeight() + " " + dm.getWidth()); + } + //if(android.graphics.BitmapFactory.decodeByteArray(bitmapData, 0, bitmapData.length) == null) + // throw new Exception(); + return bitmapData; } catch(Throwable e) { log.error("Failed to get byte stream from icon", e); //$NON-NLS-1$ return null; From 2d8fe2ac7e81d0ac3507a00d42fc4101732ef1e2 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 7 Jul 2013 16:44:49 +0200 Subject: [PATCH 3/3] Fix icon rendering --- OsmAnd/src/net/osmand/plus/render/RenderingIcons.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/render/RenderingIcons.java b/OsmAnd/src/net/osmand/plus/render/RenderingIcons.java index b044b6526c..a3a0f48d40 100644 --- a/OsmAnd/src/net/osmand/plus/render/RenderingIcons.java +++ b/OsmAnd/src/net/osmand/plus/render/RenderingIcons.java @@ -62,7 +62,7 @@ public class RenderingIcons { log.info("Icon data length is " + bitmapData.length); //$NON-NLS-1$ Bitmap dm = android.graphics.BitmapFactory.decodeByteArray(bitmapData, 0, bitmapData.length) ; if(dm != null){ - System.out.println("IC " + dm.getHeight() + " " + dm.getWidth()); + System.out.println("IC " + s +" " + dm.getHeight() + "x" + dm.getWidth()); } //if(android.graphics.BitmapFactory.decodeByteArray(bitmapData, 0, bitmapData.length) == null) // throw new Exception();