Pranav
Pranav

Reputation: 4250

Imageview Drawing catch not come as needed

I have image view inside frame layout ,i put random sticker on image view at run time but when i save image bitmap using frame layout drawing-catch then image save but with unnecessary black part comes in saved image.Actual image

After save with sticker

Required

i want bitmap without this black part.Please help.Here is my layout and code.

<FrameLayout
    android:id="@+id/fl_effect_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/rl_title"
    android:layout_marginBottom="83dp" >

    <ImageView
        android:id="@+id/im_gselected_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
         >
    </ImageView>
</FrameLayout>

Here is code that i use to create bitmap.

FrameLayout fl=(FrameLayout) findViewById(R.id.fl_effect_view);
f1.setDrawingCacheEnabled(true);
Bitmap b=Bitmap.createBitmap(f1.getDrawingCache());
f1.setDrawingCacheEnabled(false);

Upvotes: -1

Views: 445

Answers (1)

Samuel D
Samuel D

Reputation: 51

Try to set the size of the view before you get the Drawing Cache:

ImageView bottomImage = (ImageView) findViewById(R.id.im_gselected_image);
f1.layout(0, 0, bottomImage.getMeasuredWidth(), bottomImage.getMeasuredHeight());
Bitmap b=Bitmap.createBitmap(f1.getDrawingCache(true));

This will force your result to have a specific size and position, and will crop everything that is out of your defined bounds.

Please, let me now if this worked for you.

Upvotes: 2

Related Questions