0

I am trying to insert an image to static image (soemthing like an Image inside a frame). I could get it to an extent, but couldn't put it properly in the given image.

Orange border is the frame and placeholder that needs to be inserted dynamically into a marker in my map.

enter image description here

Here is what I have tried:

    Bitmap pic = BitmapFactory.decodeResource(getResources(),
            R.drawable.bluepic);
    Bitmap orangeframe = BitmapFactory.decodeResource(getResources(),R.drawable.orangeborder);
    Bitmap out = combineImages(orangeframe, pic);

   public Bitmap combineImages(Bitmap frame, Bitmap image) 
   {

    Bitmap cs = null;
    Bitmap rs = null;

    rs = Bitmap.createScaledBitmap(frame, image.getWidth(),
            image.getHeight(), true);

    cs = Bitmap.createBitmap(rs.getWidth(), rs.getHeight(),
            Bitmap.Config.RGB_565);

    Canvas comboImage = new Canvas(cs);

    comboImage.drawBitmap(image,0, 0, null);
    comboImage.drawBitmap(rs, 0, 0, null);

    if (rs != null) {
        rs.recycle();
        rs = null;
    }
    Runtime.getRuntime().gc();

    return cs;
}

I am getting this:

enter image description here

The place holder is dynamic, the orage frame image is static. I would like to insert the image directly inside the orange image programatically.

Is this possible?

TheDevMan
  • 5,914
  • 12
  • 74
  • 144
  • I think you are trying to achieve something simple in a harsh way. I would rather use two different `ImageView`s. The first one contains the placeholder as src and the rounded-squared border as background. The second one contains just the hook. – Blackbelt Sep 19 '14 at 08:01
  • @blackbelt: The problem is that I am applying this on a marker to a map. Which is looking for an bitmap. Hence I can't apply this on a imageView. Sorry I should have written what I am trying to do clearly. – TheDevMan Sep 19 '14 at 08:04
  • The map takes only bitmap as placeholder? Not views? That's not nice. In this case I would use a bitmap for the placehoder and a path to draw the border – Blackbelt Sep 19 '14 at 08:07
  • @blackbelt: How do I do that? – TheDevMan Sep 19 '14 at 08:11
  • canvas can draw a path on a bitmap. So you probably need to have a bitmap large enough to host both. It is not trivial, but it is not that difficult either.. – Blackbelt Sep 19 '14 at 08:13
  • @blackbelt: didn't understand? can you explain? – TheDevMan Sep 19 '14 at 08:18
  • @TheDevMan can't you try and achieve this with a Layout? By overlaying the two image views on top of each other. – AndroidEnthusiast Sep 19 '14 at 11:21
  • I am not sure if this is possible. I am trying to get it on map marker..so the icon can display only bitmap – TheDevMan Sep 19 '14 at 11:23

2 Answers2

0

The orange frame is an image view right? You can overlay another image view on top of it like this:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >

<ImageView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/map_marker"/>


<ImageView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="8dp"
    android:layout_gravity="center"
    android:background="@drawable/my_placeholder"/>


</FrameLayout>
AndroidEnthusiast
  • 6,557
  • 10
  • 42
  • 56
0

You can use 9-patch for that.
http://developer.android.com/tools/help/draw9patch.html

Simply define the limits in the orange image.

And then build the hierarchy like that:

<FrameLayout 
    background="static 9patch image" >
   <ImageView
       src="dynamic image"/>
</FrameLayout>
dor506
  • 5,246
  • 9
  • 44
  • 79