1

this is my xml file:

    <RelativeLayout
    android:id="@+id/relativeLayoutTemplateMain"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_below="@+id/LinearLayouttools"
    android:layout_above="@+id/lltexttools"
    android:layout_gravity="center">

    <FrameLayout
        android:id="@+id/frame"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_centerInParent="true">

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:scaleType="centerInside" />

    </FrameLayout>

</RelativeLayout>

i capture framelayout with this code:

fOut = new FileOutputStream(file);
framelayout.setDrawingCacheEnabled(true);
Bitmap bitmap = framelayout.getDrawingCache();
bitmap.compress(Bitmap.CompressFormat.jpeg, 100, fOut);
fOut.flush();
fOut.close();

but Around of the picture is black:

http://uupload.ir/files/z8cv_smsbaaz.ir_4.jpg

also when i set scaleType="FitXY":

<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:scaleType="FitXY"/>

image scale(i dont want scale image) how i solve this problem?

1 Answers1

1

you can use below method to create view to Bitmap .

public static Bitmap loadBitmapFromView(View v) {
    Bitmap b = Bitmap.createBitmap( v.getLayoutParams().width, v.getLayoutParams().height, Bitmap.Config.ARGB_8888);                
    Canvas c = new Canvas(b);
    v.layout(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
    v.draw(c);
    return b;
}

Converting a view to Bitmap without displaying it in Android?

Chetan Joshi
  • 5,582
  • 4
  • 30
  • 43