Manipulating large images on a Canvas to maintain aspect ratios results in outofmemory issues
<p>I'm trying to load a background image for a game as well as some smaller images, placing them on a Canvas, and letting people interact with the smaller overlayed images (like move, rotate)</p>

<p>In order to maintain aspect ratio (e.g. 5:3) I tried loading in the images as a bitmap and resizing them myself.  The idea was to do cropping/letter-boxing for the background according to the canvas's width/height, and maintain the correct ratio of size for the smaller images. </p>

<pre><code>Bitmap originalBitmap = BitmapFactory.decodeResource(getResources(), resourceImg);
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg2, 0, 0, width, height, matrix, true);
</code></pre>

<p>In order to cater for tablets/phones i have a background PNG background image at 1600x1000 and 200kb.</p>

<p>However I am now struggling with out of memory issues due to the bitmap being 1600x1000x4byte=6.4 mb of ram and more when it tries to resize.
(I am using the emulator at the moment when these issues occur)</p>

<p>I decided to change it to use canvas.setBackgroundResource</p>

<pre><code>    SceneCanvas sceneCanvas = (SceneCanvas) findViewById(R.id.the_canvas);
    sceneCanvas.setBackgroundResource(R.drawable.my_scene_1600x900);
</code></pre>

<p>This works well, except it fills the screen and does not maintain aspect ratio.</p>

<p>Is there a way to set the background maintaining aspect ratio?  Or have I just gone down the wrong route completely and should use ImageViews and render to the canvas somehow to avoid OutOfMemory issues</p>
