android: possible fix for bitmap recycle errors
authorXeli
Tue, 22 May 2012 00:41:26 +0200
changeset 7107 1982e702ed2f
parent 7106 aacb90365d3d
child 7108 eaef11c0d039
child 7109 af3a43a46f21
child 7110 c91d33837b0d
android: possible fix for bitmap recycle errors
project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Datastructures/FrontendDataUtils.java
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Datastructures/FrontendDataUtils.java	Tue May 22 00:40:43 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Datastructures/FrontendDataUtils.java	Tue May 22 00:41:26 2012 +0200
@@ -32,6 +32,7 @@
 import android.content.Context;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
+import java.nio.ByteBuffer;
 
 public class FrontendDataUtils {
 
@@ -95,8 +96,11 @@
 			Bitmap b = BitmapFactory.decodeFile(pathPrefix + s + ".png");//create a full path - decode to to a bitmap
 			int width = b.getWidth();
 			if(b.getHeight() > width){//some pictures contain more 'frames' underneath each other, if so we only use the first frame
-				Bitmap tmp = Bitmap.createBitmap(b, 0, 0, width, width);
-				b.recycle();
+                                Bitmap tmp = Bitmap.createBitmap(width, width, b.getConfig());
+                                int[] pixels = new int[width * width];
+                                b.getPixels(pixels, 0,width,0,0,width,width);
+				tmp.setPixels(pixels,0,width,0,0,width,width);
+                                b.recycle();
 				b = tmp;
 			}
 			map.put("img", b);