以编程方式截取屏幕截图并不捕获视频中的帧

时间:2015-03-05 07:37:02

标签: android video

我试图以编程方式在android中截取屏幕截图但只获得黑屏。我使用下面的代码截取屏幕截图 点击按钮

                View u = findViewById(R.id.ytrl);
                u.setDrawingCacheEnabled(true);
                RelativeLayout z = (RelativeLayout) findViewById(R.id.ytrl);
                int totalHeight = z.getChildAt(0).getHeight();
                int totalWidth = z.getChildAt(0).getWidth();
                u.layout(0, 0, totalWidth, totalHeight);

                u.buildDrawingCache(true);
                Bitmap b = Bitmap.createBitmap(u.getDrawingCache());
                u.setDrawingCacheEnabled(false);

                AlertDialog.Builder myCaptureDialog = new AlertDialog.Builder(PlayYoutubeVideoActivity.this);
                ImageView capturedImageView = new ImageView(PlayYoutubeVideoActivity.this);
                capturedImageView.setImageBitmap(b);
                LayoutParams capturedImageViewLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
                capturedImageView.setLayoutParams(capturedImageViewLayoutParams);

                myCaptureDialog.setView(capturedImageView);
                myCaptureDialog.show();

和布局文件main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/black" 
        android:id="@+id/ytrl">

        <com.google.android.youtube.player.YouTubePlayerView
            android:id="@+id/activity_play_youtube_video_youtube_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/button1"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_margin="5dip"
            android:background="@android:color/transparent" >

        </com.google.android.youtube.player.YouTubePlayerView>

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:text="Button" />
    </RelativeLayout>

我在图片视图中使用了相同的代码,并获得了正确的结果,但是没有通过视频获得正确的结果。

0 个答案:

没有答案