Drawing method of large-pixel BMP format image
Technical Field
The invention relates to the technical field of software programming image processing, in particular to a drawing method of a large-pixel BMP format image.
Background
The processing method for the image in the program generally comprises the steps of converting pixel coordinates by collecting two-dimensional vector coordinates and then calling a drawing tool library such as: easyX, GDI, GUI, but EasyX, GDI, GUI, etc. have a certain limitation on the pixel size of the picture, when the pixel size of the picture exceeds the limit range, the program cannot create the canvas with the pixel size, or the canvas with the pixel size can be created successfully, but the picture can only be drawn locally and cannot be drawn into a complete picture, so that the picture with large pixel is drawn into a certain technical bottleneck.
For example, c++ provided drawing tools library draws 60253 x 17181 pixels of BMP format pictures only to draw partial pictures. Referring to the following drawings in detail, wherein fig. 1 is a target drawing picture, and fig. 8 is an actual drawing incomplete picture.
Disclosure of Invention
It is necessary to propose a method for rendering large-pixel BMP-format images.
A drawing method of a large-pixel BMP format image comprises the following steps:
pre-dividing an image to be drawn into a first image and a second image;
establishing a first canvas and a second canvas;
digging out the position of the partial image occupied by the second image on the first canvas, storing the position of the partial image occupied by the second image on the second canvas, and recording the identification coordinate point of the position of the partial image which is dug out on the first canvas;
drawing a first image and a second image on a first canvas and a second canvas, respectively;
filling a second canvas drawn with a second image into the first canvas, and keeping the initial coordinate point of the second canvas coincident with the identification coordinate point on the first canvas to form a large image drawn on the same canvas;
and storing the first canvas output in a final BMP file to finish the output of the matted filling large-pixel image.
Preferably, the maximum side length of the first image and the second image is not more than 60253/2.
Preferably, the coordinates of the identification coordinate points of the position of the partial image to be scratched on the first canvas are (Xa, ya, W, H), wherein Xa and Ya are the coordinates of the X axis and the coordinates of the Y axis of the canvas respectively, W is the length of the partial canvas to be scratched, and H is the height of the partial canvas to be scratched, so as to uniquely locate the position and the contour of the partial image to be scratched.
Preferably, the image to be drawn is pre-divided into a first image, a second image and a third image along the X-axis direction;
establishing a first canvas, establishing a second canvas and establishing a third canvas;
digging out the position of a second partial image occupied by the second image on the first canvas, storing the position of the second partial image on the second canvas, and recording a second identification coordinate point of the position of the second partial image which is dug out on the first canvas; digging out a third part of image position occupied by the third image on the first canvas, storing the third part of image position occupied by the third image on the third canvas, and recording a third identification coordinate point of the scratched third part of image position on the first canvas;
drawing a first image, a second image and a third image on a first canvas, a second canvas and a third canvas respectively;
filling a second canvas drawn with a second image into the first canvas, and keeping the initial coordinate point of the second canvas coincident with a second identification coordinate point on the first canvas; filling a third canvas drawn with a third image into the first canvas, and keeping the initial coordinate point of the third canvas coincident with a third identification coordinate point on the first canvas to form a large image drawn on the same canvas;
and storing the first canvas output in a final BMP file to finish the output of the matted filling large-pixel image.
Preferably, the image to be drawn is pre-divided into a first image, a second image and a third image along the X-axis and Y-axis directions;
establishing a first canvas, establishing a second canvas and establishing a third canvas;
digging out the position of a second partial image occupied by the second image on the first canvas, storing the position of the second partial image on the second canvas, and recording a second identification coordinate point of the position of the second partial image which is dug out on the first canvas; digging out a third part of image position occupied by the third image on the first canvas, storing the third part of image position occupied by the third image on the third canvas, and recording a third identification coordinate point of the scratched third part of image position on the first canvas;
drawing a first image, a second image and a third image on a first canvas, a second canvas and a third canvas respectively;
filling a second canvas drawn with a second image into the first canvas, and keeping the initial coordinate point of the second canvas coincident with a second identification coordinate point on the first canvas; filling a third canvas drawn with a third image into the first canvas, and keeping the initial coordinate point of the third canvas coincident with a third identification coordinate point on the first canvas to form a large image drawn on the same canvas;
and storing the first canvas output in a final BMP file to finish the output of the matted filling large-pixel image.
The invention adopts the method of drawing and supplementing on canvas with the same size to solve the problem that larger pixel pictures can not be drawn by adopting a common drawing method, and the method is simpler and more convenient in understanding and code realization and has a certain use value.
Drawings
Fig. 1 is a schematic diagram of a large image to be drawn.
FIG. 2 is a schematic diagram of a partial image location scratched out on a first canvas.
FIG. 3 is a schematic diagram of a first canvas of C++.
FIG. 4 is a schematic diagram of a second canvas of C++.
Fig. 5 is a schematic drawing of a first image on a first canvas.
FIG. 6 is a schematic drawing of a second image on a second canvas.
FIG. 7 is a schematic diagram of a large image supplementing a second image on a first canvas.
Fig. 8 is an image of a prior art drawing using c++. As can be seen, the second image is not completely drawn on the canvas.
Fig. 9 is a schematic diagram of another division of a large image to be drawn.
FIG. 10 is a schematic diagram of the second image of FIG. 9 drawn on a second canvas.
FIG. 11 is a schematic drawing of the third image divided in FIG. 9 on a third canvas.
Fig. 12 is a schematic diagram of a third division manner of a large image to be drawn.
FIG. 13 is a schematic drawing of the second image divided in FIG. 12 on a second canvas.
FIG. 14 is a schematic drawing of the third image divided in FIG. 12 on a third canvas.
In the figure: the first image 10, the second image 20, the first canvas 30, the second canvas 40, the partial image position 50, the second partial image position 60, the third partial image position 70, the second partial image position 601, the third partial image position 701.
Detailed Description
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings that are needed in the embodiments will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
Referring to fig. 1 to 7, an embodiment of the present invention provides a method for drawing a BMP-formatted image with large pixels, including the steps of:
pre-dividing the image to be drawn into a first image 10 and a second image 20;
establishing a first canvas 30;
establishing a second canvas 40, matting out the partial image position 50 occupied by the second image 20 on the first canvas 30, (namely, the second image 20 is a partial image which cannot be drawn on the first canvas 30) and storing the partial image position 50 on the second canvas 40, and recording the identification coordinate points A (Xa, ya) of the scratched partial image position 50 on the first canvas 30;
drawing the first image 10 and the second image 20 on the first canvas 30 and the second canvas 40, respectively;
filling a second canvas 40 drawn with a second image 20 into the first canvas 30, keeping the initial coordinate points B (Xb and Yb) of the second canvas 40 coincident with the identification coordinate points A (Xa and Ya) on the first canvas 30, and forming a large image drawn on the same canvas (namely the first canvas 30);
the output of the first canvas 30 is stored in the final BMP file, and the output of the matted filling large-pixel image is completed.
Further, the maximum side length of the first image and the second image is not greater than 60253/2. Because the maximum array which can be identified by the drawing program in the drawing tool used in the invention is 2 32 While the array occupies no more than 60253/2 in the canvas, the maximum side length of the divided image is limited to be no more than 60253/2 in order to avoid that the image cannot be displayed completely in the canvas.
Further, the coordinates of the identification coordinate points of the position of the scratched partial image on the first canvas are A (Xa, ya, W, H), wherein Xa and Ya are the coordinates of the X axis and the coordinates of the Y axis of the canvas respectively, W is the length of the scratched partial canvas, and H is the height of the scratched partial canvas so as to uniquely position the position and the outline of the scratched partial canvas.
Furthermore, the method of the invention can also carry out multi-block division on the large pixel image, wherein the multi-block division comprises division in the same direction and division in different directions. For example, the following improvement method is divided into the first one along the same direction, the second one along the different directions, and so on, and the method is suitable for drawing images in which larger images are divided into different directions and are divided into different properties.
Referring to fig. 9-11, the improvement method one: pre-dividing an image to be drawn into a first image, a second image and a third image; the dividing method is to divide the image along the X-axis direction.
Establishing a first canvas;
establishing a second canvas, establishing a third canvas, digging out a second part of image position 60 occupied by the second image on the first canvas, storing the second part of image position 60 on the second canvas, and recording second identification coordinate points C (Xc, yc) of the second part of image position which is dug out on the first canvas; a third part of image position 70 occupied by the third image is scratched out on the first canvas and stored on the third canvas, and third identification coordinate points D (Xd and Yd) of the scratched out third part of image position are recorded on the first canvas;
drawing a first image, a second image and a third image on a first canvas, a second canvas and a third canvas respectively;
filling a second canvas drawn with a second image into the first canvas, and keeping a starting coordinate point C' of the second canvas coincident with a second identification coordinate point C on the first canvas; filling a third canvas drawn with a third image into the first canvas, and keeping the initial coordinate point D' of the third canvas coincident with the third identification coordinate point D on the first canvas to form a large image drawn on the same canvas;
and storing the first canvas output in a final BMP file to finish the output of the matted filling large-pixel image.
Referring to fig. 12-14, the improvement method two: pre-dividing an image to be drawn into a first image, a second image and a third image; the dividing method is to divide the image along the X-axis and Y-axis directions.
Establishing a first canvas;
establishing a second canvas, establishing a third canvas, digging out a second part of image position 601 occupied by the second image on the first canvas, storing the second part of image position 601 on the second canvas, and recording second identification coordinate points C1 (Xc and Yc) of the second part of image position which is dug out on the first canvas; a third part of image position 701 occupied by the third image is scratched out on the first canvas and stored on the third canvas, and third identification coordinate points D1 (Xd and Yd) of the scratched out third part of image position are recorded on the first canvas;
drawing a first image, a second image and a third image on a first canvas, a second canvas and a third canvas respectively;
filling a second canvas drawn with a second image into the first canvas, and keeping a starting coordinate point C1' of the second canvas coincident with a second identification coordinate point C1 on the first canvas; filling a third canvas drawn with a third image into the first canvas, and keeping the initial coordinate point D1' of the third canvas coincident with the third identification coordinate point D1 on the first canvas to form a large image drawn on the same canvas;
and storing the first canvas output in a final BMP file to finish the output of the matted filling large-pixel image.
The modules or units in the device of the embodiment of the invention can be combined, divided and deleted according to actual needs.
The foregoing disclosure is illustrative of the preferred embodiments of the present invention, and is not to be construed as limiting the scope of the invention, as it is understood by those skilled in the art that all or part of the above-described embodiments may be practiced with equivalents thereof, which fall within the scope of the invention as defined by the appended claims.