4

I want to create an app where i need to add frames to the images.i don't have any idea regrading this.i got one link where the frames are added to the images.could anybody help me.

Here is the link

@Thanks in Advance!!

3 Answers3

8

Edit: Gallery OnItemClickListener

gallery.setOnItemClickListener(new OnItemClickListener() {
        Bitmap frame = null, out = null;

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
           Bitmap urImage = BitmapFactory.decodeResource(getResources(),
                    R.drawable.urBackgroundImageID);//edit
            frame = BitmapFactory.decodeResource(getResources(),
                    frames[arg2]);
            out = combineImages(frame, urImage);
            imageView.setImageBitmap(out); //add "out" for ur ImageView
        }
    });

frames[] is array of drawables ie different frames

The following method will combine two images dynamically

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

You can try different integer values in

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

where I have put 0 to get needed frame position on the image.

Crisoforo Gaspar
  • 3,740
  • 2
  • 21
  • 27
nidhi_adiga
  • 1,114
  • 1
  • 16
  • 27
  • @thanks nidhi_adiga ,it is possible to show some custom frames in bottom on click the bottom frames the image will set with the frame.? –  Mar 19 '13 at 07:05
  • Yeah its possible you can put some frames in a horizontal gallery view, and gallery onItemclick u can set that particular frame to image – nidhi_adiga Mar 19 '13 at 07:09
  • No gallery OnItemClick u have to call above method passing frame and the image. – nidhi_adiga Mar 19 '13 at 07:13
  • cool but still i have some sort of confusion!! i have different image in image view so on gallery item click its not working!! –  Mar 19 '13 at 07:35
  • The method drawBitmap(Bitmap, float, float, Paint) in the type Canvas is not applicable for the arguments (ImageView, int, int, null) –  Mar 19 '13 at 07:42
  • You have to send Image(converted to Bitmap) in the ImageView not ImageView – nidhi_adiga Mar 19 '13 at 07:49
  • k..i have used some thing like this imgView.draw(comboImage); –  Mar 19 '13 at 07:53
  • @nidhi_adiga: I tried your piece of code.. I get the following output:http://imgur.com/so5auQk I would like to get this following: http://imgur.com/TZfn40Q - I trying to achieve this for a map marker in my APP.. Can you help me fix this? Thanks! – TheDevMan Sep 19 '14 at 06:11
  • Hi, Try reversing the bitmaps you are sending to 'combineImages(img1,img2)' function ie in place of img1 send img2 vice versa... And you may have to change the size of bitmap... – nidhi_adiga Sep 19 '14 at 06:19
1

There are many ways. A very simple way is that, you can draw your custom frame over your image in a View's onDraw method, then draw the view in a Bitmap. There is another way, write the frame pixels data to image pixels data then combine a new image with frame, you can use openCV or other third libs to decode images.

George
  • 11
  • 2
  • thanks for your quick response, i want to view the frames in the bottom on click the frame the image should add with that frame..Is it possible –  Mar 19 '13 at 07:03
-5
 <FrameLayout
         android:id="@+id/frame"
         android:layout_width="120dp"
        android:layout_height="120dp"
        android:foreground="@drawable/your frame...">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_margin="10dp"
        android:layout_gravity="center"
        android:src="@drawable/ic_launcher" />
    </FrameLayout>