Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I need to have a transparent image overlaid on top of the real image I want the user to see. The images will be stored on the SD card. I have seen many tutorials on doing this, but they always seem to fall short of just how do I get the two images displayed. Or maybe I'm just missing it. Anyway, here is my layout

<merge 
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/gallerylayout"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <ImageView
    android:id="@+id/visible_image"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
  />
  <ImageView
    android:id="@+id/colormap_overlay"
    android:background="#FF000000"      
    android:scaleType="fitXY"
    android:layout_alignTop="@id/visible_image"
    android:layout_alignBottom="@id/visible_image"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
  />
</merge>

and here is my code:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ctx = getApplicationContext();
    setContentView(R.layout.imagepage);
    String image_overlay = Environment.getExternalStorageDirectory() + "/" + s(R.string.APP_NAME) + "/overlay.jpg";
    String visible_image = Environment.getExternalStorageDirectory() + "/" + s(R.string.APP_NAME) + "/visible.jpg";

    ImageView image = (ImageView)findViewById(R.id.visible_image);
    BitmapFactory.Options options = new BitmapFactory.Options();
    Bitmap bm = BitmapFactory.decodeFile(visible_image, options);
    image.setImageBitmap(bm);

    ImageView overlayimage = (ImageView)findViewById(R.id.colormap_overlay);
    Bitmap bm2 = BitmapFactory.decodeFile(image_overlay);
    overlayimage.setAlpha(0);
    overlayimage.setImageBitmap(bm2);
    }

I am pretty sure my error is in my code.

Edit1 I have done some testing and it does appear that the xml layout is ok. I can show the visible image by itself, but when I show the second image (the transparent image), all I get is an empty, all black display.

To show the second image, do I just call setImageBitmap() a second time? I am beginning to think I need to do something else.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
254 views
Welcome To Ask or Share your Answers For Others

1 Answer

I figured it out. I needed to remove the android:background="#FF000000" from the layout xml.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...