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