In Android, why is my combined bitmap blank?

I'm working with a set of layered images (think stacked) and I need to combine them into one element.

I'm basing my solution off Combine multiple bitmap into one

//send a map to the method that has my stored image locations in order
private Bitmap combineImageIntoOne(NavigableMap<Integer, String> layerImages) {
        //size of my bitmaps
        int w = 400, h = 400;
        //bitmap placeholder
        Bitmap productIndex = null;

        //flattened layers
        Bitmap temp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
        //canvas to write layers to
        Canvas canvas = new Canvas(temp);
        int top = 0;
        for (Map.Entry<Integer, String> e : layerImages.entrySet()) {

            //create the layer bitmap
            productIndex = decodeSampledBitmapFromResource(getResources(), e.getValue(), 400, 400);

            //add layer to canvas
            canvas.drawBitmap(productIndex, 0f, top, null);
        }

        //convert temp to a BitmapDrawable
        Drawable d = new BitmapDrawable(getResources(),temp);

        //set my image view to have the flattened image
        carBase.setImageDrawable(d);

        return temp;
    }

The decodeSampledBitmapFromResource come from the Android docs about loading large bitmaps: Loading Large Bitmaps Efficiently You can review the code on that doc to see what I"m doing. I didn't edit the Android code much.

I've been using the Android code just fine to add layers to the FrameLayout but ended up running out of memory when the layers starting getting pretty high in number. This combining method is being used to conserve memory space.

Any ideas why the final bitmap doesn't have any content?

Answers


Reference LINK <-------------------------

public Bitmap combineImages(Bitmap c, Bitmap s) { // can add a 3rd parameter 'String loc' if you want to save the new image - left some code to do that at the bottom 
    Bitmap cs = null; 

    int width, height = 0; 

    if(c.getWidth() > s.getWidth()) { 
      width = c.getWidth() + s.getWidth(); 
      height = c.getHeight(); 
    } else { 
      width = s.getWidth() + s.getWidth(); 
      height = c.getHeight(); 
    } 

    cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); 

    Canvas comboImage = new Canvas(cs); 

    comboImage.drawBitmap(c, 0f, 0f, null); 
    comboImage.drawBitmap(s, c.getWidth(), 0f, null); 

    // this is an extra bit I added, just incase you want to save the new image somewhere and then return the location 
    /*String tmpImg = String.valueOf(System.currentTimeMillis()) + ".png"; 

    OutputStream os = null; 
    try { 
      os = new FileOutputStream(loc + tmpImg); 
      cs.compress(CompressFormat.PNG, 100, os); 
    } catch(IOException e) { 
      Log.e("combineImages", "problem combining images", e); 
    }*/ 

    return cs; 
  } 

Need Your Help

JavaFX Scene Builder ScrollPane scrolls only few pixels

javafx javafx-2 scenebuilder

I have a small database that adds labels to a VBox, which is in AnchorPane, which belongs to ScrollPane. Technically, it works fine, except that the scroll movement is minimal. Moving from top to b...

FlyoutNavigation - iOS

c# ios uiviewcontroller uinavigationcontroller xamarin

I am trying to work with the Clancey FlyoutNavigation, however I can't get it to perform a segue.