Android operating system-based scrolling screenshot implementation method and system, and storage medium
By simulated screen scrolling, multiple screenshots are obtained, and comparison blocks and reference points are set for deduplication and cropping, which solves the problem of repeated or missing long screenshots in the native Android system, and realizes efficient generation of long screenshots.
Patent Information
- Application Number
- PCT/CN2024/084126
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2024-02-28
- Filing Date
- 2024-03-27
- Publication Date
- 2025-09-04
AI Technical Summary
The existing technology does not invade Android native system code, and there are duplications or missing cases in the long screenshot implementation, and the speed is slow, making it difficult to accurately find the duplicate parts in the screenshot process.
By simulating screen scrolling, obtain multiple screenshots, set comparison blocks and reference points, deduplication and crop them, and generate growth screenshots, including setting a predetermined screenshot height and reference points, deduplication of process screenshots using comparison blocks and reference points, cropping off the repeated parts, and splicing the cropped screenshots to generate growth screenshots.
Without invading the native Android system code, the repetitive parts in the screenshot process are accurately found, which improves the accuracy and efficiency of long screenshots and greatly improves the implementation efficiency of long screenshots.
Smart Images

Figure CN2024084126_04092025_PF_FP_ABST
Abstract
Description
Long screenshot implementation method, system, and storage medium based on Android operating system Technical Field
[0001] The present application relates to the field of screenshot technology, and in particular to a method and system for implementing long screenshots based on the Android operating system, and a storage medium. Background Art
[0002] Android native version 12 did not have a built-in long screenshot function, but the interface content of current mobile device applications is rich, and often one screen cannot display the entire content, and the screen needs to be scrolled to view. When users want to take a screenshot to show others all the contents of a similar interface, the long screenshot function becomes very important. Therefore, before Android version 12, each mobile phone manufacturer needs to implement the long screenshot function by themselves.
[0003] Existing common methods for implementing long screenshots without intruding the native system generally involve three steps: the first step is to simulate scrolling and take a single screenshot, repeating this process; the second step is to crop the duplicated portions of the screenshot; and the final step is to stitch all the screenshots together to create the long screenshot. This method of stitching multiple screenshots together to achieve long screenshot functionality often results in duplicate or missing long screenshots. Conventional methods for more accurate deduplication require a complete comparison of the entire image, which is slow. Therefore, there is a need for a method that can accurately identify duplicate portions in the screenshot process without intruding the native Android system code.
[0004] Summary of the Invention
[0005] Based on this, it is necessary to provide a long screenshot implementation method, system and storage medium based on the Android operating system that can accurately find the repeated parts in the screenshot process without invading the Android native system code, and solve the slow technical problem in the existing technology.
[0006] The technical solutions of the present invention are as follows:
[0007] A method for implementing a long screenshot based on an Android operating system, the method comprising:
[0008] Step S100: obtaining a long screenshot activation instruction for activating long screenshot;
[0009] Step S200: capturing a current screenshot of the foreground application according to the long screenshot start instruction, wherein the foreground application is an application that is currently visible and is being used to interact with the user;
[0010] Step S300: Controlling the foreground application to simulate screen scrolling, scrolling from bottom to top from a simulated scrolling start point to a simulated scrolling end point, and taking a screenshot of the foreground application during each simulated screen scrolling, obtaining multiple screenshots, wherein the simulated scrolling start point and the simulated scrolling end point are preset;
[0011] Step S400: setting a comparison block and a reference point according to the simulated scrolling end point, and deduplicating the preceding and following process screenshots in each of the process screenshots according to the comparison block and the reference point to trim out duplicate portions;
[0012] Step S500: stitching all the cropped process screenshots together to generate a long screenshot.
[0013] Specifically, step S400: setting a comparison block and a reference point according to the simulated scrolling end point, and deduplicating the two preceding and following process screenshots in each of the process screenshots according to the comparison block and the reference point to trim out duplicate parts; specifically comprising:
[0014] Step S410: setting a predetermined clipping height according to the simulated scrolling end point, wherein the predetermined clipping height is greater than a maximum blank space in a list interface, wherein the list interface is pre-stored;
[0015] Step S420: moving the simulated scrolling end point downward by the predetermined interception height, and setting the area between the simulated scrolling end point before and after the movement as a comparison block;
[0016] Step S430: setting a reference point, and deduplicating the preceding and following process screenshots in each of the process screenshots based on the comparison block and the reference point, so as to cut out duplicated parts.
[0017] Specifically, step S430: setting a reference point, and deduplicating the two preceding and following process screenshots in each of the process screenshots based on the comparison block and the reference point, so as to cut out duplicate parts; specifically comprising:
[0018] Step S431: obtaining screen width pixel points, and setting a reference point according to the screen width pixel points;
[0019] Step S432: finding duplicate blocks from the two preceding and following process screenshots in each of the process screenshots based on the reference point and the comparison block;
[0020] Step S433: trimming the repeated blocks to trim the repeated parts.
[0021] Specifically, in step S432, the previous process screenshot is the first screenshot, and the next process screenshot is the second screenshot;
[0022] The step of finding repeated blocks from any two preceding and following process screenshots based on the reference point and the comparison block specifically includes:
[0023] Step S4321: Calculate the sum of all reference points in each row between the simulated scrolling start point and the simulated scrolling end point of the first screenshot, and store the sum in the int array array1. Calculate the sum of all reference points in the height portion of the comparison block in the header of the second screenshot, and store the sum in the int array array2. The lengths of the int array array1 and the int array array2 represent the number of rows of reference points to be calculated, i.e., the height of the screenshot in pixels.
[0024] Step S4322: Search for the repeated position from the end of b1 upwards, wherein the value of the int type variable compareIndex is set to be equal to the length of the int array array2;
[0025] Step S4323: Starting from the position of array1 length minus compareIndex in the int array array1, compare each item with the int array array2 in sequence. If there is a difference, compareIndex is increased by 1.
[0026] Step S4324: Repeat step S4323. If the comparison results in identical blocks, a duplicate block is generated based on the comparison result.
[0027] Specifically, step S100: obtaining a long screenshot start instruction for starting a long screenshot, and then further including:
[0028] Step S110: setting an overlay transparent window on the foreground application;
[0029] Step S120: setting a preset gap in the middle of the transparent window, wherein the preset gap is a gap with a pre-stored pixel width and a height that fills the screen.
[0030] Specifically, a long screenshot implementation system based on the Android operating system includes:
[0031] A screenshot command acquisition module is used to obtain a long screenshot activation command for activating long screenshot;
[0032] a current application screenshot module, configured to capture a current screenshot of a foreground application according to the long screenshot start instruction, wherein the foreground application is an application that is currently visible and is being used to interact with the user;
[0033] a simulated scrolling screenshot module, configured to control the foreground application to simulate scrolling, scrolling from bottom to top from a simulated scrolling start point to a simulated scrolling end point, and taking a screenshot of the foreground application each time the screen is simulated scrolled, thereby obtaining multiple screenshots, wherein the simulated scrolling start point and the simulated scrolling end point are preset;
[0034] a benchmark comparison and weight removal module, configured to set a comparison block and a benchmark point according to the simulated scrolling end point, and to remove duplicates from the preceding and following process screenshots in each of the process screenshots according to the comparison block and the benchmark point, so as to remove duplicate parts;
[0035] The screenshot splicing generation module is used to splice all the cropped process screenshots and generate a long screenshot.
[0036] Specifically, the benchmark comparison and weight cutting module is also used to:
[0037] Setting a predetermined interception height according to the simulated scrolling end point, wherein the predetermined interception height is greater than a maximum blank space in a list-type interface, wherein the list-type interface is pre-stored;
[0038] Moving the simulated scrolling end point downward by the predetermined interception height, and setting the area between the simulated scrolling end point before the movement and the simulated scrolling end point after the movement as a comparison block;
[0039] A reference point is set, and duplicates are removed from the preceding and following process screenshots in each of the process screenshots according to the comparison block and the reference point, so as to cut out duplicate parts.
[0040] Specifically, the benchmark comparison and weight cutting module is also used to:
[0041] Obtaining screen width pixels and setting a reference point based on the screen width pixels;
[0042] Finding repeated blocks from the two preceding and following process screenshots in each of the process screenshots according to the reference point and the comparison block;
[0043] The repeated blocks are cut off to achieve cutting off of the repeated parts.
[0044] Specifically, the previous process screenshot is the first screenshot, and the next process screenshot is the second screenshot. The benchmark comparison and weight cutting module is further used for:
[0045] Calculate the sum of all the reference points in each row between the simulated scrolling start and end points of the first screenshot and store it in the int array array1. Calculate the sum of all the reference points in the height portion of the comparison block in the header of the second screenshot and store it in the int array array2. The lengths of the int arrays array1 and array2 represent the number of rows of reference points being calculated, i.e., the height of the screenshot in pixels.
[0046] Start from the end of b1 and search for the duplicate position from bottom to top. Let the int type variable compareIndex have a value equal to the length of the int array array2.
[0047] Starting from the position of array1 length minus compareIndex in int array1, compare with each item of int array2 in turn. If they are different, compareIndex is increased by 1.
[0048] Repeat step S4323. If the comparison results in identical blocks, a duplicate block is generated based on the comparison result.
[0049] Specifically, the screenshot instruction acquisition module is further used to: set an overlay transparent window on the foreground application;
[0050] A preset gap is set in the middle of the transparent window, wherein the preset gap is a gap with a pre-stored pixel width and a height that fills the screen.
[0051] A computer device includes a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the long screenshot implementation method based on the Android operating system when executing the computer program.
[0052] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of the long screenshot implementation method based on the Android operating system.
[0053] The present invention achieves the following technical effects:
[0054] The above-mentioned long screenshot implementation method, system and storage medium based on the Android operating system sequentially obtain a long screenshot activation instruction for activating long screenshot; capture a current screenshot of the foreground application according to the long screenshot activation instruction, wherein the foreground application is an application that is currently visible and is being used to interact with the user; control the foreground application to simulate screen scrolling, scrolling from bottom to top from the simulated scrolling starting point to the simulated scrolling end point, and taking a screenshot of the foreground application during each simulated screen scrolling, obtaining multiple screenshots, wherein the simulated scrolling starting point and the simulated scrolling end point are preset; and setting a comparison block according to the simulated scrolling end point. , set a reference point, and deduplicate the two previous and next process screenshots in each process screenshot according to the comparison block and the reference point to crop out the repeated parts; splice all the cropped process screenshots and generate a long screenshot. On the one hand, by setting the concept of comparison blocks, the purpose of finding repeated parts is clarified and the accuracy is improved; on the other hand, by setting the reference point summation comparison concept, the comparison efficiency is greatly improved, and then a method is designed that can accurately find the repeated parts in the screenshot process without invading the Android native system code, and the speed is very fast, which greatly improves the efficiency and method of long screenshot implementation. BRIEF DESCRIPTION OF THE DRAWINGS
[0055] FIG1 is a flow chart of a method for implementing a long screenshot based on an Android operating system in one embodiment;
[0056] FIG2 is a schematic diagram of a rough cut process in a method for implementing a long screenshot based on an Android operating system in one embodiment;
[0057] FIG3 is a schematic diagram of a conventional screenshot cropping process in a method for implementing a long screenshot based on an Android operating system in one embodiment;
[0058] FIG4 is a schematic diagram of a cropping process after adding a contrast line in a long screenshot implementation method based on an Android operating system in one embodiment;
[0059] FIG5 is a schematic diagram of a conventional deduplication process in a method for implementing a long screenshot based on an Android operating system in one embodiment;
[0060] FIG6 is a schematic diagram of a screenshot comparison process in a method for implementing a long screenshot based on an Android operating system in one embodiment;
[0061] FIG7 is a schematic diagram of finding duplicate blocks in a method for implementing a long screenshot based on the Android operating system in one embodiment;
[0062] FIG8 is a schematic diagram of a screenshot process when the height of the repeated portion and the comparison block are the same in a method for implementing a long screenshot based on an Android operating system in one embodiment;
[0063] FIG9 is a schematic diagram of a method for implementing a long screenshot based on an Android operating system after a transparent window is set in one embodiment;
[0064] FIG10 is a structural block diagram of a system for implementing long screenshots based on the Android operating system in one embodiment;
[0065] FIG11 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0066] In order to make the purpose, technical solutions and advantages of this application more clear, the following further describes this application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.
[0067] In one embodiment, a terminal is provided, which is used to: obtain a long screenshot start instruction for turning on a long screenshot; capture a current screenshot of a foreground application according to the long screenshot start instruction, wherein the foreground application is an application that is currently visible and is being used to interact with a user; control the foreground application to perform simulated screen scrolling, scrolling from bottom to top from a simulated scrolling start point to a simulated scrolling end point, and capture the foreground application during each simulated screen scrolling, to obtain multiple screenshots, wherein the simulated scrolling start point and the simulated scrolling end point are preset; set a comparison block and a reference point according to the simulated scrolling end point, and deduplicate the two process screenshots in each process screenshot according to the comparison block and the reference point to crop out the repeated parts; splice all the cropped process screenshots to generate a long screenshot.
[0068] The terminal may be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, and portable wearable devices.
[0069] In one embodiment, as shown in FIG1 , a method for implementing a long screenshot based on an Android operating system is provided, the method comprising:
[0070] Step S100: obtaining a long screenshot activation instruction for activating long screenshot;
[0071] Step S200: capturing a current screenshot of the foreground application according to the long screenshot start instruction, wherein the foreground application is an application that is currently visible and is being used to interact with the user;
[0072] Step S300: Controlling the foreground application to simulate screen scrolling, scrolling from bottom to top from a simulated scrolling start point to a simulated scrolling end point, and taking a screenshot of the foreground application during each simulated screen scrolling, obtaining multiple screenshots, wherein the simulated scrolling start point and the simulated scrolling end point are preset;
[0073] Step S400: setting a comparison block and a reference point according to the simulated scrolling end point, and deduplicating the preceding and following process screenshots in each of the process screenshots according to the comparison block and the reference point to trim out duplicate portions;
[0074] Step S500: stitching all the cropped process screenshots together to generate a long screenshot.
[0075] The present invention sequentially obtains a long screenshot start instruction for starting a long screenshot; captures a current screenshot of a foreground application according to the long screenshot start instruction, wherein the foreground application is an application that is currently visible and is being used to interact with a user; controls the foreground application to simulate screen scrolling, scrolling from bottom to top from a simulated scrolling start point to a simulated scrolling end point, and captures the foreground application during each simulated screen scrolling, obtaining multiple screenshots, wherein the simulated scrolling start point and the simulated scrolling end point are preset; sets a comparison block and a reference point according to the simulated scrolling end point, and deduplicates the two process screenshots before and after each process screenshot according to the comparison block and the reference point to crop out repeated parts; splices all the cropped process screenshots and generates a long screenshot. On the one hand, by setting the comparison block concept, the purpose of finding repeated parts is clarified and the accuracy is improved; on the other hand, by setting the reference point sum comparison concept, the comparison efficiency is greatly improved, thereby achieving a method and a method that can accurately find repeated parts in the screenshot process without invading the Android native system code, and the speed is very fast, greatly improving the efficiency and efficiency of long screenshot implementation.
[0076] In one embodiment, step S400: setting a comparison block and a reference point according to the simulated scrolling end point, and deduplicating the preceding and following process screenshots in each of the process screenshots according to the comparison block and the reference point to trim out duplicate portions; specifically includes:
[0077] Step S410: setting a predetermined clipping height according to the simulated scrolling end point, wherein the predetermined clipping height is greater than a maximum blank space in a list interface, wherein the list interface is pre-stored;
[0078] Step S420: moving the simulated scrolling end point downward by the predetermined interception height, and setting the area between the simulated scrolling end point before and after the movement as a comparison block;
[0079] Step S430: setting a reference point, and deduplicating the preceding and following process screenshots in each of the process screenshots based on the comparison block and the reference point, so as to cut out duplicated parts.
[0080] In the process of taking screenshots, the prior art has the problem of mistakenly cropping during the deduplication process. In this embodiment, the predetermined cropping height and the comparison block are set to solve the problem of mistakenly cropping during the deduplication process in the prior art.
[0081] Specifically, the Android native API provides a method for obtaining a screenshot of the current screen. This method, called the screenshot method of SurfaceControl, returns a BitMap. To more accurately and efficiently identify duplicates, the screenshots must be roughly processed before being stored in an array. This processing consists of two steps: first, rough cropping, and second, extracting the comparison blocks.
[0082] The first step, rough cropping, is shown in Figure 2. Because most interfaces have a title bar at the top and a navigation bar at the bottom, neither of which is scrollable, the start and end points of the simulated scrolling should be designed to avoid these areas and maintain a certain distance from the top and bottom edges. Once the start and end points are selected, the area that changes after scrolling is actually the area between the start and end points. The first step of rough cropping is to crop out this area, but the first and last screenshots are slightly different: the first screenshot crops from the top edge of the screen to the start point, and the last screenshot crops from the end point to the bottom edge.
[0083] Next, the comparison block is captured. Since the actual scrolling distance of the screen may be less than the set height in many cases during screen scrolling, such as when the content is still loading or the interface reaches the bottom after scrolling for a while, two consecutive screenshots may have duplicated parts. To ensure the integrity of the long screenshot, deduplication is required. The conventional deduplication method is to split the image into a two-dimensional array based on pixels and compare row by row from top to bottom until the bottom of the image or a duplicate part is found. This method has a loophole in that any duplicates will be cropped, even if the two consecutive screenshots normally have some duplicates. Please refer to Figure 3 for details. The actual scrolling distance of the screen is the set distance, but because the starting point is exactly in the middle of the interval layout, the blank part at the bottom of the first screenshot and the blank part at the top of the second screenshot are mistakenly considered to be duplicates during comparison, resulting in the interval being cut in half, making the final long screenshot incorrect.
[0084] As shown in FIG4 , in order to reduce the occurrence of erroneous clipping in conventional deduplication methods, the present invention proposes the concept of a comparison block, which slightly moves the simulated scrolling end point downward by a certain height H, which is also the predetermined clipping height.
[0085] Next, the scrolling screenshot is cut out with a height of H. The part with the height of H is the comparison block. The height of this comparison block is selected to be greater than the blank space between items in most list interfaces. As shown in Figure 4, after adding the comparison block, the bottom and top of the two screenshots must have at least a part with a height of H repeated, so there is a reference for finding the repeated part. Take out the part with a height of H at the top of the latter screenshot, and start from the bottom of the previous screenshot and search from bottom to top for a block that is exactly the same as the comparison block. This can largely avoid similar problems such as accidentally cutting blank spaces. In most cases, the repeated part is at the bottom of the previous screenshot. With a reference, the repeated part can be compared from the bottom of the previous screenshot, which not only makes the comparison faster but also improves the search efficiency.
[0086] In one embodiment, controlling the foreground application to simulate screen scrolling is achieved through the injectInputEvent(InputEvent event, int mode) method of InputManager.
[0087] The first parameter of this method is the key to simulating screen touch events. An instance of MotionEvent is created through the static method obtain(long downTime, long eventTime, int action, float x, float y, int metaState) of MotionEvent. Its parameters are the time the screen was touched, the time of this action, the action type, the x coordinate of the action execution, and the y coordinate of the action execution.
[0088] The action of simulating a finger scrolling screen event can be decomposed into pressing, moving, and lifting. The corresponding action types are MotionEvent.ACTION_DOWN, MotionEvent.ACTION_MOVE, and MotionEvent.ACTION_UP. Setting the desired scrolling distance and executing the above action simulation events in sequence can complete a simulated scrolling screen.
[0089] In one embodiment, step S430: setting a reference point, and deduplicating the preceding and following process screenshots in each of the process screenshots based on the comparison block and the reference point to trim out duplicated portions; specifically includes:
[0090] Step S431: obtaining screen width pixel points, and setting a reference point according to the screen width pixel points;
[0091] Step S432: finding duplicate blocks from the two preceding and following process screenshots in each of the process screenshots based on the reference point and the comparison block;
[0092] Step S433: trimming the repeated blocks to trim the repeated parts.
[0093] In one embodiment, in step S432 , the previous process screenshot is a first screenshot, and the next process screenshot is a second screenshot;
[0094] The step of finding repeated blocks from any two preceding and following process screenshots based on the reference point and the comparison block specifically includes:
[0095] Step S4321: Calculate the sum of all reference points in each row between the simulated scrolling start point and the simulated scrolling end point of the first screenshot, and store the sum in the int array array1. Calculate the sum of all reference points in the height portion of the comparison block in the header of the second screenshot, and store the sum in the int array array2. The lengths of the int array array1 and the int array array2 represent the number of rows of reference points to be calculated, i.e., the height of the screenshot in pixels.
[0096] Step S4322: Search for the repeated position from the end of b1 upwards, wherein the value of the int type variable compareIndex is set to be equal to the length of the int array array2;
[0097] Step S4323: Starting from the position of array1 length minus compareIndex in the int array array1, compare each item with the int array array2 in sequence. If there is a difference, compareIndex is increased by 1.
[0098] Step S4324: Repeat step S4323. If the comparison results in identical blocks, a duplicate block is generated based on the comparison result.
[0099] Specifically, before performing the deduplication operation, the screenshots need to be converted into a comparable data format. The screenshot format obtained by the system native API is Bitmap. There is a getPixels method in Bitmap that can convert all pixel points within the specified coordinates of the Bitmap into int type color values and store them in an int array. After conversion to an int array, they can be compared.
[0100] Conventional deduplication algorithms in the prior art start with the top row of pixels of the previous screenshot and compare it row by row with the next screenshot. If there are any differences, the algorithm starts from the second row and compares them row by row until there are no duplicates at the bottom of the previous screenshot or the part after a certain row of the previous screenshot is exactly the same as the part at the same height at the top of the next screenshot. The deduplication process is described in detail below:
[0101] First, set the device and values (in px): Screen resolution: 1600*720, Simulated scrolling start point: 1264, Simulated scrolling end point: 386, Height of scrolling middle screenshot: 878. As shown in Figure 5, the two screenshots before and after rough cutting are called: b1 and b2, that is, b1 is the first screenshot and b2 is the second screenshot.
[0102] Next, take the color values of all pixels from the simulated scrolling end line to the bottom in b1 and store them in the int array array1, take the color values of all pixels in b2 and save them in the int array array2, define the int variable compareLine with the value 0; then start from the item pointed to by compareLine*screen width in array1 and compare them with array2 item by item. If any different pixels are found, terminate the comparison, increment compareLine by 1, that is, compareLine=compareLine+1, and then repeat step b. If the part after compareLine*screen width in array1 is exactly the same as the part of array2 with the same length from the beginning, go to step c; then, find the repeated part, cut off the compareLine line in b1 and the part after it to complete the deduplication.
[0103] In Figure 5, the top of screenshot b2 is a large blank. Assume that the actual distance of the simulated scrolling is only half of the set distance, that is, half of it is repeated. Assume that the height of the large blank between every three numbers is 60, and the height of the small blank between each number is 5. Starting from the top, moving down row by row to compare to the repeated position requires passing through three small blanks and one large blank. Only when different pixels appear in a comparison can we know that there is no repetition. Therefore, every time we pass a blank part, we must completely compare the remaining blank lines one by one before moving down one row to start the next comparison. After passing a large blank, we need to compare The number of calculations is (60*720)+(59*720)+…+(2*720)+(1*720). According to the formula for summing an arithmetic sequence, the total number of calculations is 1,317,600. Each small blank is (5*720)*(4*720)+…+(1*720), which equals 4,320. This data does not include the comparison of the blank part to the left of the number. Finally, when the repeated rows are found, the number of comparisons of the repeated part is the repeated height*screenshot width, which is 878 / 2*720=316,080 times in this setting. The amount of comparison calculations in this process is very large.
[0104] The repeated starting position in the middle is not considered a bad situation. The worse situation is that the actual scrolling distance is the set distance, as shown in Figure 6. In this case, the comparison needs to be carried out from the top of b1 to the bottom, passing through seven small blank spaces and three large blank spaces. The comparison of the large blank space alone requires 1317600*3 (3952800) times, which is a huge amount of calculation. Moreover, because there are blank spaces at the bottom of b1 and the top of b2, this algorithm will determine that the blank spaces of equal height are repeated, and the blank space at the bottom of b1 will be mistakenly cropped, resulting in an incorrect long screenshot of the final splicing starting point. Therefore, conventional deduplication algorithms are not only very computationally intensive and time-consuming on phones with poor performance, but also have a high probability of miscropping.
[0105] It can be seen that the main reason affecting efficiency is that too many comparison calculations are performed during the process of locating repeated positions. Therefore, the design of the present invention starts with reducing the number of comparisons.
[0106] The two images are split into pixels and can be viewed as a two-dimensional array of pixels. If a row of the two images is the same, then the color value of each corresponding pixel in this row is also equal. The color value of any number of equally spaced points can be summed, and the result is also equal. These equally spaced points are named reference points, and the sum of the reference points in each row of the two identical images is also equal. Of course, the reverse is not true. The equality of the sum of the reference points in two rows does not mean that all the pixels in the two rows are equal. However, based on the premise that long screenshots are achieved by continuous screenshots and the addition of comparison blocks (the tail of the first screenshot and the head of the second screenshot must be identical by at least the height of the comparison block), an appropriate number of reference points can be selected.
[0107] For two consecutive screenshots, if the reference point sums of x consecutive lines (x is greater than or equal to the comparison block height, meaning at least 120 consecutive lines) at the end of the first screenshot match the reference point sums of x consecutive lines at the beginning of the second screenshot, then these x lines are most likely duplicates of the two screenshots. Although this algorithm for finding duplicates by comparing reference points is less accurate than conventional algorithms, the error rate is extremely low given the limitations of a series of long screenshot implementations. By switching to comparing reference points and sums, the number of calculations required for each line comparison is reduced from the number of pixels in the screenshot width to 1, greatly improving comparison efficiency. The improvement is more pronounced with higher screen resolutions, making the resulting extremely low error rate completely acceptable.
[0108] Based on the test, it was found that selecting the number of reference points as 1 / 50 of the screen width pixels can achieve higher accuracy.
[0109] The detailed deduplication steps in the present invention are as follows:
[0110] First, set the device and values (in px): screen resolution: 1600*720, comparison block height: 120, simulated scrolling start point: 1264, simulated scrolling end point: 506, comparison line position: 386, scrolling mid-screenshot height: 878. The two screenshots before and after are called: first screenshot b1, second screenshot b2. Number of reference points: 720 / 50≈15
[0111] As shown in Figure 7, in step a, the sum of the reference points of each row between the start and end points of the simulated scrolling of b1 is calculated and stored in the int array array1. The sum of the reference points of each row in the height portion of the comparison block of b2 is calculated and stored in the int array array2. The lengths of the two arrays represent the number of rows of the reference points being calculated, that is, the height of the screenshot in pixels.
[0112] In step b, the duplicate position of the screenshot is usually at the end of b1. Since the comparison block has been added, the duplicate position can be found from the end of b1 upwards. Set the int variable compareIndex to the length of array2.
[0113] Step c: Starting from the position in array1 where the length of array1 minus compareIndex is equal, compare each item in array2 in turn. If they are different, add 1 to compareIndex.
[0114] Next, repeat step c. If the comparison results are exactly the same, a repeated block can be generated. The specific steps are as follows:
[0115] If they are exactly the same, go to step d;
[0116] In step d, array1 finds a continuous block that is exactly the same as array2. Set compareIndex minus the length of array2 to N. If N is greater than 0, it proves that compareIndex was incremented N times before finding the continuous identical block. Then, it is necessary to compare the N rows after the identical continuous block in b1 with the N rows after the comparison block in b2 to see if they are also exactly the same. Calculate the reference point sum of the N rows after the comparison block in b2, append it to array2, and compare the last N bits of array1 and array2 to see if they are equal. If there is any inequality, increment compareIndex by 1, and array2 keeps the appended length unchanged, which is equivalent to increasing the height of the comparison block. Then return to step c and repeat. If they are exactly the same, proceed to step e.
[0117] In step e, find the duplicate block and trim off the portion of b1 that contains the number of compareIndex rows.
[0118] Furthermore, Figure 7 illustrates the scenario when the duplicate portion is in the middle of the image. Comparing this to Figure 6 in conventional deduplication, we also assume that the duplicate portion starts in the middle. That is, the size of H is 878 / 2 = 439. The number of calculations required to find the sum of the reference points for b1 is 878*(15-1) = 12292, and the number of calculations required to find the sum of the reference points for b2 is 120*(15-1) = 1680. Since the top of the b2 screenshot is a large blank, finding the duplicate position requires going through three blank spaces.
[0119] Assuming that the height of the large blank is 60, the comparison process requires only one calculation for each row. The number of comparison calculations required after three large blanks is (1+2+…+59+60)*3(5490). The number of calculations for adding some reference points in the remaining b2 is (439-120)*(15-1)=4466. The rough calculation number is 7902+1080+5490+2871(17343), which is much smaller than the conventional deduplication method.
[0120] We should also compare it with the scenario in Figure 6 of the conventional algorithm. The scrolling distance is exactly the set distance, so the repeated part of the two pictures is exactly the height of the comparison block. As shown in Figure 8, there is less remaining part to confirm the comparison than repeating from the middle, so the number of calculations is only 12292 + 1680 = 13972, which is also far less than the conventional deduplication algorithm.
[0121] Furthermore, during the experiment, we compared the deduplication time of real devices, as follows:
[0122] Test machine CPU model: UNISOC T606 UMS9230;
[0123] RAM: 6GB
[0124] Screen resolution: 1600*720;
[0125] Take three long screenshots of the same interface, accurately remove duplicate parts, and compare the time required to remove duplicates in milliseconds between the first and second screenshots. The data is as follows:
[0126]
[0127] In addition, experiments show that the performance improvement of the optimized algorithm is more obvious on devices with higher resolution.
[0128] Finally, stitch all the deduplicated screenshots together in order to get the complete long screenshot.
[0129] In one embodiment, step S100: obtaining a long screenshot start instruction for starting a long screenshot, and then further comprising:
[0130] Step S110: setting an overlay transparent window on the foreground application;
[0131] Step S120: setting a preset gap in the middle of the transparent window, wherein the preset gap is a gap with a pre-stored pixel width and a height that fills the screen.
[0132] Specifically, the application being captured must be the foreground application currently interacting with the user. Any screen touch events will be passed to the foreground application and consumed (the same applies to simulated scrolling events). In order to prevent the user's touch operations from interfering with simulated scrolling, the screenshot needs to receive and process touch events earlier than the application being captured.
[0133] Without invading the native system to make modifications, the screenshot application cannot intercept the consumed touch events before the foreground application, as shown in Figure 9. For this reason, the screenshot design covers a transparent window on the screenshot application so that the screenshot can receive screen touch events first. However, this will also intercept the simulated scrolling events, and the screenshot application will not be able to be scrolled. Based on this situation, the screenshot design leaves a 1-pixel wide gap in the middle of the screen and the height fills the screen. In this way, the simulated scrolling event can act on the screenshot application through this gap. The touch operation of the human hand cannot always move on a straight line of 1 pixel width, so this width of the gap ensures that the simulated scrolling is not interfered with by the user's touch.
[0134] In one embodiment, as shown in FIG10 , a long screenshot implementation system based on the Android operating system is provided, the system comprising:
[0135] A screenshot command acquisition module is used to obtain a long screenshot activation command for activating long screenshot;
[0136] a current application screenshot module, configured to capture a current screenshot of a foreground application according to the long screenshot start instruction, wherein the foreground application is an application that is currently visible and is being used to interact with the user;
[0137] a simulated scrolling screenshot module, configured to control the foreground application to simulate scrolling, scrolling from bottom to top from a simulated scrolling start point to a simulated scrolling end point, and taking a screenshot of the foreground application each time the screen is simulated scrolled, thereby obtaining multiple screenshots, wherein the simulated scrolling start point and the simulated scrolling end point are preset;
[0138] a benchmark comparison and weight removal module, configured to set a comparison block and a benchmark point according to the simulated scrolling end point, and to remove duplicates from the preceding and following process screenshots in each of the process screenshots according to the comparison block and the benchmark point, so as to remove duplicate parts;
[0139] The screenshot splicing generation module is used to splice all the cropped process screenshots and generate a long screenshot.
[0140] In one embodiment, the benchmark comparison and weight cutting module is further used to:
[0141] Setting a predetermined interception height according to the simulated scrolling end point, wherein the predetermined interception height is greater than a maximum blank space in a list-type interface, wherein the list-type interface is pre-stored;
[0142] Moving the simulated scrolling end point downward by the predetermined interception height, and setting the area between the simulated scrolling end point before the movement and the simulated scrolling end point after the movement as a comparison block;
[0143] A reference point is set, and duplicates are removed from the preceding and following process screenshots in each of the process screenshots according to the comparison block and the reference point, so as to cut out duplicate parts.
[0144] In one embodiment, the benchmark comparison and weight cutting module is further used to:
[0145] Obtaining screen width pixels and setting a reference point based on the screen width pixels;
[0146] Finding repeated blocks from the two preceding and following process screenshots in each of the process screenshots according to the reference point and the comparison block;
[0147] The repeated blocks are cut off to achieve cutting off of the repeated parts.
[0148] In one embodiment, specifically, the previous process screenshot is a first screenshot, and the next process screenshot is a second screenshot. The benchmark comparison and weight cutting module is further configured to:
[0149] Calculate the sum of all the reference points in each row between the simulated scrolling start and end points of the first screenshot and store it in the int array array1. Calculate the sum of all the reference points in the height portion of the comparison block in the header of the second screenshot and store it in the int array array2. The lengths of the int arrays array1 and array2 represent the number of rows of reference points being calculated, i.e., the height of the screenshot in pixels.
[0150] Start from the end of b1 and search for the duplicate position from bottom to top. Let the int type variable compareIndex have a value equal to the length of the int array array2.
[0151] Starting from the position of array1 length minus compareIndex in int array1, compare with each item of int array2 in turn. If they are different, compareIndex is increased by 1.
[0152] Repeat step S4323. If the comparison results in identical blocks, a duplicate block is generated based on the comparison result.
[0153] Specifically, the screenshot instruction acquisition module is further used to: set an overlay transparent window on the foreground application;
[0154] A preset gap is set in the middle of the transparent window, wherein the preset gap is a gap with a pre-stored pixel width and a height that fills the screen.
[0155] In one embodiment, as shown in FIG11 , a computer device includes a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the long screenshot implementation method based on the Android operating system when executing the computer program.
[0156] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of the long screenshot implementation method based on the Android operating system.
[0157] Those skilled in the art will appreciate that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0158] The technical features of the above embodiments can be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0159] The above-described embodiments merely represent several implementation methods of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present invention. It should be noted that a person skilled in the art could make various modifications and improvements without departing from the spirit of the present application, all of which fall within the scope of protection of the present application. Therefore, the scope of protection of the present patent application shall be determined by the appended claims.
Claims
1. A method for implementing long screenshot based on the Android operating system, characterized in that: The method comprises: Step S100: obtaining a long screenshot activation instruction for activating long screenshot; Step S200: capturing a current screenshot of the foreground application according to the long screenshot start instruction, wherein the foreground application is an application that is currently visible and is being used to interact with the user; Step S300: Controlling the foreground application to simulate screen scrolling, scrolling from bottom to top from a simulated scrolling start point to a simulated scrolling end point, and taking a screenshot of the foreground application during each simulated screen scrolling, obtaining multiple screenshots, wherein the simulated scrolling start point and the simulated scrolling end point are preset; Step S400: setting a comparison block and a reference point according to the simulated scrolling end point, and deduplicating the preceding and following process screenshots in each of the process screenshots according to the comparison block and the reference point to trim out duplicate portions; Step S500: stitching all the cropped process screenshots together to generate a long screenshot.
2. The method for implementing long screenshot based on the Android operating system according to claim 1, characterized in that: Step S400: setting a comparison block and a reference point according to the simulated scrolling end point, and deduplicating the preceding and following process screenshots in each of the process screenshots according to the comparison block and the reference point to trim out duplicated portions; specifically, the steps include: Step S410: setting a predetermined clipping height according to the simulated scrolling end point, wherein the predetermined clipping height is greater than a maximum blank space in a list interface, wherein the list interface is pre-stored; Step S420: moving the simulated scrolling end point downward by the predetermined interception height, and setting the area between the simulated scrolling end point before and after the movement as a comparison block; Step S430: setting a reference point, and deduplicating the preceding and following process screenshots in each of the process screenshots based on the comparison block and the reference point, so as to cut out duplicated parts.
3. The method for implementing long screenshot based on the Android operating system according to claim 2, characterized in that: Step S430: setting a reference point, and deduplicating the preceding and following process screenshots in each of the process screenshots based on the comparison block and the reference point, so as to cut out duplicated parts; specifically, the step S430 includes: Step S431: obtaining screen width pixel points, and setting a reference point according to the screen width pixel points; Step S432: finding duplicate blocks from the two preceding and following process screenshots in each of the process screenshots based on the reference point and the comparison block; Step S433: trimming the repeated blocks to trim the repeated parts.
4. The method for implementing long screenshot based on the Android operating system according to claim 3, characterized in that: In step S432, the previous process screenshot is the first screenshot, and the next process screenshot is the second screenshot; The step of finding repeated blocks from any two preceding and following process screenshots based on the reference point and the comparison block specifically includes: Step S4321: Calculate the sum of all reference points in each row between the simulated scrolling start point and the simulated scrolling end point of the first screenshot, and store the sum in the int array array1. Calculate the sum of all reference points in the height portion of the comparison block in the header of the second screenshot, and store the sum in the int array array2. The lengths of the int array array1 and the int array array2 represent the number of rows of reference points to be calculated, i.e., the height of the screenshot in pixels. Step S4322: Search for the repeated position from the end of b1 upwards, wherein the value of the int type variable compareIndex is set to be equal to the length of the int array array2; Step S4323: Starting from the position of array1 length minus compareIndex in the int array array1, compare each item with the int array array2 in sequence. If there is a difference, compareIndex is increased by 1. Step S4324: Repeat step S4323. If the comparison results in identical blocks, a duplicate block is generated based on the comparison result.
5. The method for implementing long screenshot based on the Android operating system according to any one of claims 1 to 4, characterized in that: Step S100: obtaining a long screenshot activation instruction for activating long screenshot, followed by: Step S110: setting an overlay transparent window on the foreground application; Step S120: setting a preset gap in the middle of the transparent window, wherein the preset gap is a gap with a pre-stored pixel width and a height that fills the screen.
6. A long screenshot implementation system based on the Android operating system, characterized in that: The system comprises: A screenshot command acquisition module is used to obtain a long screenshot activation command for activating long screenshot; a current application screenshot module, configured to capture a current screenshot of a foreground application according to the long screenshot start instruction, wherein the foreground application is an application that is currently visible and is being used to interact with the user; a simulated scrolling screenshot module, configured to control the foreground application to simulate scrolling, scrolling from bottom to top from a simulated scrolling start point to a simulated scrolling end point, and taking a screenshot of the foreground application each time the screen is simulated scrolled, thereby obtaining multiple screenshots, wherein the simulated scrolling start point and the simulated scrolling end point are preset; a benchmark comparison and weight removal module, configured to set a comparison block and a benchmark point according to the simulated scrolling end point, and to remove duplicates from the preceding and following process screenshots in each of the process screenshots according to the comparison block and the benchmark point, so as to remove duplicate parts; The screenshot splicing generation module is used to splice all the cropped process screenshots and generate a long screenshot.
7. The long screenshot implementation system based on the Android operating system according to claim 6, characterized in that: The benchmark comparison and weight cutting module is also used for: Setting a predetermined interception height according to the simulated scrolling end point, wherein the predetermined interception height is greater than a maximum blank space in a list-type interface, wherein the list-type interface is pre-stored; Moving the simulated scrolling end point downward by the predetermined interception height, and setting the area between the simulated scrolling end point before the movement and the simulated scrolling end point after the movement as a comparison block; A reference point is set, and duplicates are removed from the preceding and following process screenshots in each of the process screenshots according to the comparison block and the reference point, so as to cut out duplicate parts.
8. The long screenshot implementation system based on the Android operating system according to claim 7, characterized in that: The benchmark comparison and weight cutting module is also used for: Obtaining screen width pixels and setting a reference point based on the screen width pixels; According to the reference point and the comparison block, duplicate blocks are found from the two preceding and following process screenshots in each process screenshot; and the duplicate blocks are cut off to trim the duplicate portion.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 5 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Long screen capture method for mobile terminal
CN107229401A
Long screen capture method and device
CN108108217A
Screen interface long screenshot method, mobile terminal and computer readable storage medium
CN110209456A
Method and apparatus for controlling scrolling
US20140055395A1