WO2019056744A1 - 截屏方法、装置、电子设备及可读存储介质 - Google Patents

截屏方法、装置、电子设备及可读存储介质 Download PDF

Info

Publication number
WO2019056744A1
WO2019056744A1 PCT/CN2018/082937 CN2018082937W WO2019056744A1 WO 2019056744 A1 WO2019056744 A1 WO 2019056744A1 CN 2018082937 W CN2018082937 W CN 2018082937W WO 2019056744 A1 WO2019056744 A1 WO 2019056744A1
Authority
WO
WIPO (PCT)
Prior art keywords
format
screen capture
data
imagereader
screen
Prior art date
Application number
PCT/CN2018/082937
Other languages
English (en)
French (fr)
Inventor
黄伟
陈少杰
张文明
Original Assignee
武汉斗鱼网络科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 武汉斗鱼网络科技有限公司 filed Critical 武汉斗鱼网络科技有限公司
Publication of WO2019056744A1 publication Critical patent/WO2019056744A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/01Input arrangements or combined input and output arrangements for interaction between user and computer
    • G06F3/048Interaction techniques based on graphical user interfaces [GUI]
    • G06F3/0484Interaction techniques based on graphical user interfaces [GUI] for the control of specific functions or operations, e.g. selecting or manipulating an object, an image or a displayed text element, setting a parameter value or selecting a range
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/451Execution arrangements for user interfaces

Definitions

  • the present disclosure relates to the field of computer technologies, and in particular, to a screen capture method, apparatus, electronic device, and readable storage medium.
  • an object of the present disclosure includes providing a screen capture method, apparatus, electronic device, and readable storage medium.
  • the present disclosure provides a screen capture method, the screen capture method comprising:
  • the image reading object including a pointer object pointing to the buffer area;
  • a thread is started to acquire image data in the buffer area and store it.
  • the screen capture method is applied to an electronic device installed with an Android system, and the step of establishing an image reading object to implement initialization, the image reading object including a pointer object pointing to the buffer area includes:
  • an ImageReader object as the image reading object based on an Android system, the format of the ImageReader object comprising a first format and a second format;
  • a rendering tool that invokes the graphics library system interface renders a frame of data into a buffer pointed to by the pointer object
  • step a-e is re-executed, where step b is to reset another format different from the default format to the default format of the ImageReader object.
  • the format of the ImageReader object includes RGBA_8888 and RGBX_8888;
  • the second format is RGBX_8888; when the first format is RGBX_8888, the second format is RGBA_8888.
  • the setOnImageAvailableListener interface is called to set the callback steps, including:
  • the step of monitoring whether there is new screen capture data includes:
  • the setOnImageAvailableListener interface determines whether there is screen capture data by monitoring whether the data of the buffer pointed to by the Surface of the ImageReader object is updated or not.
  • the created environment object WindowSurface includes an Enterprise Generation Language object to provide an environment for screen capture operations, so that the data obtained by the screen capture is input into the specified buffer area.
  • a step of creating a rendering tool for rendering the intercepted current screen includes:
  • the method before the step of starting a thread to acquire image data in the buffer area and storing the file, the method further includes:
  • the RGBA value of each pixel of the image data is acquired from the buffer pointed to by the pointer object in turn, and converted into an ARGB value.
  • the step of invoking the graphics library system interface according to the user's screen capture operation to render the data corresponding to the current screen, and transferring the rendered image data to the buffer area pointed by the pointer object of the image reading object includes: :
  • the cache exchange function in the graphics library system interface is called to transfer the rendered image data to a buffer pointed to by the pointer object of the image read object.
  • the present disclosure also provides a screen capture device, the screen capture device comprising:
  • a rendering module configured to invoke a graphics library system interface according to a user's screen capture operation to render data corresponding to the current screen, and deliver the rendered image data to a buffer area pointed by the pointer object of the image reading object;
  • a storage module configured to start a thread to acquire image data in the buffer area and store the image.
  • the screen capture device is configured to be installed with an electronic device of the Android system, and the establishing module includes:
  • a first creating unit configured to create an ImageReader object as the image reading object based on an Android system, where the format of the ImageReader object includes a first format and a second format;
  • a setting unit configured to set the first format or the second format to a default format of an ImageReader object
  • the callback unit is configured to call a setOnImageAvailableListener interface to set a callback;
  • a second creation unit configured to create an environment object WindowSurface
  • a third creating unit configured to create a rendering tool configured to be used by the rendering module to render the intercepted current screen
  • An image rendering unit configured to call a rendering tool of the graphics library system interface to render a frame of data into a buffer pointed to by the pointer object of the ImageReader object;
  • An obtaining unit configured to obtain image data rendered in a buffer area
  • a determining unit configured to determine whether the format of the image data obtained by the rendering is a first format
  • the setting unit is further configured to reset another medium format different from the default format to a default format of the ImageReader object when the format of the image data rendered by the determining unit is not the first format.
  • the format of the ImageReader object includes RGBA_8888 and RGBX_8888;
  • the second format is RGBX_8888; when the first format is RGBX_8888, the second format is RGBA_8888.
  • the callback unit is configured to call a setOnImageAvailableListener interface to set a callback to monitor whether there is new screen capture data, and if there is new screen capture data, perform a screen save.
  • the setOnImageAvailableListener interface determines whether there is screen capture data by monitoring whether the data of the buffer pointed to by the Surface of the ImageReader object is updated or not.
  • the created environment object WindowSurface includes an Enterprise Generation Language object to provide an environment for screen capture operations, so that the data obtained by the screen capture is input into the specified buffer area.
  • the third creating unit is configured to create a rendering tool to render the intercepted current screen into the ImageReader object.
  • the device further includes:
  • the conversion module is configured to sequentially acquire an RGBA value of each pixel of the image data from a buffer pointed to by the pointer object of the ImageReader object, and convert the value into an ARGB value.
  • the rendering module includes:
  • a switching unit configured to invoke a switching function to switch a context of the graphics library system interface to a created WindowSurface environment
  • a screen image rendering unit configured to invoke the graphics library system interface to render data corresponding to the current screen
  • a transfer unit configured to invoke a cache exchange function in the graphics library system interface to transfer the rendered image data to a buffer pointed to by the pointer object of the image read object.
  • the present disclosure also provides an electronic device, including:
  • the above-described screen capture device installed/stored in the memory and executed by the processor.
  • the present disclosure also provides a readable storage medium having stored thereon a computer program that, when executed, implements the screen capture method described above.
  • the screen capture method, the device, the electronic device and the readable storage medium of the present disclosure directly render the data corresponding to the current screen by calling the graphic library system interface, thereby avoiding directly reading or copying the original data of the current screen.
  • Information because the rendering action is operated by a Graphics Processing Unit (GPU), does not block the Central Processing Unit (CPU), and can create a new thread to obtain image data in the buffer area, and then save the picture.
  • GPU Graphics Processing Unit
  • CPU Central Processing Unit
  • FIG. 1 is a block schematic diagram of an electronic device provided by the present disclosure.
  • FIG. 2 is a flow chart of a screen capture method provided by the present disclosure.
  • FIG. 3 is a detailed flowchart of step S101 of the screen capture method provided by the present disclosure.
  • FIG. 4 is a detailed flowchart of step S102 of the screen capture method provided by the present disclosure.
  • FIG. 5 is a schematic diagram of functional modules of a screen capture device provided by the present disclosure.
  • FIG. 6 is a schematic diagram of functional units included in a setup module of a screen capture device provided by the present disclosure.
  • FIG. 7 is a schematic diagram of functional units included in a rendering module of a screen capture device provided by the present disclosure.
  • FIG. 1 it is a block schematic diagram of an electronic device 100.
  • the electronic device 100 includes a screen capture device 110, a memory 111, a memory controller 112, a processor 113, a peripheral interface 114, an input output unit 115, and a display unit 116.
  • FIG. 1 is merely illustrative and does not limit the structure of the electronic device 100.
  • electronic device 100 may also include more or fewer components than those shown in FIG. 1, or have a different configuration than that shown in FIG.
  • the electronic device 100 in this embodiment may be a mobile electronic device, and an Android system is installed in the mobile electronic device.
  • the components of the memory 111, the memory controller 112, the processor 113, the peripheral interface 114, the input and output unit 115, and the display unit 116 are electrically connected directly or indirectly to each other to implement data transmission or interaction.
  • the components can be electrically connected to one another via one or more communication buses or signal lines.
  • the screen capture device 110 includes at least one software function module that can be stored in the memory 111 or in an operating system (OS) of the electronic device 100 in the form of software or firmware.
  • the processor 113 is configured to execute an executable module stored in a memory, such as a software function module or a computer program included in the screen capture device 110.
  • the memory 111 can be, but not limited to, a random access memory (RAM), a read only memory (ROM), and a programmable read-only memory (PROM). Erasable Programmable Read-Only Memory (EPROM), Electric Erasable Programmable Read-Only Memory (EEPROM), and the like.
  • RAM random access memory
  • ROM read only memory
  • PROM programmable read-only memory
  • EPROM Erasable Programmable Read-Only Memory
  • EEPROM Electric Erasable Programmable Read-Only Memory
  • the memory 111 is used to store a program, and the processor 113 executes the program after receiving the execution instruction.
  • the method executed by the electronic device 100 defined by the process disclosed in any embodiment of the present disclosure may be applied to the processor 113.
  • the processor 113 may be an integrated circuit chip with signal processing capabilities.
  • the processor 113 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP processor, etc.), or a digital signal processing (DSP). , Application Specific Integrated Circuit (ASIC), Field Programmable Gate Array (FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware component.
  • ASIC Application Specific Integrated Circuit
  • FPGA Field Programmable Gate Array
  • the general purpose processor may be a microprocessor or the processor or any conventional processor or the like.
  • peripheral interface 114 couples various input/input devices to the processor 113 and the memory 111.
  • peripheral interface 114, processor 113, and memory controller 112 can be implemented in a single chip. In other instances, they can be implemented by separate chips.
  • the input and output unit 115 is configured to provide input data to the user or electronic device output data.
  • the input and output unit 115 may be, but not limited to, a mouse, a keyboard, and the like.
  • the display unit 116 provides an interactive interface (such as a user operation interface) between the electronic device 100 and the user or for displaying image data to the user for reference.
  • the display unit may be a liquid crystal display or a touch display.
  • a touch display it can be a capacitive touch screen or a resistive touch screen that supports single-point and multi-touch operations. Supporting single-point and multi-touch operations means that the touch display can sense the simultaneous touch operation from one or more positions on the touch display, and the touch operation is performed by the processor. Calculation and processing.
  • the application layer of the electronic device cannot directly obtain the image raw data in the Open Graphics Library (openGL), and needs to call glReadPixels to read or back up the original data information, which is a time-consuming operation, resulting in the existing In the technology, the electronic device of the Android system needs to obtain the screenshot data of the mobile game live broadcast, which will affect the smoothness of the live broadcast.
  • openGL Open Graphics Library
  • FIG. 2 is a flowchart of a screen capture method applied to the electronic device shown in FIG. 1 provided by the present disclosure. The specific flow shown in FIG. 2 will be described in detail below.
  • Step S101 an image reading object is established to implement initialization, and the image reading object includes a pointer object pointing to the buffer area.
  • the screen capture method can be used to implement a background screen shot of an electronic device on which an Android system is installed.
  • the image reading object may be an ImageReader object in an Android system.
  • the pointer object included in the ImageReader object may be a Surface through which the buffer pointed to by the Surface may be accessed.
  • the screen capture method is applied to an electronic device installed with an Android system.
  • the step S101 may include: step S1011 - step S1016.
  • Step S1011 Create an ImageReader object as the image reading object based on the Android system.
  • the format of the ImageReader object includes a first format and a second format.
  • step S1012 the first format or the second format is set to a default format of the ImageReader object.
  • the format of the ImageReader object may be RGBA_8888 or RGBX_8888.
  • the first format may be RGBA_8888 or RGBX_8888.
  • the second format when the first format is RGBA_8888, the second format is RGBX_8888.
  • the first format is RGBX_8888, the second format is RGBA_8888.
  • the first format may set the default format of the ImageReader object. For example, set RGBX_8888 to the default format of the ImageReader object.
  • step S1013 the setOnImageAvailableListener interface is called to set a callback.
  • the setOnImageAvailableListener interface is used to monitor whether there is new screen capture data for related storage.
  • the current screen data is rendered into the ImageReader, and the callback of the setOnImageAvailableListener interface can be listened to, and then the screen save is performed.
  • no screen capture operation is performed, there is no data rendering action, and the setOnImageAvailableListener interface has no related operations.
  • the setOnImageAvailableListener interface can determine whether there is screen capture data by monitoring whether the data of the buffer pointed to by the Surface of the ImageReader object is updated.
  • step S1014 an environment object WindowSurface is created.
  • the environment object may be an EGL (Enterprise Generation Language) object.
  • EGL Enterprise Generation Language
  • the EGL is an interface between the OpenGL interface and the underlying Native platform window system.
  • the WindowSurface is used to provide an environment for the screen capture operation, so that the data obtained by the screen capture is input into the designated buffer area.
  • the Surface used to create the WindowSurface needs to use the pointer object Surface object contained in the ImageReader.
  • the pointer object Surface is obtained by the GetSurface method.
  • step S1015 a rendering tool filter is created.
  • the rendering tool filter is created, and in one instance, the rendering tool filter can be a DYGLTextureScreenFilter.
  • the rendering tool filter is used to render screen data of a live game broadcast into the ImageReader object.
  • Step S1016 invoking a graphics library system interface to render a frame of data into a buffer area pointed by the pointer object.
  • the graphics library system interface may be an OpenGL (Open Graphics Library) interface, which refers to a professional graphics program interface that defines a cross-programming language and a cross-platform programming interface specification.
  • OpenGL Open Graphics Library
  • Step S1017 Acquire image data rendered in the buffer area.
  • Step S1018 Determine whether the format of the rendered image data is a default format.
  • step S1012 is to set another format different from the default format as the default format of the reset of the ImageReader object. For example, if the first format is previously set to the default format, it is judged that the format of the rendered image data is not the default format, and the second format is set to the default format during the process of returning to re-execution of steps S1011 to S1015.
  • step S101 ends.
  • step S101 is an initialization process.
  • the graphics library system interface may overwrite the format of the ImageReader object during rendering, so that the rendered image data is different from the default format of the ImageReader object.
  • the steps S1016 to S1018 are set to detect, and the format of the image data obtained by the rendering is prevented from being different from the default format, thereby obtaining the rendered image.
  • Image data will be reported directly to the UnsupportedOperationException, which will improve the effectiveness of the screen capture.
  • Step S102 the graphic library system interface is called according to the screen capture operation of the user to render the data corresponding to the current screen, and the rendered image data is transferred to the buffer area pointed by the pointer object of the image reading object.
  • the step S102 includes: step S1021 and step S1022.
  • Step S1021 Call a switching function to switch the context of the graphics library system interface to the environment where the created WindowSurface is located, and invoke the graphics library system interface to render the data corresponding to the current screen.
  • the output corresponding to the mobile game uplink context is an encoder. Therefore, before the screen capture is performed, the context of the graphics library system interface is switched.
  • makeCurrent is invoked to switch the context of the graphics library system interface, and the EGL context is switched from the mobile game OpenGL context to the created WindowSurface context.
  • the rendering by the render tool filter of the opengl interface is invoked.
  • Step S1022 Calling a cache exchange function in the graphics library system interface to transfer the rendered image data to a buffer area pointed by the pointer object of the image read object.
  • the exchange function may be a swapBuffers function of the opengl interface.
  • the rendered image data is passed to the buffer pointed to by the pointer object of the ImageReader object by calling the swapBuffers function of the opengl interface.
  • the pointer object may be the Surface, and the Surface corresponds to a buffer area.
  • Step S103 starting a thread to acquire image data in the buffer area and storing the data.
  • the thread may be a new thread that is started by the start method before step S101.
  • the steps of steps S101 and S102 are performed in this thread.
  • step S101 the initialized setOnImageAvailableListener interface is used to monitor the update of the data of the buffer area, and when the buffer area has data update, the updated data may be stored for a long time.
  • the method further includes:
  • Step S104 sequentially obtaining an RGBA value of each pixel of the image data from a buffer area pointed by the pointer object, and converting into an ARGB value.
  • bitmap bitmap file
  • the format of the image data in the buffer area may be PixelFormat.RGBA_8888.
  • the electronic device traverses each pixel in the image data, and re-assigns the RGBA value of each pixel to convert to an ARGB value.
  • the RGBA value is obtained in turn from the buffer pointed to by the pointer object of the ImageReader object, converted to an ARGB value, where the A value represents transparency and is directly set to opaque 255.
  • the R, G, B, and A values are stored in one byte in Android
  • the storage order of the image data in the buffer area is R, G, B, and A
  • the storage order in the Bitmap image is A. , R, G, B.
  • variable offset can be set to the offset of the storage address, and the buffer is the data address of the ImageReader object.
  • the R value of the image data in the buffer area pointed to by the pointer object of the ImageReader object is stored in the R value of the Bitmap, and needs to be shifted to the left by two bits, that is, the R value in the Bitmap is (buffer.get(offset) )&0xff) ⁇ 16. And so on, set the pixel variable to pixel, you can get the calculation of each value as follows:
  • (buffer.get(offset)&0xff) ⁇ 16;//R
  • (buffer.get(offset+1)&0xff) ⁇ 8;//G
  • (buffer.get(offset+2)&0xff);//B
  • (buffer.get(offset+3)
  • A can be set to 255.
  • the screen capture method of the present disclosure directly renders the data corresponding to the current screen by calling the graphic library system interface, thereby avoiding directly reading or copying the original data information of the current screen. Since the rendering action is operated by the GPU, the CPU is not blocked, and the new one can be newly created. The thread obtains the image data in the buffer area, and then performs related operations of saving the picture, thereby realizing a background screen capture that does not affect the live stream fluency.
  • FIG. 5 is a functional block diagram of the screen capture device 110 shown in FIG. 1 provided by the present disclosure.
  • Each module in the screen capture device 110 in this embodiment is used to perform various steps in the above method embodiments.
  • the screen capture device 110 includes an establishing module 1101, a rendering module 1102, and a storage module 1103.
  • the establishing module 1101 is configured to establish an image reading object, where the image reading object includes a pointer object pointing to the buffer area.
  • the rendering module 1102 is configured to invoke the graphics library system interface to render data corresponding to the current screen according to the screen capture operation of the user, and deliver the rendered image data to a buffer area pointed by the pointer object of the image reading object.
  • the storage module 1103 is configured to start a thread to acquire image data in the buffer area and store the data.
  • the establishing module 1101 includes: a first creating unit 11011, a setting unit 11012, an image rendering unit 11013, an obtaining unit 11014, a determining unit 11015, a second creating unit 11016, and a third creation.
  • the first creating unit 11011 is configured to create an ImageReader object as the image reading object based on an Android system, and the format of the ImageReader object includes a first format and a second format.
  • the setting unit 11012 is configured to set a default format of the ImageReader object in the first format or the second format.
  • the callback unit 11013 is configured to call a setOnImageAvailableListener interface to set a callback.
  • the second creating unit 11014 is configured to create an environment object WindowSurface.
  • the third creating unit 11015 is configured to create a rendering tool filter.
  • the image rendering unit 11016 is configured to invoke the graphics library system interface to render a frame of data into a buffer pointed to by the pointer object of the ImageReader object.
  • the obtaining unit 11017 is configured to obtain image data that is rendered in a buffer area.
  • the determining unit 11018 is configured to determine whether the format of the rendered image data is the first format.
  • the setting unit 11012 is further configured to, when the determining unit 11018 determines that the format of the rendered image data is not the default format, set another medium format different from the default format to a reset default format of the ImageReader object.
  • the rendering module 1102 is further configured to: according to a screen capture operation of the user, invoke a rendering tool filter of the graphics library system interface to render data corresponding to the current screen, and deliver the rendered image data to the image reading object.
  • the pointer object points to the cache.
  • the apparatus further includes: a conversion module 1104, configured to sequentially acquire an RGBA value of each pixel of the image data from a buffer pointed by the pointer object of the ImageReader object, and convert the value into an ARGB value.
  • a conversion module 1104 configured to sequentially acquire an RGBA value of each pixel of the image data from a buffer pointed by the pointer object of the ImageReader object, and convert the value into an ARGB value.
  • the rendering module 1102 includes: a switching unit 11021, a screen image rendering unit 11022, and a delivery unit 11023.
  • the switching unit 11021 is configured to invoke a switching function to switch the context of the graphics library system interface to the created WindowSurface environment.
  • the screen image rendering unit 11022 is configured to invoke the graphics library system interface to render data corresponding to the current screen.
  • the transmitting unit 11023 is configured to invoke a cache exchange function in the graphics library system interface to deliver the rendered image data to a buffer pointed to by the pointer object of the image read object.
  • the format of the ImageReader object includes RGBA_8888 and RGBX_8888;
  • the second format is RGBX_8888; when the first format is RGBX_8888, the second format is RGBA_8888.
  • the callback unit 11013 is configured to call a setOnImageAvailableListener interface to set a callback to monitor whether there is new screen capture data, and if there is new screen capture data, perform a screen save.
  • the setOnImageAvailableListener interface determines whether there is screen capture data by monitoring whether the data of the buffer pointed to by the Surface of the ImageReader object is updated or not.
  • the created environment object WindowSurface includes an Enterprise Generation Language object to provide an environment for screen capture operations, so that the data obtained by the screen capture is input into the specified buffer area.
  • the third creation unit 11015 is configured to create a rendering tool that renders the intercepted current screen into the ImageReader object.
  • the screen capture device of the present disclosure directly renders the data corresponding to the current screen by calling the graphic library system interface, thereby avoiding directly reading or copying the original data information of the current screen. Since the rendering action is operated by the GPU, the CPU is not blocked, and the new one can be newly created. The thread obtains the image data in the buffer area, and then performs related operations of saving the picture, thereby realizing a background screen capture that does not affect the live stream fluency.
  • the present disclosure provides a readable storage medium having stored thereon a computer program that, when executed, implements the screen capture method provided by the above embodiments.
  • each block of the flowchart or block diagram can represent a module, a program segment, or a portion of code that includes one or more of the Executable instructions. It should also be noted that, in some alternative implementations, the functions noted in the blocks may also occur in a different order than those illustrated in the drawings.
  • each block of the block diagrams and/or flowcharts, and combinations of blocks in the block diagrams and/or flowcharts can be implemented in a dedicated hardware-based system that performs the specified function or action. Or it can be implemented by a combination of dedicated hardware and computer instructions.
  • each functional module in various embodiments of the present disclosure may be integrated to form a separate part, or each module may exist separately, or two or more modules may be integrated to form a separate part.
  • the functions, if implemented in the form of software functional modules and sold or used as separate products, may be stored in a computer readable storage medium.
  • a computer readable storage medium including: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, and the like.
  • the screen capture method, device, electronic device and readable storage medium provided by the present disclosure realize a background screen capture that does not affect the live stream fluency.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Human Computer Interaction (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Processing Or Creating Images (AREA)
  • User Interface Of Digital Computer (AREA)

Abstract

一种截屏方法、装置、电子终端及可读存储介质。所述截屏方法包括:建立图像读取对象以实现初始化,该图像读取对象包括指向缓存区的指针对象(S101);根据用户的截屏操作调用图形库系统接口将当前屏幕对应的数据渲染,并将渲染得到的图像数据传递至所述图像读取对象的指针对象指向的缓存区中(S102);依次从所述指针对象指向的缓存区获取所述图像数据每个像素点的RGBA值,并转换为ARGB值(S104);启动一线程获取所述缓存区中的图像数据并进行存储(S103)。

Description

截屏方法、装置、电子设备及可读存储介质
相关申请的交叉引用
本申请要求于2017年09月20日提交中国专利局的申请号为CN2017108546188,名称为“截屏方法、装置、电子设备及可读存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本公开涉及计算机技术领域,具体而言,涉及一种截屏方法、装置、电子设备及可读存储介质。
背景技术
目前在很多平台直播手游时,截取屏幕内容存在如下问题:在录屏过程中,由于录屏直播为对录屏数据按顺序逐帧进行渲染显示,直接拷贝录屏直播的显示数据以获取图片信息,会影响直播流畅度。
发明内容
有鉴于此,本公开的目的包括,提供一种截屏方法、装置、电子设备及可读存储介质。
本公开提供的一种截屏方法,所述截屏方法包括:
建立图像读取对象以实现初始化,该图像读取对象包括指向缓存区的指针对象;
根据用户的截屏操作调用图形库系统接口将当前屏幕对应的数据渲染,并将渲染得到的图像数据传递至所述图像读取对象的指针对象指向的缓存区中;
启动一线程获取所述缓存区中的图像数据并进行存储。
可选地,该截屏方法应用于安装有Android系统的电子设备,所述建立图像读取对象以实现初始化,该图像读取对象包括指向缓存区的指针对象的步骤包括:
a.基于Android系统创建ImageReader对象作为所述图像读取对象,所述ImageReader对象的格式包括第一格式和第二格式;
b.将所述第一格式或第二格式设置为ImageReader对象的默认格式;
c.调用setOnImageAvailableListener接口设置回调;
d.创建环境对象WindowSurface;
e.创建渲染工具,用于对截取的当前屏幕进行渲染;
f.调用图形库系统接口的渲染工具渲染一帧数据到所述指针对象指向的缓存区中;
g.获取缓存区中渲染得到的图像数据;
h.判断所述渲染得到的图像数据的格式是否为所述默认格式;
若不是默认格式,则重新执行步骤a-e,其中,步骤b为将不同于该默认格式的另一种格式重置为ImageReader对象的默认格式。
可选地,所述ImageReader对象的格式包括RGBA_8888和RGBX_8888;
当所述第一格式为RGBA_8888,所述第二格式则为RGBX_8888;当所述第一格式为RGBX_8888,所述第二格式则为RGBA_8888。
可选地,调用setOnImageAvailableListener接口设置回调的步骤,包括:
调用setOnImageAvailableListener接口设置回调,以监听是否有新的截屏数据,如果有新的截屏数据则进行截屏保存。
可选地,监听是否有新的截屏数据的步骤,包括:
所述setOnImageAvailableListener接口通过监听所述ImageReader对象的Surface指向的缓存区的数据更新与否判断是否有截屏数据。
可选地,创建的所述环境对象WindowSurface包括Enterprise Generation Language对象,用以提供截屏操作的环境,以使截屏得到的数据输入指定缓存区中。
可选地,创建渲染工具,用于对截取的当前屏幕进行渲染的步骤,包括:
创建渲染工具,将截取的当前屏幕渲染到所述ImageReader对象中。
可选地,在启动一线程获取所述缓存区中的图像数据并进行存储的步骤之前,所述方法还包括:
依次从所述指针对象指向的缓存区获取所述图像数据每个像素点的RGBA值,并转换为ARGB值。
可选地,所述根据用户的截屏操作调用图形库系统接口将当前屏幕对应的数据渲染,并将渲染得到的图像数据传递至所述图像读取对象的指针对象指向的缓存区中的步骤包括:
调用一切换函数将所述图形库系统接口的上下文环境切换至创建的WindowSurface环境中,调用所述图形库系统接口将当前屏幕对应的数据渲染;
调用所述图形库系统接口中的缓存交换函数将渲染得到的图像数据传递至所述图像读取对象的指针对象指向的缓存区中。
本公开还提供一种截屏装置,所述截屏装置包括:
建立模块,用于建立图像读取对象以实现初始化,该图像读取对象包括一指向缓存区的指针对象;
渲染模块,用于根据用户的截屏操作调用图形库系统接口将当前屏幕对应的数据渲染,并将渲染得到的图像数据传递至所述图像读取对象的指针对象指向的缓存区中;
存储模块,用于启动一线程获取所述缓存区中的图像数据并进行存储。
可选地,该截屏装置应配置成安装有Android系统的电子设备,所述建立模块包括:
第一创建单元,配置成基于Android系统创建ImageReader对象作为所述图像读取对象,所述ImageReader对象的格式包括第一格式和第二格式;
设置单元,配置成将所述第一格式或第二格式设置为ImageReader对象的默认格式;
回调单元,配置成调用setOnImageAvailableListener接口设置回调;
第二创建单元,配置成创建环境对象WindowSurface;
第三创建单元,配置成创建渲染工具,以配置成供所述渲染模块对截取的当前屏幕进行渲染;
图像渲染单元,配置成调用图形库系统接口的渲染工具渲染一帧数据到ImageReader对象的指针对象指向的缓存区中;
获取单元,配置成获取缓存区中渲染得到的图像数据;
判断单元,配置成判断所述渲染得到的图像数据的格式是否为第一格式;
所述设置单元还配置成当所述判断单元渲染得到的图像数据的格式不为第一格式时,将为将不同于该默认格式的另一中格式重置为ImageReader对象的默认格式。
可选地,所述ImageReader对象的格式包括RGBA_8888和RGBX_8888;
当所述第一格式为RGBA_8888,所述第二格式则为RGBX_8888;当所述第一格式为RGBX_8888,所述第二格式则为RGBA_8888。
可选地,所述回调单元配置成调用setOnImageAvailableListener接口设置回调,以监听是否有新的截屏数据,如果有新的截屏数据则进行截屏保存。
可选地,所述setOnImageAvailableListener接口通过监听所述ImageReader对象的Surface指向的缓存区的数据更新与否判断是否有截屏数据。
可选地,创建的所述环境对象WindowSurface包括Enterprise Generation Language对象,用以提供截屏操作的环境,以使截屏得到的数据输入指定缓存区中。
可选地,所述第三创建单元配置成创建渲染工具,将截取的当前屏幕渲染到所述ImageReader对象中。
可选地,所述装置还包括:
转换模块,配置成依次从ImageReader对象的指针对象指向的缓存区获取所述图像数据每个像素点的RGBA值,并转换为ARGB值。
可选地,所述渲染模块包括:
切换单元,配置成调用切换函数将所述图形库系统接口的上下文环境切换至创建的WindowSurface环境中;
屏幕图像渲染单元,配置成调用所述图形库系统接口将当前屏幕对应的数据渲染;
传递单元,配置成调用所述图形库系统接口中的缓存交换函数将渲染得到的图像数据传递至所述图像读取对象的指针对象指向的缓存区中。
本公开还提供一种电子设备,包括:
存储器;
处理器;
安装/存储于所述存储器并由所述处理器执行的上述的截屏装置。
本公开还提供一种可读存储介质,其上存储有计算机程序,所述计算机程序在执行时实现上述的截屏方法。
与现有技术相比,本公开的截屏方法、装置、电子设备及可读存储介质,通过调用图形库系统接口直接渲染得到当前屏幕对应的数据,避免了直接读取或拷贝当前屏幕的原始数据信息,由于渲染动作由图形处理器(Graphics Processing Unit,GPU)操作,不会阻塞中央处理器(Central Processing Unit,CPU),且可以新建线程来获取缓存区中的图像数据,然后进行保存图片的相关操作,从而实现了不影响直播流畅度的后台截屏。
为使本公开的上述目的、特征和优点能更明显易懂,下文特举,并配合所附附图,作详细说明如下。
附图说明
为了更清楚地说明本公开的技术方案,下面将对实施例中所需要使用的附图作简单地介绍,应当理解,以下附图仅示出了本公开的某些实施例,因此不应被看作是对范围的限定,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他相关的附图。
图1为本公开提供的电子设备的方框示意图。
图2为本公开提供的截屏方法的流程图。
图3为本公开提供的截屏方法的步骤S101的详细流程图。
图4为本公开提供的截屏方法的步骤S102的详细流程图。
图5为本公开提供的截屏装置的功能模块示意图。
图6为本公开提供的截屏装置的建立模块包括的功能单元示意图。
图7为本公开提供的截屏装置的渲染模块包括的功能单元示意图。
具体实施方式
下面将结合本公开中附图,对本公开中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本公开一部分实施例,而不是全部的实施例。通常在此处附图中描述和示出的本公开的组件可以以各种不同的配置来布置和设计。因此,以下对在附图中提供的本公开的实施例的详细描述并非旨在限制要求保护的本公开的范围,而是仅仅表示本公开的选定实施例。基于本公开的实施例,本领域技术人员在没有做出创造性劳动的前提下所获得的所有其他实施例,都属于本公开保护的范围。
应注意到:相似的标号和字母在下面的附图中表示类似项,因此,一旦某一项在一个附图中被定义,则在随后的附图中不需要对其进行进一步定义和解释。同时,在本公开的描述中,术语“第一”、“第 二”等仅用于区分描述,而不能理解为指示或暗示相对重要性。
如图1所示,是一电子设备100的方框示意图。所述电子设备100包括截屏装置110、存储器111、存储控制器112、处理器113、外设接口114、输入输出单元115和显示单元116。本领域普通技术人员可以理解,图1所示的结构仅为示意,其并不对电子设备100的结构造成限定。例如,电子设备100还可包括比图1中所示更多或者更少的组件,或者具有与图1所示不同的配置。本实施例所述的电子设备100可以是移动电子设备,所述移动电子设备中安装有Android系统。
所述存储器111、存储控制器112、处理器113、外设接口114、输入输出单元115及显示单元116各元件相互之间直接或间接地电性连接,以实现数据的传输或交互。例如,这些元件相互之间可通过一条或多条通讯总线或信号线实现电性连接。所述截屏装置110包括至少一个可以软件或固件(Firmware)的形式存储于所述存储器111中或固化在所述电子设备100的操作系统(Operating System,OS)中的软件功能模块。所述处理器113用于执行存储器中存储的可执行模块,例如所述截屏装置110包括的软件功能模块或计算机程序。
其中,所述存储器111可以是,但不限于,随机存取存储器(Random Access Memory,RAM),只读存储器(Read Only Memory,ROM),可编程只读存储器(Programmable Read-Only Memory,PROM),可擦除只读存储器(Erasable Programmable Read-Only Memory,EPROM),电可擦除只读存储器(Electric Erasable Programmable Read-Only Memory,EEPROM)等。其中,存储器111用于存储程序,所述处理器113在接收到执行指令后,执行所述程序,本公开任一实施例揭示的过程定义的电子设备100所执行的方法可以应用于处理器113中,或者由处理器113实现。
所述处理器113可能是一种集成电路芯片,具有信号的处理能力。上述的处理器113可以是通用处理器,包括中央处理器(Central Processing Unit,简称CPU)、网络处理器(Network Processor,简称NP)等;还可以是数字信号处理器(Digital Signal Processing,DSP)、专用集成电路(ASIC)、现场可编程门阵列(Field Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件。可以实现或者执行本公开中的公开的各方法、步骤及逻辑框图。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。
所述外设接口114将各种输入/输入装置耦合至处理器113以及存储器111。在一些实施例中,外设接口114,处理器113以及存储控制器112可以在单个芯片中实现。在其他一些实例中,他们可以分别由独立的芯片实现。
所述输入输出单元115用于提供给用户输入数据或者电子设备输出数据。所述输入输出单元115可以是,但不限于,鼠标和键盘等。
所述显示单元116在所述电子设备100与用户之间提供一个交互界面(例如用户操作界面)或用于显示图像数据给用户参考。在本实施例中,所述显示单元可以是液晶显示器或触控显示器。若为触控显 示器,其可为支持单点和多点触控操作的电容式触控屏或电阻式触控屏等。支持单点和多点触控操作是指触控显示器能感应到来自该触控显示器上一个或多个位置处同时产生的触控操作,并将该感应到的触控操作交由处理器进行计算和处理。
由于安卓平台限制,电子设备的应用层无法直接获取图形程序接口(Open Graphics Library,openGL)中的图像原始数据,需要调用glReadPixels读取或者备份原始数据信息,此操作为耗时操作,导致现有技术中安卓系统的电子设备如果需要获取手游直播的截屏数据会影响直播的流畅性。
请参阅图2,是本公开提供的应用于图1所示的电子设备的截屏方法的流程图。下面将对图2所示的具体流程进行详细阐述。
步骤S101,建立图像读取对象以实现初始化,该图像读取对象包括指向缓存区的指针对象。
在一种实施方式中,所述截屏方法可用于实现安装有Android系统的电子设备的后台截屏。所述图像读取对象可以是Android系统中的ImageReader对象。
本实施例中,所述ImageReader对象中包括的指针对象可以是Surface,通过所述Surface可以访问所述Surface指向的缓存区。
本实施例中,在一种实施方式中,所述截屏方法应用于安装有Android系统的电子设备,如图3所示,所述步骤S101可包括:步骤S1011-步骤S1016。
步骤S1011,基于Android系统创建ImageReader对象作为所述图像读取对象。其中,ImageReader对象的格式包括第一格式和第二格式。
步骤S1012,将所述第一格式或第二格式设置ImageReader对象的默认格式。
所述ImageReader对象的格式可能是RGBA_8888或RGBX_8888。
在一个实例中,所述第一格式可以是RGBA_8888,也可以是RGBX_8888。本实施例中,当第一格式为RGBA_8888,所述第二格式则为RGBX_8888。当第一格式为RGBX_8888,所述第二格式则为RGBA_8888。
本实施例中,可以将第一格式设置ImageReader对象的默认格式。例如,将RGBX_8888设置为所述ImageReader对象的默认格式。
步骤S1013,调用setOnImageAvailableListener接口设置回调。
本实施例中,该setOnImageAvailableListener接口用于监听是否有新的截屏数据,从而进行相关存储。当用户进行截屏操作时,将当前屏幕的数据渲染到ImageReader中,setOnImageAvailableListener接口的回调即可监听到,然后进行截屏保存。未进行截屏操作时,则无数据渲染动作,此setOnImageAvailableListener接口也无相关操作。
本实施例中,所述setOnImageAvailableListener接口可通过监听所述ImageReader对象的Surface指向的缓存区的数据更新与否判断是否有截屏数据。
步骤S1014,创建环境对象WindowSurface。
本实施例中,所述环境对象可以是EGL(Enterprise Generation Language,业务编程语言)对象。所述EGL是OpenGL接口和底层Native平台视窗系统之间的接口。
本实施例中,所述WindowSurface用于提供截屏操作的环境,以使截屏得到的数据输入指定缓存区中。
在一个实例中,由于需要将截屏数据输出到ImageReader对象的指针对象Surface中,所以创建所述WindowSurface所用的Surface需要使用ImageReader所包含的指针对象Surface对象。在一个实例中,该指针对象Surface通过GetSurface方法获取。
步骤S1015,创建渲染工具filter。
在一个实例中,创建所述渲染工具filter,在一个实例中,渲染工具filter可以是DYGLTextureScreenFilter。
在一个实例中,所述渲染工具filter用于将手游直播的屏幕数据渲染到所述ImageReader对象中。
步骤S1016,调用图形库系统接口渲染一帧数据到所述指针对象指向的缓存区中。
本实施例中,所述图形库系统接口可以是opengl(Open Graphics Library)接口是指定义了一个跨编程语言、跨平台的编程接口规格的专业的图形程序接口。
步骤S1017,获取缓存区中渲染得到的图像数据。
步骤S1018,判断所述渲染得到的图像数据的格式是否为默认格式。
若不是默认格式,则返回重新执行步骤S1011至步骤S1015;其中,步骤S1012为将不同于该默认格式的另一种格式设置为ImageReader对象的重置的默认格式。例如,若之前将第一格式设定为默认格式,在判断渲染得到的图像数据的格式不是默认格式,在返回重新执行步骤S1011至步骤S1015过程中,将第二格式设定为默认格式。
若是第一格式,则步骤S101的流程结束。
本实施例中,步骤S101为一个初始化的过程。其中,所述图形库系统接口在渲染时可能会覆盖所述ImageReader对象的格式,导致渲染得到的图像数据与所述ImageReader对象的默认格式不同。为了使设置所述ImageReader对象的默认格式与图形库系统接口在渲染得到的图像数据的格式相同,设置步骤S1016至S1018进行检测,避免渲染得到的图像数据的格式与默认格式不同导致获取渲染得到的图像数据时会直接报UnsupportedOperationException异常,从而提高截屏有效性。
步骤S102,根据用户的截屏操作调用图形库系统接口将当前屏幕对应的数据渲染,并将渲染得到的图像数据传递至所述图像读取对象的指针对象指向的缓存区中。
本实施例中,如图4所示,所述步骤S102包括:步骤S1021和步骤S1022。
步骤S1021,调用一切换函数将所述图形库系统接口的上下文环境切换至创建的WindowSurface所 处环境中,调用所述图形库系统接口将当前屏幕对应的数据渲染。
由于一个openGL上下文环境对应一个输出,在一个实例中,手游直播上行文环境对应的输出为编码器。因此,截屏进行图像保存前,切换所述图形库系统接口的上下文环境。
在一种实施方式中,调用makeCurrent切换所述图形库系统接口的上下文环境,将EGL上下文环境从手游直播openGL上下文环境,切换到创建的WindowSurface上下文环境。
在一种实施方式中,调用opengl接口的渲染工具filter进行的渲染。
步骤S1022,调用所述图形库系统接口中的缓存交换函数将渲染得到的图像数据传递至所述图像读取对象的指针对象指向的缓存区中。
在一种实施方式中,所述交换函数可以是opengl接口的swapBuffers函数。通过调用opengl接口的swapBuffers函数将渲染得到的图像数据传递到ImageReader对象的指针对象指向的缓存区。其中,所述指针对象可以是所述Surface,所述Surface对应一个缓存区。
步骤S103,启动一线程获取所述缓存区中的图像数据并进行存储。
本实施例中,所述线程可以是在步骤S101之前通过start方法启动的新线程。在一个实例中,所述步骤S101和S102的步骤在此线程中进行。
本实施例中,上述步骤S101中使用上述初始化的setOnImageAvailableListener接口监听所述缓存区的数据的更新,当所述缓存区有数据更新可以将更新得到的数据进行长期保存。
本实施例中,请再次参阅图2,在步骤S103之前,所述方法还包括:
步骤S104,依次从所述指针对象指向的缓存区获取所述图像数据每个像素点的RGBA值,并转换为ARGB值。
其中,若直接将缓存区中的图像数据保存为Bitmap(位图文件),可能为空白图片。
在一个实例中,所述缓存区中的图像数据的格式可以是PixelFormat.RGBA_8888。所述电子设备遍历所述图像数据中的每一个像素点,对每个像素点的RGBA值进行重新赋值,以转换为ARGB值。在一个实例中:依次从ImageReader对象的指针对象指向的缓存区获取RGBA值,转换为ARGB值,其中A值代表透明度,直接设置为不透明255。其中,R,G,B,A值在安卓中存储长度为一个字节,所述图像数据在所述缓存区的存储顺序为R,G,B,A,而Bitmap图像中的存储顺序为A,R,G,B。在一个实例中,可以设置变量offset为存储地址的偏移量,buffer为ImageReader对象的数据地址。本实例中可以调用方法buffer.get(offset)获取ImageReader对象的指针对象指向的缓存区中的图像数据的R值;调用方法buffer.get(offset+1)获取ImageReader对象的指针对象指向的缓存区中的图像数据的G值;调用方法buffer.get(offset+2)获取ImageReader对象的指针对象指向的缓存区中的图像数据的B值;调用方法buffer.get(offset+3)获取ImageReader对象的指针对象指向的缓存区中的图像数据的A值。本实施例中,ImageReader对象的指针对象指向的缓存区中的图像数据的R值存储到Bitmap中的R值,需 要向左偏移两位,即Bitmap中的R值为(buffer.get(offset)&0xff)<<16。依次类推,设置像素变量为pixel,可以得到每个值的计算方法如下:
pixel|=(buffer.get(offset)&0xff)<<16;//R
pixel|=(buffer.get(offset+1)&0xff)<<8;//G
pixel|=(buffer.get(offset+2)&0xff);//B
pixel|=(buffer.get(offset+3)|0xff)<<24;//A
本实施例中,与0xff进行或运算,即可设置A为255。
本公开的截屏方法,通过调用图形库系统接口直接渲染得到当前屏幕对应的数据,避免了直接读取或拷贝当前屏幕的原始数据信息,由于渲染动作由GPU操作,不会阻塞CPU,且可以新建线程中来获取缓存区中的图像数据,然后进行保存图片的相关操作,从而实现了不影响直播流畅度的后台截屏。
请参阅图5,是本公开提供的图1所示的截屏装置110的功能模块示意图。本实施例中的截屏装置110中的各个模块用于执行上述方法实施例中的各个步骤。所述截屏装置110包括建立模块1101、渲染模块1102及存储模块1103。
所述建立模块1101,用于建立图像读取对象以实现初始化,该图像读取对象包括指向缓存区的指针对象。
所述渲染模块1102,用于根据用户的截屏操作调用图形库系统接口将当前屏幕对应的数据渲染,并将渲染得到的图像数据传递至所述图像读取对象的指针对象指向的缓存区中。
所述存储模块1103,用于启动一线程获取所述缓存区中的图像数据并进行存储。
本实施例中,如图6所示,所述建立模块1101包括:第一创建单元11011、设置单元11012、图像渲染单元11013、获取单元11014、判断单元11015、第二创建单元11016、第三创建单元11017及判断单元11018。
所述第一创建单元11011,用于基于Android系统创建ImageReader对象作为所述图像读取对象,所述ImageReader对象的格式包括第一格式和第二格式。
所述设置单元11012,用于将所述第一格式或第二格式设置ImageReader对象的默认格式。
所述回调单元11013,用于调用setOnImageAvailableListener接口设置回调。
所述第二创建单元11014,用于创建环境对象WindowSurface。
所述第三创建单元11015,用于创建渲染工具filter。
所述图像渲染单元11016,用于调用图形库系统接口渲染一帧数据到ImageReader对象的指针对象指向的缓存区中。
所述获取单元11017,用于获取缓存区中渲染得到的图像数据。
所述判断单元11018,用于判断所述渲染得到的图像数据的格式是否为第一格式。
所述设置单元11012还用于当判断单元11018判断渲染得到的图像数据的格式不为默认格式时,将不同于该默认格式的另一中格式设置为ImageReader对象的重置的默认格式。
本实施例中,所述渲染模块1102还用于根据用户的截屏操作调用图形库系统接口的渲染工具filter将当前屏幕对应的数据渲染,并将渲染得到的图像数据传递至所述图像读取对象的指针对象指向的缓存区中。
本实施例中,所述装置还包括:转换模块1104,用于依次从ImageReader对象的指针对象指向的缓存区获取所述图像数据每个像素点的RGBA值,并转换为ARGB值。
本实施例中,如图7所示,所述渲染模块1102包括:切换单元11021、屏幕图像渲染单元11022及传递单元11023。
所述切换单元11021,用于调用一切换函数将所述图形库系统接口的上下文环境切换至创建的WindowSurface环境中。
所述屏幕图像渲染单元11022,用于调用所述图形库系统接口将当前屏幕对应的数据渲染。
所述传递单元11023,用于调用所述图形库系统接口中的缓存交换函数将渲染得到的图像数据传递至所述图像读取对象的指针对象指向的缓存区中。
可选地,所述ImageReader对象的格式包括RGBA_8888和RGBX_8888;
当所述第一格式为RGBA_8888,所述第二格式则为RGBX_8888;当所述第一格式为RGBX_8888,所述第二格式则为RGBA_8888。
可选地,所述回调单元11013配置成调用setOnImageAvailableListener接口设置回调,以监听是否有新的截屏数据,如果有新的截屏数据则进行截屏保存。
setOnImageAvailableListener接口通过监听所述ImageReader对象的Surface指向的缓存区的数据更新与否判断是否有截屏数据。
创建的所述环境对象WindowSurface包括Enterprise Generation Language对象,用以提供截屏操作的环境,以使截屏得到的数据输入指定缓存区中。
所述第三创建单元11015配置成创建渲染工具,将截取的当前屏幕渲染到所述ImageReader对象中。
关于本装置实施例的其它细节可以进一步地参考上述方法实施例中的描述,在此不再赘述。
本公开的截屏装置,通过调用图形库系统接口直接渲染得到当前屏幕对应的数据,避免了直接读取或拷贝当前屏幕的原始数据信息,由于渲染动作由GPU操作,不会阻塞CPU,且可以新建线程中来获取缓存区中的图像数据,然后进行保存图片的相关操作,从而实现了不影响直播流畅度的后台截屏。
本公开提供一种可读存储介质,其上存储有计算机程序,所述计算机程序在执行时实现上述实施例提供的截屏方法。
在本申请所提供的几个实施例中,应该理解到,所揭露的装置和方法,也可以通过其它的方式实现。 以上所描述的装置实施例仅仅是示意性的,例如,附图中的流程图和框图显示了根据本公开的多个实施例的装置、方法和计算机程序产品的可能实现的体系架构、功能和操作。在这点上,流程图或框图中的每个方框可以代表一个模块、程序段或代码的一部分,所述模块、程序段或代码的一部分包含一个或多个用于实现规定的逻辑功能的可执行指令。也应当注意,在有些作为替换的实现方式中,方框中所标注的功能也可以以不同于附图中所标注的顺序发生。例如,两个连续的方框实际上可以基本并行地执行,它们有时也可以按相反的顺序执行,这依所涉及的功能而定。也要注意的是,框图和/或流程图中的每个方框、以及框图和/或流程图中的方框的组合,可以用执行规定的功能或动作的专用的基于硬件的系统来实现,或者可以用专用硬件与计算机指令的组合来实现。
另外,在本公开各个实施例中的各功能模块可以集成在一起形成一个独立的部分,也可以是各个模块单独存在,也可以两个或两个以上模块集成形成一个独立的部分。
所述功能如果以软件功能模块的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本公开的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本公开各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。需要说明的是,在本文中,诸如第一和第二等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、物品或者设备中还存在另外的相同要素。
以上所述仅为本公开的优选实施例而已,并不用于限制本公开,对于本领域的技术人员来说,本公开可以有各种更改和变化。凡在本公开的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本公开的保护范围之内。应注意到:相似的标号和字母在下面的附图中表示类似项,因此,一旦某一项在一个附图中被定义,则在随后的附图中不需要对其进行进一步定义和解释。
以上所述,仅为本公开的具体实施方式,但本公开的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本公开揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本公开的保护范围之内。因此,本公开的保护范围应所述以权利要求的保护范围为准。
工业实用性
本公开提供的截屏方法、装置、电子设备及可读存储介质,实现了不影响直播流畅度的后台截屏。

Claims (20)

  1. 一种截屏方法,其特征在于,所述截屏方法包括:
    建立图像读取对象以实现初始化,该图像读取对象包括指向缓存区的指针对象;
    根据用户的截屏操作调用图形库系统接口将当前屏幕对应的数据渲染,并将渲染得到的图像数据传递至所述图像读取对象的指针对象指向的缓存区中;
    启动一线程获取所述缓存区中的图像数据并进行存储。
  2. 如权利要求1所述的截屏方法,其特征在于,该截屏方法应用于安装有Android系统的电子设备,所述建立图像读取对象以实现初始化,该图像读取对象包括指向缓存区的指针对象的步骤包括:
    a.基于Android系统创建ImageReader对象作为所述图像读取对象,所述ImageReader对象的格式包括第一格式和第二格式;
    b.将所述第一格式或第二格式设置为ImageReader对象的默认格式;
    c.调用setOnImageAvailableListener接口设置回调;
    d.创建环境对象WindowSurface;
    e.创建渲染工具,用于对截取的当前屏幕进行渲染;
    f.调用图形库系统接口的渲染工具渲染一帧数据到所述指针对象指向的缓存区中;
    g.获取缓存区中渲染得到的图像数据;
    h.判断所述渲染得到的图像数据的格式是否为所述默认格式;
    若不是默认格式,则重新执行步骤a-e,其中,步骤b为将不同于该默认格式的另一种格式重置为ImageReader对象的默认格式。
  3. 如权利要求2所述的截屏方法,其特征在于,所述ImageReader对象的格式包括RGBA_8888和RGBX_8888;
    当所述第一格式为RGBA_8888,所述第二格式则为RGBX_8888;当所述第一格式为RGBX_8888,所述第二格式则为RGBA_8888。
  4. 如权利要求2或3所述的截屏方法,其特征在于,调用setOnImageAvailableListener接口设置回调的步骤,包括:
    调用setOnImageAvailableListener接口设置回调,以监听是否有新的截屏数据,如果有新的截屏数据则进行截屏保存。
  5. 如权利要求4所述的截屏方法,其特征在于,监听是否有新的截屏数据的步骤,包括:
    所述setOnImageAvailableListener接口通过监听所述ImageReader对象的Surface指向的缓存区的数据更新与否判断是否有截屏数据。
  6. 如权利要求2至5任一项所述的截屏方法,其特征在于,创建的所述环境对象WindowSurface包括Enterprise Generation Language对象,用以提供截屏操作的环境,以使截屏得到的数据输入指定缓存区中。
  7. 如权利要求2至6任一项所述的截屏方法,其特征在于,创建渲染工具,用于对截取的当前屏幕进行渲染的步骤,包括:
    创建渲染工具,将截取的当前屏幕渲染到所述ImageReader对象中。
  8. 如权利要求1至7任一项所述的截屏方法,其特征在于,在启动一线程获取所述缓存区中的图像数据并进行存储的步骤之前,所述方法还包括:
    依次从所述指针对象指向的缓存区获取所述图像数据每个像素点的RGBA值,并转换为ARGB值。
  9. 如权利要求1至8任一项所述的截屏方法,其特征在于,所述根据用户的截屏操作调用图形库系统接口将当前屏幕对应的数据渲染,并将渲染得到的图像数据传递至所述图像读取对象的指针对象指向的缓存区中的步骤包括:
    调用一切换函数将所述图形库系统接口的上下文环境切换至创建的WindowSurface环境中,调用所述图形库系统接口将当前屏幕对应的数据渲染;
    调用所述图形库系统接口中的缓存交换函数将渲染得到的图像数据传递至所述图像读取对象的指针对象指向的缓存区中。
  10. 一种截屏装置,其特征在于,所述截屏装置包括:
    建立模块,配置成建立图像读取对象以实现初始化,该图像读取对象包括指向缓存区的指针对象;
    渲染模块,配置成根据用户的截屏操作调用图形库系统接口将当前屏幕对应的数据渲染,并将渲染得到的图像数据传递至所述图像读取对象的指针对象指向的缓存区中;
    存储模块,配置成启动一线程获取所述缓存区中的图像数据并进行存储。
  11. 如权利要求10所述的截屏装置,其特征在于,该截屏装置应配置成安装有Android系统的电子设备,所述建立模块包括:
    第一创建单元,配置成基于Android系统创建ImageReader对象作为所述图像读取对象,所述ImageReader对象的格式包括第一格式和第二格式;
    设置单元,配置成将所述第一格式或第二格式设置为ImageReader对象的默认格式;
    回调单元,配置成调用setOnImageAvailableListener接口设置回调;
    第二创建单元,配置成创建环境对象WindowSurface;
    第三创建单元,配置成创建渲染工具,以配置成供所述渲染模块对截取的当前屏幕进行渲染;
    图像渲染单元,配置成调用图形库系统接口的渲染工具渲染一帧数据到ImageReader对象的指针对象指向的缓存区中;
    获取单元,配置成获取缓存区中渲染得到的图像数据;
    判断单元,配置成判断所述渲染得到的图像数据的格式是否为第一格式;
    所述设置单元还配置成当所述判断单元渲染得到的图像数据的格式不为第一格式时,将为将不同于该默认格式的另一中格式重置为ImageReader对象的默认格式。
  12. 如权利要求11所述的截屏装置,其特征在于,所述ImageReader对象的格式包括RGBA_8888和RGBX_8888;
    当所述第一格式为RGBA_8888,所述第二格式则为RGBX_8888;当所述第一格式为RGBX_8888,所述第二格式则为RGBA_8888。
  13. 如权利要求11或12所述的截屏装置,其特征在于,所述回调单元配置成调用setOnImageAvailableListener接口设置回调,以监听是否有新的截屏数据,如果有新的截屏数据则进行截屏保存。
  14. 如权利要求13所述的截屏装置,其特征在于,所述setOnImageAvailableListener接口通过监听所述ImageReader对象的Surface指向的缓存区的数据更新与否判断是否有截屏数据。
  15. 如权利要求11至14任一项所述的截屏装置,其特征在于,创建的所述环境对象WindowSurface包括Enterprise Generation Language对象,用以提供截屏操作的环境,以使截屏得到的数据输入指定缓存区中。
  16. 如权利要求11至15任一项所述的截屏装置,其特征在于,所述第三创建单元配置成创建渲染工具,将截取的当前屏幕渲染到所述ImageReader对象中。
  17. 如权利要求10至16任一项所述的截屏装置,其特征在于,所述装置还包括:
    转换模块,配置成依次从ImageReader对象的指针对象指向的缓存区获取所述图像数据每个像素点的RGBA值,并转换为ARGB值。
  18. 如权利要求10至17任一项所述的截屏装置,其特征在于,所述渲染模块包括:
    切换单元,配置成调用切换函数将所述图形库系统接口的上下文环境切换至创建的WindowSurface环境中;
    屏幕图像渲染单元,配置成调用所述图形库系统接口将当前屏幕对应的数据渲染;
    传递单元,配置成调用所述图形库系统接口中的缓存交换函数将渲染得到的图像数据传递至所述图像读取对象的指针对象指向的缓存区中。
  19. 一种电子设备,其特征在于,包括:
    存储器;
    处理器;
    安装/存储于所述存储器并由所述处理器执行的权利要求5-8任一项所述的截屏装置。
  20. 一种可读存储介质,其上存储有计算机程序,其特征在于,所述计算机程序在执行时实现上述权利要求1-9中任意一项所述的截屏方法。
PCT/CN2018/082937 2017-09-20 2018-04-13 截屏方法、装置、电子设备及可读存储介质 WO2019056744A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201710854618.8 2017-09-20
CN201710854618.8A CN107515759B (zh) 2017-09-20 2017-09-20 截屏方法、装置、电子设备及可读存储介质

Publications (1)

Publication Number Publication Date
WO2019056744A1 true WO2019056744A1 (zh) 2019-03-28

Family

ID=60725875

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2018/082937 WO2019056744A1 (zh) 2017-09-20 2018-04-13 截屏方法、装置、电子设备及可读存储介质

Country Status (2)

Country Link
CN (1) CN107515759B (zh)
WO (1) WO2019056744A1 (zh)

Families Citing this family (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107515759B (zh) * 2017-09-20 2020-08-04 武汉斗鱼网络科技有限公司 截屏方法、装置、电子设备及可读存储介质
CN108449625B (zh) * 2018-01-30 2020-08-07 深圳市创梦天地科技股份有限公司 视频截图方法、装置及终端
CN108388461A (zh) * 2018-02-27 2018-08-10 山东超越数控电子股份有限公司 一种用于固件的屏幕图像截取方法与装置
CN109408497B (zh) * 2018-09-20 2022-02-08 创新先进技术有限公司 一种数据的渲染方法、装置及设备
CN109821236B (zh) * 2019-01-18 2022-02-22 恒信东方文化股份有限公司 一种实时图像的提取方法
CN109857309B (zh) * 2019-01-21 2022-02-01 武汉卡比特信息有限公司 一种基于iOS移动终端的屏幕截图投射方法
CN112004041B (zh) * 2019-05-27 2022-06-10 腾讯科技(深圳)有限公司 视频录制方法、装置、终端及存储介质
CN111405301B (zh) * 2020-03-02 2022-10-04 广州虎牙科技有限公司 终端的录屏交互方法、装置、计算机设备及存储介质
CN113794926A (zh) * 2021-09-03 2021-12-14 深圳创维-Rgb电子有限公司 屏幕图像获取方法、装置和计算机可读存储介质
CN113784075B (zh) * 2021-09-28 2024-05-14 统信软件技术有限公司 一种屏幕录像读取方法、系统及计算设备
CN114579246B (zh) * 2022-05-05 2022-07-08 北京麟卓信息科技有限公司 一种安卓兼容环境中多窗口模式下安卓应用的截屏方法
CN117687771A (zh) * 2023-07-24 2024-03-12 荣耀终端有限公司 一种缓冲区分配方法、装置、电子设备及存储介质

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20150022522A1 (en) * 2012-03-20 2015-01-22 Siemens Corporation Luggage Visualization and Virtual Unpacking
CN105427236A (zh) * 2015-12-18 2016-03-23 魅族科技(中国)有限公司 一种图像渲染方法及装置
CN105933778A (zh) * 2016-06-17 2016-09-07 北京奇虎科技有限公司 基于终端屏幕内容的直播方法及装置
CN107515759A (zh) * 2017-09-20 2017-12-26 武汉斗鱼网络科技有限公司 截屏方法、装置、电子设备及可读存储介质

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080256508A1 (en) * 2003-10-09 2008-10-16 Einfalt, Ehf. Hybrid Spreadsheet/Workflow Design and Execution Environment
CN106131656A (zh) * 2016-06-28 2016-11-16 武汉斗鱼网络科技有限公司 一种用于视频直播间准实时截图的系统及方法

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20150022522A1 (en) * 2012-03-20 2015-01-22 Siemens Corporation Luggage Visualization and Virtual Unpacking
CN105427236A (zh) * 2015-12-18 2016-03-23 魅族科技(中国)有限公司 一种图像渲染方法及装置
CN105933778A (zh) * 2016-06-17 2016-09-07 北京奇虎科技有限公司 基于终端屏幕内容的直播方法及装置
CN107515759A (zh) * 2017-09-20 2017-12-26 武汉斗鱼网络科技有限公司 截屏方法、装置、电子设备及可读存储介质

Also Published As

Publication number Publication date
CN107515759B (zh) 2020-08-04
CN107515759A (zh) 2017-12-26

Similar Documents

Publication Publication Date Title
WO2019056744A1 (zh) 截屏方法、装置、电子设备及可读存储介质
CN109194960B (zh) 一种图像帧渲染方法、装置及电子设备
CN111163345B (zh) 一种图像渲染方法及装置
US10949944B2 (en) System and method for unified application programming interface and model
WO2018176960A1 (zh) 显示网络图片的方法、装置以及用户终端
KR102307163B1 (ko) 크로스 플랫폼 렌더링 엔진
TWI604375B (zh) 螢幕分享方法以及使用該方法的裝置
JP6062506B2 (ja) 汎用グラフィクス処理装置における計算リソースパイプライン化
US11403121B2 (en) Streaming per-pixel transparency information using transparency-agnostic video codecs
WO2013039812A2 (en) System and method for layering using tile-based renderers
US9679408B2 (en) Techniques for enhancing multiple view performance in a three dimensional pipeline
WO2022179362A1 (zh) 一种图像融合方法以及装置
CN113655975B (zh) 图像显示方法、装置、电子设备和介质
US9460481B2 (en) Systems and methods for processing desktop graphics for remote display
WO2019134289A1 (zh) 投屏控制方法、装置、电子终端及可读存储介质
KR102575541B1 (ko) 이미지를 캡처하기 위한 방법, 단말기 및 이의 저장 매체
US9349213B2 (en) Tile-based accumulative multi-layer alpha blending systems and methods
CN107329654B (zh) 绘制元素浮层的方法、装置以及计算机可读存储介质
WO2018205390A1 (zh) 一种控件布局显示控制方法、系统、装置及计算机可读存储介质
WO2019114044A1 (zh) 图像处理方法、装置、电子设备及计算机可读存储介质
JP5842029B2 (ja) 画像データをキャッシュする情報処理支援装置、情報処理装置及び情報処理支援プログラム
US12039350B2 (en) Streaming application visuals using page-like splitting of individual windows
CN114035903A (zh) 实现Linux KVM虚拟机支持3D应用的方法及系统
CN113094607A (zh) 获取本地资源的方法及装置
CN113378094A (zh) 界面共享方法、装置、设备及介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 18859806

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 18859806

Country of ref document: EP

Kind code of ref document: A1