3

in my application I have a lit view. each row includes thumbnail image in left and some text in right.

I can get image from server and inflate rows. everything about the list correct. it is like this image:

enter image description here

when user click on rows video will play. I need to add video sign to image simething like: enter image description here on top of each image. Is it possible to add this image on top of my imageview?

Thank you for your helping

Hesam
  • 52,260
  • 74
  • 224
  • 365

2 Answers2

6

Say, your play icon is transparent, then use overlay technique to draw this play icon on your imageview image. Just use the following function:

 public Bitmap putOverlay(Bitmap bmp1, Bitmap overlay) {
        Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bmOverlay);
        Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);

            canvas.drawBitmap(bmp1, 0, 0, null); 
            canvas.drawBitmap(overlay, 0, 0, null);       

        return bmOverlay;
    }

Pass image of your corresponding imageview and another image(for ex: play icon), it returns a merged image which you can set to your imageview. You can also extend ImageView class and override onDraw method to accomplish it.

Imran Rana
  • 11,899
  • 7
  • 45
  • 51
  • Thanks Imran for your help. Just, I didn't understand what is "i_kar"? – Hesam Jun 08 '12 at 16:45
  • Sorry, I pasted it from one of my programs, ignore it(it was one of my test cases). see modified answer :) – Imran Rana Jun 08 '12 at 16:47
  • Thanks again. What about the paint? it seems it is useless. correct? because its never used, together with canvas items. – Hesam Jun 08 '12 at 16:57
  • Hmm you can You use paint instead of null or also use matrix as [described here](http://stackoverflow.com/questions/1540272/android-how-to-overlay-a-bitmap-draw-over-a-bitmap). You can also take a look at [LayerDrawable](http://developer.android.com/reference/android/graphics/drawable/LayerDrawable.html) as another option and this so post:[overlay-two-images](http://stackoverflow.com/questions/2739971/overlay-two-images-in-android-to-set-an-imageview) – Imran Rana Jun 08 '12 at 17:01
  • thanks dear Imran Rana, I appreciate if you answer my related question at http://stackoverflow.com/questions/11030014/android-how-to-add-a-bitmap-layer-over-another-bitmap-layer-dynamically-from-l – Hesam Jun 14 '12 at 09:43
0

You can add moive simbol/icon like this

  public Bitmap putOverlay(Bitmap source) {
    Canvas canvas = new Canvas(source);
    Bitmap icon = BitmapFactory.decodeResource(MainApplication.getInstance().getResources(), R.drawable.video_icon);

    float left = (source.getWidth() / 2) - (icon.getWidth() / 2);
    float top = (source.getHeight() / 2) - (icon.getHeight() / 2);

    canvas.drawBitmap(icon, left, top, null);   

    return source;
}
Ram
  • 1,408
  • 13
  • 29