簡體   English   中英

如何獲取相對布局或framelayout的屏幕截圖?

[英]how to get screenshot of relative layout or framelayout?

請找xml作為參考。我在一個相對布局中有2個imageview。 我想要relativelayout的位圖。 現在我可以使用下面的代碼獲取位圖

但是沒有讓兩個imageview圖像只獲得一個圖像位圖

請為此提出任何合適的解決方案。

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

這是我的java代碼,這就是我如何傳遞位圖。

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

首先你的位圖轉換成ByteArray並傳遞如下

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

並獲取下面的其他活動

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

你可以通過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);

用於獲取圖像

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM