A method, device and related components for implementing Qt preview of large-size images
By performing grid processing and view scene management on large-resolution images, the problem of large memory usage after image loading preview is solved, and efficient large-resolution image browsing function is realized.
Patent Information
- Application Number
- CN202210768811.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-30
- Publication Date
- 2025-06-13
- Estimated Expiration
- 2042-06-30
AI Technical Summary
Existing large-resolution images will take up more memory after loading the preview, resulting in computer performance degradation.
By loading the image file data into memory objects and grid processing them, dividing them into multiple sub-image file data, generating corresponding project objects, adding these project objects to the view scene, and sorting them in order. If the input control command is received, it is determined whether the project object is in the display area. If it is there, coordinate conversion and picture display are performed.
It realizes the rapid cutting of large-resolution pictures into small pieces of sub-image data, and is effectively managed through the Qt view scene framework, reducing memory usage and supporting browsing functions of large-resolution pictures such as zooming, moving, etc.
Smart Images

Figure CN115033311B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing, and particularly to a method, device and related components for realizing QT preview of large-size pictures. Background Art
[0002] Currently, previewing pictures is a common function in multimedia development projects. That is, after loading a picture, users can view the details of the picture through operations such as zooming in and out and moving in the preview window. However, when previewing pictures with a very large size, the computer memory will be occupied very much. For example, a picture with a resolution of 10000*10000 occupies about 390 mb of memory, a picture with a resolution of 15000*15000 occupies about 850 mb of memory, and a picture with a resolution of 30000*30000 occupies up to about 3500 mb of memory.
[0003] As can be seen from the above, existing large-resolution pictures will occupy a large amount of memory after being loaded and previewed. Summary of the Invention
[0004] The purpose of the present invention is to provide a method, device and related components for realizing QT preview of large-size pictures, aiming to solve the problem that existing large-resolution pictures will occupy a large amount of memory after being loaded and previewed.
[0005] To solve the above technical problems, the purpose of the present invention is achieved through the following technical solutions: providing a method for realizing QT preview of large-size pictures, which includes:
[0006] Loading picture file data into a memory object;
[0007] Performing a grid processing step on the picture file data, so that the picture file data is divided into multiple sub-picture file data, and generating corresponding item objects;
[0008] Adding all the item objects into a view scene and arranging them in order;
[0009] If a received input control instruction is received, then determine whether each item object is within the display area of the view scene. If the current item object is within the display area of the view scene, then determine the current item object as a target item object, and perform a coordinate conversion step on the target item object to obtain a corresponding screen display area, and perform picture display based on the screen display area.
[0010] In addition, the technical problem to be solved by the present invention also lies in providing a device for realizing QT preview of large-size pictures, which includes:
[0011] A loading unit for loading picture file data into a memory object;
[0012] A grid processing unit for performing a grid processing step on the picture file data, so that the picture file data is segmented into multiple sub-picture file data and corresponding project objects are generated;
[0013] A sorting unit for adding all the project objects into a view scene and arranging them in order;
[0014] A display processing unit for, if a received input control instruction is received, determining whether each project object is within the display area of the view scene. If the current project object is within the display area of the view scene, determining the current project object as a target project object, and performing a coordinate conversion step on the target project object to obtain a corresponding screen display area, and performing picture display based on the screen display area.
[0015] In addition, an embodiment of the present invention further provides a computer device, which includes a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the method for realizing QT preview of large-size pictures described in the first aspect above is implemented.
[0016] In addition, an embodiment of the present invention further provides a computer-readable storage medium, where the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor is caused to execute the method for realizing QT preview of large-size pictures described in the first aspect above.
[0017] An embodiment of the present invention discloses a method, device, and related components for realizing QT preview of large-size pictures. The method includes: loading picture file data into a memory object; performing a grid processing step on the picture file data, so that the picture file data is segmented into multiple sub-picture file data and corresponding project objects are generated; adding all the project objects into a view scene and arranging them in order; if a received input control instruction is received, determining whether each project object is within the display area of the view scene. If the current project object is within the display area of the view scene, determining the current project object as a target project object, and performing a coordinate conversion step on the target project object to obtain a corresponding screen display area, and performing picture display based on the screen display area. This method can quickly cut a large-resolution picture into small sub-picture file data, and effectively cut and manage the large-resolution picture file data into small sub-picture file data by using the view scene framework of Qt, so as to realize various functions of large-resolution picture browsing such as zooming and moving. Description of the Drawings
[0018] To more clearly illustrate the technical solutions of the embodiments of the present invention, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the drawings in the following description are some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0019] Figure 1 It is a schematic flowchart of the method for realizing QT preview of large-size pictures provided by the embodiments of the present invention;
[0020] Figure 2 It is a schematic block diagram of the device for realizing QT preview of large-size pictures provided by the embodiments of the present invention;
[0021] Figure 3 It is a schematic block diagram of the computer device provided by the embodiments of the present invention. Detailed implementation manners
[0022] The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the drawings in the embodiments of the present invention. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the scope of protection of the present invention.
[0023] It should be understood that when used in this specification and the appended claims, the terms "comprises" and "comprising" indicate the presence of the described features, wholes, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components, and / or their combinations.
[0024] It should also be understood that the terms used in this specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in this specification of the present invention and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an", and "the" are intended to include the plural forms.
[0025] It should be further understood that the term " / and / or" used in this specification of the present invention and the appended claims refers to any combination and all possible combinations of one or more of the related listed items, and includes these combinations.
[0026] It should be added that the graphics view framework provides a model-view programming method based on graphics items, which mainly consists of three parts: a scene, a view, and graphics items. These three parts are represented by the three classes QGraphicsScene, QGraphicsView, and QGraphicsItem respectively. Among them, multiple views can view a scene, and the scene contains graphics items of various geometric shapes.
[0027] Please refer to Figure 1 , Figure 1 which is a schematic flowchart of the method for implementing QT preview of large-size pictures provided by the embodiment of the present invention;
[0028] As Figure 1 shown, the method includes steps S101 to S105.
[0029] S101. Load the picture file data into a memory object;
[0030] S102. Perform a grid processing step on the picture file data, so that the picture file data is divided into multiple sub-picture file data, and generate corresponding project objects;
[0031] S103. Add all the project objects into the view scene and arrange them in order;
[0032] S104. If a control instruction is received, determine whether each project object is within the display area of the view scene. If the current project object is within the display area of the view scene, execute step S105;
[0033] S105. Determine the current project object as the target project object, and perform a coordinate conversion step on the target project object to obtain the corresponding screen display area, and enter the next step S106;
[0034] S106. Display the picture based on the screen display area.
[0035] In this embodiment, after the user selects the target picture, first load the picture file data corresponding to the target picture and save it into a memory object. Since what is loaded is picture file data rather than picture object data, the occupied memory is relatively much smaller. Then, divide the entire picture file data into grids. For example, for a picture file data with a resolution of 10000*10000, if it is divided into grids of 10*10, then 100 sub-picture file data of 1000*1000 can be obtained. Then, generate corresponding project objects based on the obtained sub-picture file data, that is, generate 100 project objects; then add these 100 project objects into the view scene and arrange the project objects in order according to their positions.
[0036] Based on the control instructions for the user to zoom in, zoom out or move the target picture, judge these 100 project objects. Specifically, judge whether each project object is within the display area of the view scene. For example, if 60 project objects are located within the display area of the view scene, then name these 60 project objects as target project objects, and then perform a coordinate conversion step for each target project object to obtain the corresponding screen display area, and finally perform picture display according to the screen display area.
[0037] It should be noted that for non-target project objects, no display rendering is performed, so no memory is consumed. That is to say, the remaining 40 project objects are non-target project objects, and when the picture is displayed, no rendering operation will be performed on this part of non-target project objects.
[0038] Generally speaking, based on the zoom size value input by the user for the target picture, the sub-picture file data included in the target project objects is scaled and processed to construct a suitable picture for display. The memory occupancy of this part is related to the size of the display area, and project objects outside the screen will not be rendered. Therefore, the maximum display memory loss of the entire 10*10 grid picture is 2 times the size of the screen.
[0039] In a specific embodiment, the step S101 includes the following steps:
[0040] S10. Use a file manager to read the binary data in the picture file data and store the binary data in a byte array object.
[0041] In this embodiment, use a file manager (QFile) to read the binary data in the picture file data and save the binary data to a byte array object (QByteArray object), and subsequent rapid scaling or moving processing can be performed on the binary data according to the control instructions input by the user.
[0042] In a specific embodiment, the "grid processing step" in the step S102 includes the following steps:
[0043] S20. Based on a preset cutting size rule, read the sub-picture file data of n*m size from the picture file data and store all the sub-picture file data in a hash table;
[0044] S21. Generate corresponding project objects under the grid coordinates corresponding to the hash table;
[0045] S22. According to the grid coordinates in the hash table, associate each piece of sub-picture file data with the corresponding project object.
[0046] In this embodiment, for pictures with different resolutions, different cutting size rules can be preset to achieve a better grid division effect for each picture. For example, for picture file data with a resolution of 10000*10000, it is divided into a 10*10 grid, and for picture file data with a resolution of 6000*4000, it can be set to be divided into a 6*4 grid. That is to say, this application does not specifically limit the values of n and m in step S20 and the size relationship between the two, and corresponding settings can be made according to the actual situation.
[0047] All the cut sub-picture file data are stored in a hash table (ImageItemGridTbl), and at the same time, corresponding project objects (ImageItem objects) are generated for the grid subscripts. For example, 10*10 small pieces of sub-picture file data are read from the picture file data, and then these 10*10 small pieces of sub-picture file data are stored in the hash table, and then 10*10 project objects are generated corresponding to the grid subscripts. It should be noted that the project objects are generated based on the cut small pieces of sub-picture file data and then cached, and can be reused again when there is new small piece of sub-picture file data next time.
[0048] After obtaining the project objects, according to the subscripts in the hash table, the 10*10 small pieces of sub-picture file data are associated with the corresponding project objects to facilitate the later rendering of photos by the project objects to call the corresponding sub-picture file data. Further, the key index of the hash table ImageItemGridTbl is established in connection with the project objects by the following formula QHash<Qpair<quint32, quint32>, ImageItem*>.
[0049] In a specific embodiment, the step S20 includes the following steps:
[0050] S201. Use setScaledSize in the QImageReader class to read n*m sized sub-picture file data from the picture file data.
[0051] In this embodiment, the setScaledSize function in the QImageReader class is used to read sub-picture file data from the picture file data.
[0052] In a specific embodiment, the step "if a received input control instruction is received, then determine whether each project object is within the display area of the view scene" in step S104 includes the following steps:
[0053] S30. Convert the graphic coordinates of each of the project objects in the graphic coordinate system into view coordinates in the view coordinate system;
[0054] S31. Determine whether the view coordinates of each of the said item objects are within the display area of the said view scene.
[0055] In this embodiment, the view scene framework has three coordinate systems. One is the view coordinate system, which is the window that can be seen; one is the scene coordinate system, which is the content displayed in the window; and the last one is the coordinate system of the graphic item (Item). Each item object ImageItem is an Item. Therefore, in this application, after converting the graphic coordinates of each item object ImageItem in the graphic coordinate system into view coordinates, it can be determined whether the item object is within the display area of the view scene.
[0056] If the item object is not within the display area of the view scene, this part of the item objects will not be rendered, so no memory will be consumed.
[0057] In a specific embodiment, the "coordinate conversion step" in the said step S104 includes the following steps:
[0058] S40. Convert the view coordinates of each of the said target item objects in the view coordinate system into scene coordinates in the scene coordinate system to obtain the corresponding screen display area.
[0059] In this embodiment, if the item object, i.e., the target item object, is within the display area of the view scene, then convert the view coordinates of each target item object in the view coordinate system into scene coordinates in the scene coordinate system to obtain the screen display area of the target item object.
[0060] In a specific embodiment, the said step S106 includes the following steps:
[0061] S50. Obtain the number of sub-picture file data associated with the said target item object according to the said screen display area;
[0062] S51. Perform corresponding operations on the said sub-picture file data based on the input control instruction.
[0063] In this embodiment, according to the size of the screen display area obtained for the target item object, read the picture tile data (sub-picture file data) associated with the target item object for fast zoom conversion or movement. That is to say, in this way, the memory occupied by the generated picture object is related to the size of the display area. Therefore, it can be seen that when performing zoom display, the entire rendering process generates at most picture objects twice the size of the screen resolution. It should be noted that because this application uses the cache of the hash table, at most picture objects twice the size of the screen resolution are generated.
[0064] The method of the present application can quickly cut a large - resolution picture into small sub - picture file data, and effectively cut the large - resolution picture file data into small sub - picture file data and manage it by using the view - scene framework of Qt, so as to realize various functions of large - resolution picture browsing such as zooming and moving.
[0065] An embodiment of the present invention also provides a device for realizing QT preview of large - size pictures. The device for realizing QT preview of large - size pictures is used to execute any embodiment of the foregoing method for realizing QT preview of large - size pictures. Specifically, please refer to Figure 2 , Figure 2 which is a schematic block diagram of the device for realizing QT preview of large - size pictures provided by an embodiment of the present invention.
[0066] As Figure 2 shown, the device 600 for realizing QT preview of large - size pictures includes:
[0067] A loading unit 601, configured to load picture file data into a memory object;
[0068] A grid processing unit 602, configured to perform grid processing steps on the picture file data, so that the picture file data is segmented into multiple sub - picture file data, and generate corresponding project objects;
[0069] A sorting unit 603, configured to add all the project objects into a view scene and arrange them in order;
[0070] A display processing unit 604, configured to, if a received input control instruction is received, determine whether each project object is within the display area of the view scene. If the current project object is within the display area of the view scene, determine that the current project object is a target project object, and perform a coordinate conversion step on the target project object to obtain a corresponding screen display area, and perform picture display based on the screen display area.
[0071] This device can quickly cut a large - resolution picture into small sub - picture file data, and effectively cut the large - resolution picture file data into small sub - picture file data and manage it by using the view - scene framework of Qt, so as to realize various functions of large - resolution picture browsing such as zooming and moving.
[0072] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, the specific working processes of the above - described device and units can refer to the corresponding processes in the foregoing method embodiments, and will not be elaborated herein.
[0073] The above - described device for realizing QT preview of large - size pictures can be implemented in the form of a computer program, and this computer program can be in Figure 3running on the computer device shown.
[0074] Please refer to Figure 3 , Figure 3 which is a schematic block diagram of the computer device provided by an embodiment of the present invention. The computer device 1100 is a server, and the server can be an independent server or a server cluster composed of multiple servers.
[0075] Refer to Figure 3 wherein, the computer device 1100 includes a processor 1102, a memory, and a network interface 1105 connected through a system bus 1101. Among them, the memory may include a non-volatile storage medium 1103 and an internal memory 1104.
[0076] The non-volatile storage medium 1103 can store an operating system 11031 and a computer program 11032. When the computer program 11032 is executed, it can cause the processor 1102 to execute a method for realizing QT preview of large-size pictures.
[0077] The processor 1102 is used to provide computing and control capabilities to support the operation of the entire computer device 1100.
[0078] The internal memory 1104 provides an environment for the operation of the computer program 11032 in the non-volatile storage medium 1103. When the computer program 11032 is executed by the processor 1102, it can cause the processor 1102 to execute a method for realizing QT preview of large-size pictures.
[0079] The network interface 1105 is used for network communication, such as providing the transmission of data information, etc. Those skilled in the art can understand that Figure 3 the structure shown in [[ ]] is only a block diagram of some structures related to the solution of the present invention, and does not constitute a limitation on the computer device 1100 to which the solution of the present invention is applied. The specific computer device 1100 may include more or fewer components than those shown in the figure, or combine some components, or have different component arrangements.
[0080] Those skilled in the art can understand that Figure 3 the embodiment of the computer device shown in [[ ]] does not constitute a limitation on the specific composition of the computer device. In other embodiments, the computer device may include more or fewer components than those shown in the figure, or combine some components, or have different component arrangements. For example, in some embodiments, the computer device may only include a memory and a processor. In such an embodiment, the structures and functions of the memory and the processor are the same as those in Figure 3 the embodiment shown, and will not be elaborated here.
[0081] It should be understood that in the embodiments of the present invention, the processor 1102 may be a central processing unit (CPU), and the processor 1102 may also be other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0082] In another embodiment of the present invention, a computer-readable storage medium is provided. The computer-readable storage medium may be a non-volatile computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, it implements the method for realizing QT preview of large-size pictures in the embodiments of the present invention.
[0083] The storage medium is a physical, non-transitory storage medium, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a magnetic disk or an optical disc, etc., which are various physical storage media that can store program codes.
[0084] Those skilled in the art can clearly understand that for the convenience and conciseness of description, the specific working processes of the above-described devices, apparatuses, and units can refer to the corresponding processes in the foregoing method embodiments, and will not be described herein again.
[0085] As described above, the above are only specific embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of various equivalent modifications or substitutions within the technical scope disclosed by the present invention, and these modifications or substitutions should all be covered by the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.
Claims
1. A method for realizing QT preview of large-size pictures, characterized in that, it includes: Loading the picture file data into a memory object; Performing a grid processing step on the picture file data, so that the picture file data is divided into multiple sub-picture file data, and generating corresponding project objects; Adding all the project objects into the view scene and arranging them in order; If a received input control instruction is received, determine whether each project object is within the display area of the view scene. If the current project object is within the display area of the view scene, determine that the current project object is the target project object, and perform a coordinate conversion step on the target project object to obtain a corresponding screen display area, and perform picture display based on the screen display area; The grid processing step includes: Based on a preset cutting size rule, reading sub-picture file data of n*m size from the picture file data, and storing all the sub-picture file data into a hash table; Generating corresponding project objects under the grid coordinates corresponding to the hash table; According to the grid coordinates in the hash table, associating each sub-picture file data with the corresponding project object; The associating each sub-picture file data with the corresponding project object according to the grid coordinates in the hash table specifically means that after obtaining the project object, associating the sub-picture file data with the corresponding project object according to the subscript in the hash table; The associating the sub-picture file data with the corresponding project object according to the subscript in the hash table after obtaining the project object specifically means establishing a connection between the key index of the hash table ImageItemGridTbl and the project object using the following formulas QHash<Qpair<quint32, quint32>, ImageItem*>.
2. The method for realizing QT preview of large-size pictures according to claim 1, characterized in that, The step of if a received input control instruction is received, determining whether each project object is within the display area of the view scene includes: Converting the graphic coordinates of each project object in the graphic coordinate system into view coordinates in the view coordinate system respectively; Judging whether the view coordinates of each project object are within the display area of the view scene.
3. The method for realizing QT preview of large-size pictures according to claim 2, characterized in that, The coordinate conversion step includes: Converting the view coordinates of each target project object in the view coordinate system into scene coordinates in the scene coordinate system to obtain a corresponding screen display area.
4. The method for realizing QT preview of large-size pictures according to claim 3, characterized in that, The performing picture display based on the screen display area includes: Obtaining the sub-picture file data associated with the target project object according to the screen display area; Performing corresponding operations on the sub-picture file data based on the input control instruction.
5. The method for realizing QT preview of large-size pictures according to claim 1, characterized in that, The loading the picture file data into a memory object includes: Read the binary data in the picture file data using a file manager, and store the binary data into a byte array object.
6. The method for implementing QT preview of large-size pictures according to claim 1, characterized in that, the reading of the sub-picture file data of n*m size from the picture file data includes: using setScaledSize in the QImageReader class to read the sub-picture file data of n*m size from the picture file data.
7. An apparatus for implementing QT preview of large-size pictures, characterized in that, it includes: a loading unit for loading picture file data into a memory object; a grid processing unit for performing grid processing steps on the picture file data, so that the picture file data is divided into multiple sub-picture file data, and generating corresponding project objects; a sorting unit for adding all the project objects into a view scene and arranging them in order; a display processing unit for, if receiving an input control instruction, determining whether each project object is within the display area of the view scene, if the current project object is within the display area of the view scene, determining the current project object as a target project object, and performing a coordinate conversion step on the target project object to obtain a corresponding screen display area, and performing picture display based on the screen display area; wherein, the grid processing steps include: reading the sub-picture file data of n*m size from the picture file data based on a preset cutting size rule, and storing all the sub-picture file data into a hash table; generating corresponding project objects under the grid coordinates corresponding to the hash table; associating each sub-picture file data with the corresponding project object according to the grid coordinates in the hash table; the associating each sub-picture file data with the corresponding project object according to the grid coordinates in the hash table is specifically, after obtaining a project object, associating the sub-picture file data with the corresponding project object according to the subscript in the hash table; the associating the sub-picture file data with the corresponding project object according to the subscript in the hash table after obtaining a project object is specifically establishing a connection between the key index of the hash table ImageItemGridTbl and the project object using the following formulas QHash<Qpair<quint32, quint32>, ImageItem*>.
8. A computer device, including a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, when the processor executes the computer program, it implements the method for implementing QT preview of large-size pictures according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, it causes the processor to execute the method for implementing QT preview of large-size pictures according to any one of claims 1 to 6.
Citation Information
Patent Citations
Picture loading method, device and system, electronic equipment and readable storage medium
CN112000908A