KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
For readibility, I posted the code examples that my solutions refer to first, and thenI listed the explanations of my solutions in a numerical list. I have been struggling with this for a while now. I have done much reading, asked questions on here, and experimented; but have not come up with a decent solution. I need to read variously sized images from input streams, and display them with as high of quality as my memory constraints allow. Below are the options I have considered, none of which seem great to me. Any help or input would be greatly appreciated. public class NativeTest extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); double nativeUsage = Debug.getNativeHeapAllocatedSize(); Log.i("memory", nativeUsage+""); } } double getAvailableMemory() { //current heap size double heapSize = Runtime.getRuntime().totalMemory(); //amount available in heap double heapRemaining = Runtime.getRuntime().freeMemory(); double nativeUsage = Debug.getNativeHeapAllocatedSize(); double memoryAvailable = Runtime.getRuntime().maxMemory() - (heapSize - heapRemaining) - nativeUsage; return memoryAvailable; } Bitmap createImageTrialAndError(InputStream stream) { Bitmap image = null; int dowsample = 1; while(image == null) { try { Options opts = new Options(); opts.inSampleSize = downsample; image = BitmapFactory.decodeStream(imgStream, null, opts); } catch (OutOfMemoryError ome) { downsample = downsample * 2; Log.i("out of mem", "try using: " + downsample); } } return image; } The ideal solution would be if Bitmap had a Bitmap.drawBitmap(inputstream...) method. This would allow me to draw from the inputstream without having to allocate memory for the Bit
Tags (comma-separated)
Save Edits
Cancel