简体   繁体   中英

how to get screenshot of relative layout or framelayout?

Please find xml for reference.I have 2 imageview in one relative layout. I want bitmap of relativelayout. Right now i am able to get bitmap using below code

But not getting both imageview image just getting only one image bitmap

Kindly request any suitable solution for that.

<FrameLayout
        android:id="@+id/linImageView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/linRecyclerAndAdsView">

        <RelativeLayout
            android:id="@+id/relImageView"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView xmlns:wsv="http://schemas.android.com/apk/res-auto"
                android:id="@+id/iv_stickerview"
                android:scaleType="fitXY"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_centerInParent="true" />

            <FrameLayout
                android:id="@+id/vg_canvas"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                >

                <ImageView
                    android:id="@+id/fetchimage"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:adjustViewBounds="true"
                    android:scaleType="fitXY"
                    android:src="@drawable/profile" />

            </FrameLayout>
        </RelativeLayout>
    </FrameLayout>

this is my java code thats how i pass the bitmap.

                relativeLayout.setDrawingCacheEnabled(true);
                relativeLayout.buildDrawingCache();
                bitmap = relativeLayout.getDrawingCache();


                imagePath = Other.saveImage(bitmap);

                Intent newIntent = new Intent(ActivityApp.this, com.aviary.android.feather.sdk.FeatherActivity.class);
                newIntent.setData(Uri.parse(imagePath));
                newIntent.putExtra(Constants.EXTRA_IN_API_KEY_SECRET, "-------------");
                startActivityForResult(newIntent, 1);

first your bitmap convert into ByteArray and pass like below

ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();

Intent i1 = new Intent(this, com.aviary.android.feather.sdk.FeatherActivity.class.class);
i1.putExtra("image",byteArray);

And fetch in another activity like below

byte[] byteArray = getIntent().getByteArrayExtra("image");
Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);

You can directly send bitmap object througn Intent.

  relativeLayout.setDrawingCacheEnabled(true);
            relativeLayout.buildDrawingCache();
            bitmap = relativeLayout.getDrawingCache();

            Intent newIntent = new Intent(StickerActivity.this, com.aviary.android.feather.sdk.FeatherActivity.class);
            newIntent.putExtra("image",bitmap);
            newIntent.putExtra(Constants.EXTRA_IN_API_KEY_SECRET, "e79f03f8602642c9a3e692d2f54df669");
            startActivityForResult(newIntent, 1);

For fetching image

Intent intent = getIntent();
            Bitmap bitmap = (Bitmap) intent.getParcelableExtra("image")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM