2014-09-19 49 views
0

我想插入一个图像静态图像(soemthing像一个帧内的图像)。我可以在一定程度上得到它,但不能把它正确地放在给定的图像中。插入图像给出一个图像在android

橙色边框是需要动态插入地图中标记的框架和占位符。

enter image description here

这是我曾尝试:

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; 
} 

我得到这个:

enter image description here

的占位符是动态的,ORAGE帧图像是静止的。我想以编程方式直接在橙色图像中插入图像。

这可能吗?

+0

我想你想实现的东西在恶劣的方式简单。我宁愿使用两个不同的ImageView。第一个包含占位符作为src和圆角平方的边框作为背景。第二个只包含钩子。 – Blackbelt 2014-09-19 08:01:14

+0

@blackbelt:问题是我正在将这个标记应用到地图上。哪一个正在寻找一个位图。因此我不能将它应用于imageView。对不起,我应该写下我正在努力做的事情。 – TheDevMan 2014-09-19 08:04:06

+0

地图只占用位图作为占位符?没有意见?这不好。在这种情况下,我将使用placehoder的位图和绘制边界的路径 – Blackbelt 2014-09-19 08:07:21

回答

0

橙色的框架是一个图像视图权利?你可以像这样覆盖另一个图像视图:

<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> 
+0

我无法使用XML。我正在设置我的地图标记,以便我可以通过编程方式设置位图图标。 – TheDevMan 2014-09-19 14:35:43

+0

@TheDevMan创建你的位图,使用imageview.setImageBitmap – AndroidEnthusiast 2014-09-19 15:59:27

+0

无法使用imageview ...地图标记正在寻找图标(位图),而不是别的? – TheDevMan 2014-09-19 16:11:42

0

你可以使用9补丁。
http://developer.android.com/tools/help/draw9patch.html

只需在橙色图像中定义限制即可。

,然后建立这样的层次:

<FrameLayout 
    background="static 9patch image" > 
    <ImageView 
     src="dynamic image"/> 
</FrameLayout> 
+0

我无法使用XML。我正在设置我的地图标记。所以我正在寻找位图图标。 programatically .. – TheDevMan 2014-09-19 14:34:52

+0

他们是怎么做到的:https://play.google.com/store/apps/details?id = com.tndev.loveframes&hl = en? – TheDevMan 2014-09-20 02:07:02