A method for drawing a large picture
By dividing the total background buffered image Bitmap into several background buffered image Bitmap and enlarging and drawing in equal proportions according to the area to be displayed, the problems of failure in drawing large images, excessive memory usage and interface lag in traditional drawing methods are solved, and a more efficient drawing process is achieved.
Patent Information
- Application Number
- CN202411063103.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-05
- Publication Date
- 2025-04-08
- Estimated Expiration
- 2044-08-05
AI Technical Summary
Traditional Bitmap-based double-cache drawings are likely to lead to drawing failure, excessive memory usage and interface lag when drawing large images.
By dividing the total background buffered image Bitmap into several background buffered image Bitmap and enlarging and drawing in proportion according to the area to be displayed, memory usage is reduced and drawing efficiency is improved.
It effectively solves the drawing failure problem caused by the size of the graph exceeding the Bitmap range, reduces memory usage and interface lag, and improves drawing efficiency.
Smart Images

Figure CN118887074B_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of drawing and relates to a large-scale drawing method. Background Art
[0002] Traditional drawing generally uses double-buffered drawing based on Bitmap to solve the problem of screen flickering during drawing. However, due to the limited size of Bitmap, it is easy to have the following defects when using a single Bitmap to draw a large picture:
[0003] 1) If the size of the image exceeds the range of the Bitmap, drawing will fail;
[0004] 2) At present, sometimes you need to view the details of the drawn image, and you need to enlarge the image. That is, when drawing, you need to enlarge the entire Bitmap in proportion (the width and height of the Bitmap need to be multiplied by the enlargement factor at the same time). Therefore, when enlarging the image, the memory occupied will increase;
[0005] 3) When we need to enlarge the image or switch the content on the screen, we need to refresh the interface, which requires a redraw operation; the entire Bitmap needs to be drawn and displayed, resulting in a long refresh time and the user interface is prone to freezes. Summary of the invention
[0006] In view of this, an object of the present invention is to provide a large-scale image drawing method to solve the technical problems mentioned in the prior art.
[0007] A large-scale image drawing method comprises the following steps:
[0008] Set the size of the background buffer image Bitmap;
[0009] Determine the number of columns of the background buffer image Bitmap in the total background buffer image Bitmap and the size of each column of the background buffer image Bitmap according to the width of the image to be drawn, and determine the number of rows of the background buffer image Bitmap in the total background buffer image Bitmap and the size of each row of the background buffer image Bitmap according to the height of the image to be drawn;
[0010] Calculating the position of the pixel point where each of the background buffer image Bitmaps is located in the total background buffer image Bitmap according to the size of each of the background buffer image Bitmaps;
[0011] The sizes of the scroll bars in the horizontal and vertical directions are set according to the size of the total background buffer image Bitmap;
[0012] Finding the background buffer image Bitmap that needs to be displayed on the screen according to the position of the pixel point where each background buffer image Bitmap is located and the position of the scroll bar;
[0013] Create the background buffer image Bitmap to be displayed on the screen, and draw on the created background buffer image Bitmap as required;
[0014] The drawn background buffer image Bitmap is displayed on the screen, and the memory is released.
[0015] Optionally, the size of the background buffer image Bitmap includes the width and height of the background buffer image Bitmap, and the set width and height of the background buffer image Bitmap are saved in a configuration file.
[0016] Optionally, the values of the columns and rows of the total background buffer image Bitmap are calculated respectively according to the width and height of the image to be drawn.
[0017] Optionally, the total number of columns of the background buffer image Bitmap is calculated as follows:
[0018] Divide the width of the image to be drawn by the width of the background buffer image Bitmap in the configuration file, round the calculation result and determine whether the remainder of the calculation result is 0;
[0019] If the remainder of the calculation result is 0, the total number of columns of the background buffer image Bitmap is an integer of the calculation result;
[0020] If the remainder of the calculation result is not 0, the number of columns of the total background buffer image Bitmap is the integer of the calculation result plus 1, and the width of the last column of the total background buffer image Bitmap is the remainder of the calculation result.
[0021] Optionally, the total number of rows of the background buffer image Bitmap is calculated as follows:
[0022] Divide the height of the image to be drawn by the height of the background buffer image Bitmap in the configuration file, round the calculation result and determine whether the remainder of the calculation result is 0;
[0023] If the remainder of the calculation result is 0, the total number of rows of the background buffer image Bitmap is an integer of the calculation result;
[0024] If the remainder of the calculation result is not 0, the number of rows of the total background buffer image Bitmap is the integer of the calculation result plus 1, and the height of the last row of the total background buffer image Bitmap is the remainder of the calculation result.
[0025] Optionally, the width and height of the background buffer image Bitmap are read from the configuration file, and the position of the pixel point of each background buffer image Bitmap in the total background buffer image Bitmap is calculated according to the column and row where each background buffer image Bitmap is located;
[0026] The horizontal coordinate of the starting position of the background buffer image Bitmap is column number*width, and the vertical coordinate is row number*height, and the starting numbering of the row number and the column number both starts from 0.
[0027] Optionally, when the drawn image is larger than the background buffer image Bitmap that needs to be displayed on the screen, the scroll bar is set on the background buffer image Bitmap that needs to be displayed on the screen, and the value of the scroll bar along the horizontal direction is equal to the width of the image that needs to be displayed on the screen, and the value of the scroll bar along the vertical direction is equal to the height of the image that needs to be displayed on the screen.
[0028] Optionally, the background buffer image Bitmap to be drawn is captured according to the current position of the scroll bar and the position of each pixel point of the background buffer image Bitmap, wherein;
[0029] If the captured background buffer image Bitmap meets any of the following drawing conditions, no drawing is required;
[0030] If the captured background buffer image Bitmap does not meet all the following drawing conditions, it needs to be drawn;
[0031] The drawing conditions are specifically:
[0032] A. The horizontal end position of the background buffer image Bitmap is less than 0, and the horizontal end position of the background buffer image Bitmap is the horizontal start position of the background buffer image Bitmap + the horizontal position of the scroll bar + the width of the corresponding background buffer image Bitmap;
[0033] B. The horizontal starting position of the background buffer image Bitmap is greater than the width of the display area, and the horizontal starting position of the background buffer image Bitmap is the horizontal starting position of the background buffer image Bitmap + the horizontal position of the scroll bar;
[0034] C. The vertical end position of the background buffer image Bitmap is less than 0, and the vertical end position of the background buffer image Bitmap is the vertical start position of the background buffer image Bitmap + the position of the scroll bar in the vertical direction + the height of the corresponding background buffer image Bitmap;
[0035] D. The vertical starting position of the background buffer image Bitmap is greater than the height of the display area, and the vertical starting position of the background buffer image Bitmap is the vertical starting position of the background buffer image Bitmap + the position of the scroll bar along the vertical direction.
[0036] Optionally, the method for creating the background buffer image Bitmap to be displayed on the screen is:
[0037] The background buffer image Bitmap to be displayed on the screen is created using a Bitmap creation function according to the calculated width and height of each background buffer image Bitmap.
[0038] Optionally, the method for releasing the memory is:
[0039] The background buffer image Bitmap displayed on the screen is released using the Bitmap release function.
[0040] The beneficial effects that the present invention can produce include:
[0041] The invention provides a large-image drawing method, which divides a total background buffer image Bitmap into a plurality of background buffer image Bitmaps with a width of X and a height of Y by adopting a bitmap segmentation method, thereby effectively solving the problem of drawing failure caused by the size of the image exceeding the range of the background buffer image Bitmap. At the same time, after the total background buffer image Bitmap is segmented, the coordinate position of each background buffer image Bitmap will be recalculated according to the equal proportion when drawing, and then the background buffer image Bitmap to be displayed on the screen will be found according to the coordinate position of the background buffer image Bitmap. Although the background buffer image Bitmap still needs to be enlarged in equal proportion after the total background buffer image Bitmap is segmented, because the size of the screen is fixed, the number of background buffer image Bitmaps to be displayed after enlargement will be reduced, so the memory used during creation will not be too large, and the change is not very large, and the memory occupation is relatively stable. In addition, after the total background buffer image Bitmap is segmented, according to finding the background buffer image Bitmap to be displayed on the screen, only the content within the visible range needs to be drawn when drawing, and it is not necessary to draw all of them, so the time used will be relatively less, and the interface jamming phenomenon will also be reduced. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 The present invention is a schematic diagram of a large picture drawing method. DETAILED DESCRIPTION
[0043] The present invention is described in detail below with reference to the accompanying drawings and embodiments, but the present invention is not limited to these embodiments.
[0044] like Figure 1 As shown, the present invention provides a large image drawing method, comprising the following steps: before use, firstly, a preprocessing module is configured according to the interface display size of the user system, the preprocessing module is used to obtain the interface display size of the system, and calculate the size value range of the background buffer image Bitmap (bitmap) of the corresponding system according to the obtained interface display size, and then arbitrarily select a value within the size value range of the background buffer image Bitmap as the size setting value of the background buffer image Bitmap of the system this time, and calculate the number of background buffer image Bitmaps required for the current drawing according to the size setting value of the background buffer image Bitmap selected this time (the number consists of rows and columns), thereby obtaining a plurality of groups of data samples to form a database, wherein each group of data samples is the number corresponding to the size of the corresponding background buffer image Bitmap, so that the user can call one of the groups of data samples from the database as a reference to set the size of a single background buffer image Bitmap according to the size of the current drawing to be drawn, which can improve the matching degree of the background buffer image Bitmap in the user system, thereby ensuring that a single background buffer image Bitmap is successfully drawn in the system, and there is no need to perform multiple tests to obtain a single background buffer image Bitmap The drawing threshold in the system is used to shorten the drawing time; wherein, the size of the background buffer image Bitmap includes the width and height of the background buffer image Bitmap, and the set width and height of the background buffer image Bitmap are saved in the configuration file; then, the number and size of the background buffer image Bitmap in each row in the total background buffer image Bitmap are determined according to the width of the image to be drawn, and the number and size of the background buffer image Bitmap in each column in the total background buffer image Bitmap are determined according to the height of the image to be drawn; then, the position of the pixel point where each background buffer image Bitmap in the total background buffer image Bitmap is located is calculated according to the size of each background buffer image Bitmap; the size of the scroll bar in the horizontal direction and the vertical direction is set according to the size of the total background buffer image Bitmap; the background buffer image Bitmap to be displayed on the screen is found according to the position of the pixel point where each background buffer image Bitmap is located and the position of the scroll bar; the background buffer image Bitmap to be displayed on the screen is created, and drawing is performed on the created background buffer image Bitmap as required; the drawn background buffer image Bitmap is displayed on the screen, and the memory is released.
[0045] In the above, the values of the columns and rows of the total background buffer image Bitmap are calculated according to the width and height of the image to be drawn. Specifically, the method for calculating the number of columns of the total background buffer image Bitmap is: divide the width of the image to be drawn by the width of the background buffer image Bitmap in the configuration file, round the calculation result and determine whether the remainder of the calculation result is 0; if the remainder of the calculation result is 0, the number of columns of the total background buffer image Bitmap is the integer of the calculation result; if the remainder of the calculation result is not 0, the number of columns of the total background buffer image Bitmap is the integer of the calculation result plus 1, and the width of the last column of the total background buffer image Bitmap is the remainder of the calculation result. The total number of rows of the background buffer image Bitmap is calculated as follows: divide the height of the image to be drawn by the height of the background buffer image Bitmap in the configuration file, round the calculation result and determine whether the remainder of the calculation result is 0; if the remainder of the calculation result is 0, the total number of rows of the background buffer image Bitmap is the integer of the calculation result; if the remainder of the calculation result is not 0, the total number of rows of the background buffer image Bitmap is the integer of the calculation result plus 1, and the height of the last row of the total background buffer image Bitmap is the remainder of the calculation result.
[0046] In the above embodiment, if the height of the drawn image is 3000, and the height of each background buffer image Bitmap is set to 300, then the total background buffer image Bitmap has 10 rows, and the height of each row of the background buffer image Bitmap is 300; if the height of the drawn image is 3100, and the height of each background buffer image Bitmap is set to 300, then the total background buffer image Bitmap has 11 rows, of which 10 rows of the background buffer image Bitmap have a height of 300, and the height of the last row of the background buffer image Bitmap is 100. It should be noted that the calculation method of the column is the same as the calculation method of the row, and the width of the last column is the remainder of the ratio of the width of the total background buffer image Bitmap to the width of the background buffer image Bitmap.
[0047] In the above, the width and height of the background buffer image Bitmap are read from the configuration file, and the position of the pixel point in the total background buffer image Bitmap is calculated according to the column and height of each background buffer image Bitmap; the horizontal coordinate of the starting position of the background buffer image Bitmap is column number * width, and the vertical coordinate is row number * height, and the starting number of the row number and column number both start from 0. Specifically, the coordinate position (X, Y) of each background buffer image Bitmap at the time of drawing can be calculated according to the starting position of each background buffer image Bitmap and the current position of the scroll bar, wherein the X coordinate is the column number * width of the starting position of the background buffer image Bitmap + the horizontal coordinate value of the scroll bar, and the Y coordinate is the row number * height of the starting position of the background buffer image Bitmap + the vertical coordinate value of the scroll bar. If the current scroll bar position is (-1000, -2000), the coordinate of the starting position of the background buffer image Bitmap is (1100, 2300), then the coordinate position at the time of drawing is (100, 300).
[0048] In the above, when the drawn image is larger than the background buffer image Bitmap to be displayed on the screen, a scroll bar is set in the background buffer image Bitmap to be displayed on the screen, and the value of the scroll bar along the horizontal direction is equal to the width of the image to be displayed on the screen, and the value of the scroll bar along the vertical direction is equal to the height of the image to be displayed on the screen. Specifically, when determining the background buffer image Bitmap to be displayed on the screen, first obtain the current position of the scroll bar according to the scroll bar acquisition position function; wherein, the scroll bar acquisition position function along the vertical direction is:
[0049] AutoScrollposition.Y;
[0050] The function for getting the position of the scroll bar in the horizontal direction is:
[0051] AutoScrollposition.X;
[0052] It should be noted that the scroll bar size setting function is obtained by assigning a specific value to the scroll bar position obtaining function, and the specific output result of the scroll bar position obtaining function changes in real time according to the current position of the scroll bar.
[0053] In the above, the background buffer image Bitmap to be drawn is captured according to the current position of the scroll bar and the position of the pixel points of each background buffer image Bitmap, wherein; if the captured background buffer image Bitmap meets any of the following drawing conditions, it does not need to be drawn; if the captured background buffer image Bitmap does not meet all of the following drawing conditions, it needs to be drawn; the specific drawing conditions are:
[0054] A. The horizontal end position of the background buffer image Bitmap is less than 0. The horizontal end position of the background buffer image Bitmap is the horizontal start position of the background buffer image Bitmap + the horizontal position of the scroll bar + the width of the corresponding background buffer image Bitmap;
[0055] B. The horizontal starting position of the background buffer image Bitmap is greater than the width of the display area. The horizontal starting position of the background buffer image Bitmap is the horizontal starting position of the background buffer image Bitmap + the horizontal position of the scroll bar;
[0056] C. The vertical end position of the background buffer image Bitmap is less than 0. The vertical end position of the background buffer image Bitmap is the vertical start position of the background buffer image Bitmap + the position of the scroll bar in the vertical direction + the height of the corresponding background buffer image Bitmap;
[0057] D. The vertical starting position of the background buffer image Bitmap is greater than the height of the display area. The vertical starting position of the background buffer image Bitmap is the vertical starting position of the background buffer image Bitmap + the position of the scroll bar along the vertical direction.
[0058] In the above, the method for creating the background buffer image Bitmap to be displayed on the screen is: using the Bitmap creation function to create the background buffer image Bitmap to be displayed on the screen according to the calculated width and height of each background buffer image Bitmap; specifically, the Bitmap creation function is:
[0059] Bitmap bitmap=new Bitmap(width,height).
[0060] In the above, the method for releasing the memory is: using the Bitmap release function to release the background buffer image Bitmap displayed on the screen. Specifically, the Bitmap release function is:
[0061] bitmap.Dispose();
[0062] bitmap = null;
[0063] At this time, the Bitmap release function can be used to recycle the background buffer image Bitmap that is not needed on the screen, so as to completely release the background buffer image Bitmap and reduce memory usage.
[0064] In the above, the present application adopts the method of bitmap segmentation to segment the total background buffer image Bitmap into several background buffer image Bitmaps with a width of X and a height of Y, thereby effectively solving the problem of drawing failure caused by the size of the image exceeding the range of the background buffer image Bitmap. At the same time, after the total background buffer image Bitmap is segmented, the coordinate position of each background buffer image Bitmap will be recalculated according to the equal proportion when drawing, and then the background buffer image Bitmap that needs to be displayed on the screen is found according to the coordinate position of the background buffer image Bitmap. Although the background buffer image Bitmap still needs to be enlarged in proportion after the total background buffer image Bitmap is segmented, because the size of the screen is fixed, the number of background buffer image Bitmaps that need to be displayed after enlargement will be reduced, so the memory used during creation will not be too large, and the change is not very large, and the memory occupied is relatively stable. In addition, after the total background buffer image Bitmap is segmented, according to the background buffer image Bitmap that needs to be displayed on the screen, only the content within the visible range needs to be drawn when drawing, and it is not necessary to draw all of it, so the time used will be relatively less, and the interface jamming phenomenon will also be reduced.
[0065] The above are only several embodiments of the present invention and are not intended to limit the present invention in any form. Although the present invention is disclosed as above in the form of a preferred embodiment, it is not intended to limit the present invention. Any technician familiar with the profession, without departing from the scope of the technical solution of the present invention, using the above disclosed technical content to make slight changes or modifications are equivalent to equivalent implementation cases and fall within the scope of the technical solution.
Claims
1. A large picture drawing method, characterized in that: The following steps are involved: Setting the size of the background buffer image Bitmap, the size of the background buffer image Bitmap includes the width and height of the background buffer image Bitmap, and saving the set width and height of the background buffer image Bitmap in a configuration file; Determine the number of columns of the background buffer image Bitmap in the total background buffer image Bitmap and the size of each column of the background buffer image Bitmap according to the width of the image to be drawn, and determine the number of rows of the background buffer image Bitmap in the total background buffer image Bitmap and the size of each row of the background buffer image Bitmap according to the height of the image to be drawn; Calculating the position of the pixel point where each of the background buffer image Bitmaps is located in the total background buffer image Bitmap according to the size of each of the background buffer image Bitmaps, wherein the width and height of the background buffer image Bitmaps are read from the configuration file, and calculating the position of the pixel point where each of the background buffer image Bitmaps is located in the total background buffer image Bitmap according to the column and row where the background buffer image Bitmap is located; The sizes of the scroll bars in the horizontal and vertical directions are set according to the size of the total background buffer image Bitmap; Finding the background buffer image Bitmap that needs to be displayed on the screen according to the position of the pixel point where each background buffer image Bitmap is located and the position of the scroll bar; Create the background buffer image Bitmap to be displayed on the screen, and draw on the created background buffer image Bitmap as required; The drawn background buffer image Bitmap is displayed on the screen, and the memory is released.
2. A large-scale drawing method according to claim 1, characterized in that: The calculation method of the number of columns of the background buffer image Bitmap in the total background buffer image Bitmap is: Divide the width of the image to be drawn by the width of the background buffer image Bitmap in the configuration file, round the calculation result and determine whether the remainder of the calculation result is 0; If the remainder of the calculation result is 0, the number of columns of the background buffer image Bitmap in the total background buffer image Bitmap is an integer of the calculation result; If the remainder of the calculation result is not 0, the number of columns of the background buffer image Bitmap in the total background buffer image Bitmap is the integer of the calculation result plus 1, and the width of the last column of the background buffer image Bitmap in the total background buffer image Bitmap is the remainder of the calculation result.
3. A large-scale drawing method according to claim 1, characterized in that: The calculation method of the number of rows of the background buffer image Bitmap in the total background buffer image Bitmap is: Divide the height of the image to be drawn by the height of the background buffer image Bitmap in the configuration file, round the calculation result and determine whether the remainder of the calculation result is 0; If the remainder of the calculation result is 0, the number of rows of the background buffer image Bitmap in the total background buffer image Bitmap is an integer of the calculation result; If the remainder of the calculation result is not 0, the number of rows of the background buffer image Bitmap in the total background buffer image Bitmap is the integer of the calculation result plus 1, and the height of the last row of the background buffer image Bitmap in the total background buffer image Bitmap is the remainder of the calculation result.
4. A large-scale drawing method according to claim 1, characterized in that: The horizontal coordinate of the starting position of the background buffer image Bitmap is column number*width, and the vertical coordinate is row number*height, and the starting numbering of the row number and the column number both starts from 0.
5. A large-scale drawing method according to claim 4, characterized in that: When the drawn image is larger than the background buffer image Bitmap that needs to be displayed on the screen, the scroll bar is set on the background buffer image Bitmap that needs to be displayed on the screen, and the value of the scroll bar along the horizontal direction is equal to the width of the image that needs to be displayed on the screen, and the value of the scroll bar along the vertical direction is equal to the height of the image that needs to be displayed on the screen.
6. A large-scale drawing method according to claim 5, characterized in that: The background buffer image Bitmap to be drawn is captured according to the current position of the scroll bar and the position of each pixel point of the background buffer image Bitmap, wherein; If the captured background buffer image Bitmap meets any of the following drawing conditions, no drawing is required; If the captured background buffer image Bitmap does not meet all the following drawing conditions, it needs to be drawn; The drawing conditions are specifically: A. The horizontal end position of the background buffer image Bitmap is less than 0, and the horizontal end position of the background buffer image Bitmap is the horizontal start position of the background buffer image Bitmap + the horizontal position of the scroll bar + the width of the corresponding background buffer image Bitmap; B. The horizontal starting position of the background buffer image Bitmap is greater than the width of the display area, and the horizontal starting position of the background buffer image Bitmap is the horizontal starting position of the background buffer image Bitmap + the horizontal position of the scroll bar; C. The vertical end position of the background buffer image Bitmap is less than 0, and the vertical end position of the background buffer image Bitmap is the vertical start position of the background buffer image Bitmap + the position of the scroll bar in the vertical direction + the height of the corresponding background buffer image Bitmap; D. The vertical starting position of the background buffer image Bitmap is greater than the height of the display area, and the vertical starting position of the background buffer image Bitmap is the vertical starting position of the background buffer image Bitmap + the position of the scroll bar along the vertical direction.
7. A large-scale drawing method according to claim 1, characterized in that: The method for creating the background buffer image Bitmap to be displayed on the screen is: The background buffer image Bitmap to be displayed on the screen is created using a Bitmap creation function according to the calculated width and height of each background buffer image Bitmap.
8. A large-scale drawing method according to claim 1, characterized in that: The method to release memory is: The background buffer image Bitmap displayed on the screen is released using the Bitmap release function.
Citation Information
Patent Citations
Method and system for large image display
KR1020010000208A