【问题标题】:insert an image to given a Image in android在android中插入图像给定图像
【发布时间】:2014-09-19 07:55:57
【问题描述】:

我正在尝试将图像插入静态图像(类似于框架内的图像)。我可以在一定程度上得到它,但无法将它正确地放在给定的图像中。

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

这是我尝试过的:

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

我得到了这个:

占位符是动态的,橙色框架图像是静态的。我想以编程方式将图像直接插入橙色图像中。

这可能吗?

【问题讨论】:

  • 我认为您正试图以苛刻的方式实现简单的目标。我宁愿使用两个不同的ImageViews。第一个包含作为 src 的占位符和作为背景的圆角方形边框。第二个只包含钩子。
  • @blackbelt:问题是我将它应用到地图的标记上。哪个正在寻找位图。因此我不能在 imageView 上应用它。对不起,我应该清楚地写下我想做的事情。
  • 地图只使用位图作为占位符?不是观点?这不好。在这种情况下,我会为占位符使用位图和绘制边框的路径
  • @blackbelt:我该怎么做?
  • canvas 可以在位图上绘制路径。所以你可能需要一个足够大的位图来承载两者。这不是微不足道的,但也不是那么困难..

标签: android image image-editing


【解决方案1】:

橙色框是图像视图,对吗?您可以像这样在其上叠加另一个图像视图:

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

【讨论】:

  • 我不能使用 XML。我正在设置我的地图标记,所以我正在寻找位图图标以编程方式设置它。
  • @TheDevMan 创建你的位图,使用 imageview.setImageBitmap
  • 无法使用图像视图...地图标记正在寻找图标(位图)而不是其他?
  • 我明白了……你见过尝试过这种方法吗? stackoverflow.com/questions/14564100/…
  • 他们做得怎么样:play.google.com/store/apps/…?
【解决方案2】:

您可以为此使用 9-patch。
http://developer.android.com/tools/help/draw9patch.html

只需定义橙色图像中的限制。

然后像这样构建层次结构:

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

【讨论】:

  • 我不能使用 XML。我正在设置我的地图标记。所以我正在寻找位图图标。以编程方式..
  • 他们做得怎么样:play.google.com/store/apps/…?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-19
  • 2021-06-06
  • 2020-06-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多