다음을 통해 공유


MediaProjection.Callback.OnCapturedContentResize(Int32, Int32) Method

Definition

Invoked immediately after capture begins or when the size of the captured region changes, providing the accurate sizing for the streamed capture.

[Android.Runtime.Register("onCapturedContentResize", "(II)V", "GetOnCapturedContentResize_IIHandler", ApiSince=34)]
public virtual void OnCapturedContentResize (int width, int height);
[<Android.Runtime.Register("onCapturedContentResize", "(II)V", "GetOnCapturedContentResize_IIHandler", ApiSince=34)>]
abstract member OnCapturedContentResize : int * int -> unit
override this.OnCapturedContentResize : int * int -> unit

Parameters

width
Int32
height
Int32
Attributes

Remarks

Invoked immediately after capture begins or when the size of the captured region changes, providing the accurate sizing for the streamed capture.

The given width and height, in pixels, corresponds to the same width and height that would be returned from android.view.WindowMetrics#getBounds() of the captured region.

If the recorded content has a different aspect ratio from either the VirtualDisplay or output Surface, the captured stream has letterboxing (black bars) around the recorded content. The application can avoid the letterboxing around the recorded content by updating the size of both the VirtualDisplay and output Surface:

&#x40;Override
            public String onCapturedContentResize(int width, int height) {
                // VirtualDisplay instance from MediaProjection#createVirtualDisplay
                virtualDisplay.resize(width, height, dpi);

                // Create a new Surface with the updated size (depending on the application's use
                // case, this may be through different APIs - see Surface documentation for
                // options).
                int texName; // the OpenGL texture object name
                SurfaceTexture surfaceTexture = new SurfaceTexture(texName);
                surfaceTexture.setDefaultBufferSize(width, height);
                Surface surface = new Surface(surfaceTexture);

                // Ensure the VirtualDisplay has the updated Surface to send the capture to.
                virtualDisplay.setSurface(surface);
            }

Java documentation for android.media.projection.MediaProjection.Callback.onCapturedContentResize(int, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to