Image conversion method and device and electronic equipment

文档序号:1287554 发布日期:2020-08-28 浏览:6次 中文

阅读说明:本技术 一种图像转换方法、装置及电子设备 (Image conversion method and device and electronic equipment ) 是由 邓斌 于 2019-02-20 设计创作,主要内容包括:本发明实施例提供了一种图像转换方法、装置及电子设备,包括,当接收到针对PDF文档的图像转换的触发操作时,获取PDF文档中原始图像各个像素点的像素值,并且判断原始图像中各像素点的像素值是否小于预设阈值,以及将小于预设阈值的像素值变更为第一预设像素值,第一预设像素值占据的数据量为1比特,以及将不小于预设阈值的像素值变更为第二预设像素值,第二预设像素值占据的数据量为1比特,第二预设像素值和第一预设像素值不同,通过将原始图像中占据1个字节或者多个字节的像素值转换为只占据数据量为1比特的第一预设像素值或第二预设像素值,减少了PDF文档中图像的大小,从而减少了PDF文档的大小。(The embodiment of the invention provides an image conversion method, an image conversion device and electronic equipment, wherein when a trigger operation aiming at the image conversion of a PDF document is received, the pixel values of all pixel points of an original image in the PDF document are obtained, whether the pixel values of all the pixel points in the original image are smaller than a preset threshold value or not is judged, the pixel values smaller than the preset threshold value are changed into first preset pixel values, the data quantity occupied by the first preset pixel values is 1bit, the pixel values not smaller than the preset threshold value are changed into second preset pixel values, the data quantity occupied by the second preset pixel values is 1bit, the second preset pixel values are different from the first preset pixel values, the size of the image in the PDF document is reduced by converting the pixel values occupying 1 byte or more bytes in the original image into the first preset pixel values or the second preset pixel values only occupying 1bit, thereby reducing the size of the PDF document.)

1. An image conversion method, comprising:

when a trigger operation aiming at the image conversion of a PDF document is received, acquiring the pixel value of each pixel point of an original image in the PDF document;

judging whether the pixel value of each pixel point in the original image is smaller than a preset threshold value or not;

changing the pixel value smaller than the preset threshold value into a first preset pixel value, wherein the data volume occupied by the first preset pixel value is 1 bit;

and changing the pixel value not less than the preset threshold value into a second preset pixel value, wherein the second preset pixel value occupies 1bit of data, and the second preset pixel value is different from the first preset pixel value.

2. The method of claim 1, wherein the original image is an RGB image, and the pixel values are RGB values;

the judging whether the pixel value of each pixel point in the original image is smaller than a preset threshold value includes:

respectively judging whether the R value, the G value and the B value of each pixel point in the original image are smaller than the preset threshold value;

the changing the pixel value smaller than the preset threshold value into a first preset pixel value includes:

changing the pixel value of the pixel point of which the R value, the G value and the B value are all smaller than the preset threshold value into a first preset pixel value;

the changing the pixel value not less than the preset threshold value into a second preset pixel value includes:

and changing the pixel value of the pixel point of which the R value, the G value or the B value is not less than the preset threshold value into a second preset pixel value.

3. The method of claim 1, wherein the original image is a grayscale image and the pixel values are grayscale values.

4. The method according to claim 1, wherein when receiving a trigger operation for image conversion of a PDF document, acquiring pixel values of respective pixel points of an original image in the PDF document comprises:

when a trigger operation aiming at the image conversion of the PDF document is received, popping up an information prompt box, wherein the information prompt box is used for prompting whether the image conversion is determined or not;

and when receiving an operation of determining image conversion, acquiring pixel values of all pixel points of the original image in the PDF document.

5. An image conversion apparatus characterized by comprising:

the device comprises a pixel value acquisition module, a pixel value acquisition module and a pixel value acquisition module, wherein the pixel value acquisition module is used for acquiring the pixel value of each pixel point of an original image in a PDF document when receiving a trigger operation aiming at image conversion of the PDF document;

the judging module is used for judging whether the pixel value of each pixel point in the original image is smaller than a preset threshold value or not;

a first pixel value changing module, configured to change a pixel value smaller than the preset threshold to a first preset pixel value, where a data amount occupied by the first preset pixel value is 1 bit;

and the second pixel value changing module is used for changing the pixel value not less than the preset threshold value into a second preset pixel value, the data volume occupied by the second preset pixel value is 1bit, and the second preset pixel value is different from the first preset pixel value.

6. The apparatus of claim 5, wherein the original image is an RGB image, and the pixel values are RGB values;

the judging module is specifically configured to respectively judge whether an R value, a G value, and a B value of each pixel point in the original image are smaller than the preset threshold;

the first pixel value changing module is specifically configured to change the pixel value of the pixel point of which the R value, the G value, and the B value are all smaller than the preset threshold value to a first preset pixel value;

the second pixel value changing module is specifically configured to change the pixel value of the pixel point whose R value, G value, or B value is not less than the preset threshold value to a second preset pixel value.

7. The apparatus of claim 5, wherein the original image is a grayscale image and the pixel values are grayscale values.

8. The apparatus according to claim 5, wherein the pixel value obtaining module is specifically configured to pop up an information prompt box when receiving a trigger operation for image conversion of a PDF document, where the information prompt box is used to prompt whether to determine to perform image conversion, and when receiving an operation to determine to perform image conversion, obtain pixel values of respective pixel points of an original image in the PDF document.

9. An electronic device is characterized by comprising a processor, a communication interface, a memory and a communication bus, wherein the processor and the communication interface are used for realizing mutual communication by the memory through the communication bus;

a memory for storing a computer program;

a processor for implementing the method steps of any of claims 1 to 4 when executing a program stored in the memory.

10. A computer-readable storage medium, characterized in that a computer program is stored in the computer-readable storage medium, which computer program, when being executed by a processor, carries out the method steps of any one of claims 1 to 4.

Technical Field

The present invention relates to the field of PDF processing technologies, and in particular, to an image conversion method, an image conversion device, and an electronic device.

Background

The abbreviation of pdf (portable Document format) means "portable Document format", which is an electronic file format. This file format is operating system platform independent, i.e., PDF files are common to both Windows, Unix, and Mac OS operating systems. This feature makes it an ideal document format for electronic document distribution and digital information dissemination over the Internet. More and more electronic books, product descriptions, company literature, web materials, and electronic mail are beginning to use PDF formatted files.

The size of a PDF document determines the cost that the PDF document needs to consume in the internet transmission process, the larger the PDF document, the higher the cost that needs to consume, and the size of the PDF document often depends on the size of an image included in the PDF document, and when the image included in the PDF document is too large, which causes the PDF document to be too large, the prior art does not provide a corresponding solution for reducing the size of the PDF document.

Disclosure of Invention

An object of an embodiment of the present invention is to provide an image conversion method to reduce the size of an image in a PDF document. The specific technical scheme is as follows:

the embodiment of the invention provides an image conversion method, which comprises the following steps:

when a trigger operation aiming at the image conversion of a PDF document is received, acquiring the pixel value of each pixel point of an original image in the PDF document;

judging whether the pixel value of each pixel point in the original image is smaller than a preset threshold value or not;

changing the pixel value smaller than the preset threshold value into a first preset pixel value, wherein the data volume occupied by the first preset pixel value is 1 bit;

and changing the pixel value not less than the preset threshold value into a second preset pixel value, wherein the second preset pixel value occupies 1bit of data, and the second preset pixel value is different from the first preset pixel value.

Further, the original image is an RGB image, and the pixel values are RGB values;

the judging whether the pixel value of each pixel point in the original image is smaller than a preset threshold value includes:

respectively judging whether the R value, the G value and the B value of each pixel point in the original image are smaller than the preset threshold value;

the changing the pixel value smaller than the preset threshold value into a first preset pixel value includes:

changing the pixel value of the pixel point of which the R value, the G value and the B value are all smaller than the preset threshold value into a first preset pixel value;

the changing the pixel value not less than the preset threshold value into a second preset pixel value includes:

and changing the pixel value of the pixel point of which the R value, the G value or the B value is more than or equal to the preset threshold value into a second preset pixel value.

Further, the original image is a gray image, and the pixel values are gray values.

Further, when receiving a trigger operation for image conversion of a PDF document, acquiring a pixel value of each pixel point of an original image in the PDF document includes:

when a trigger operation aiming at the image conversion of the PDF document is received, popping up an information prompt box, wherein the information prompt box is used for prompting whether the image conversion is determined or not;

and when receiving an operation of determining image conversion, acquiring pixel values of all pixel points of the original image in the PDF document.

An embodiment of the present invention further provides an image conversion apparatus, including:

the device comprises a pixel value acquisition module, a pixel value acquisition module and a pixel value acquisition module, wherein the pixel value acquisition module is used for acquiring the pixel value of each pixel point of an original image in a PDF document when receiving a trigger operation aiming at image conversion of the PDF document;

the judging module is used for judging whether the pixel value of each pixel point in the original image is smaller than a preset threshold value or not;

the pixel value changing module is used for changing the pixel value smaller than the preset threshold value into a first preset pixel value, and the data volume occupied by the first preset pixel value is 1 bit; and changing the pixel value not less than the preset threshold value into a second preset pixel value, wherein the second preset pixel value occupies a data volume of 1bit, and the second preset pixel value is different from the first preset pixel value.

Further, the original image is an RGB image, and the pixel values are RGB values;

the judging module is specifically configured to respectively judge whether an R value, a G value, and a B value of each pixel point in the original image are smaller than the preset threshold;

the pixel value changing module is specifically configured to change the pixel value of a pixel point of which the R value, the G value, and the B value are all smaller than the preset threshold value to a first preset pixel value; and changing the pixel value of the pixel point of which the R value, the G value or the B value is more than or equal to the preset threshold value into a second preset pixel value.

Further, the original image is a gray image, and the pixel values are gray values.

Further, the pixel value obtaining module is specifically configured to pop up an information prompt box when a trigger operation for image conversion of a PDF document is received, where the information prompt box is used to prompt whether to determine to perform image conversion, and when an operation for determining to perform image conversion is received, obtain a pixel value of each pixel point of an original image in the PDF document.

The embodiment of the invention also provides electronic equipment which comprises a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory are communicated with each other through the communication bus;

a memory for storing a computer program;

and the processor is used for realizing the steps of any image conversion method when executing the program stored in the memory.

The present invention also provides a computer-readable storage medium, in which a computer program is stored, and the computer program, when executed by a processor, implements the steps of any one of the image conversion methods described above.

Embodiments of the present invention also provide a computer program product containing instructions, which when run on a computer, cause the computer to perform any one of the image conversion methods described above.

In the scheme of the image conversion method, the apparatus and the electronic device provided by the embodiment of the invention, when a trigger operation for image conversion of a PDF document is received, pixel values of pixel points of an original image in the PDF document are obtained, whether the pixel values of the pixel points in the original image are smaller than a preset threshold value or not is judged, the pixel values smaller than the preset threshold value are changed into first preset pixel values, the data volume occupied by the first preset pixel values is 1bit, the pixel values not smaller than the preset threshold value are changed into second preset pixel values, the data volume occupied by the second preset pixel values is 1bit, the second preset pixel values are different from the first preset pixel values, the size of the image in the PDF document is reduced by converting the pixel values occupying 1 byte or more in the original image into the first preset pixel values or the second preset pixel values only occupying 1bit, thereby reducing the size of the PDF document.

Of course, not all of the advantages described above need to be achieved at the same time in the practice of any one product or method of the invention.

Drawings

In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below.

Fig. 1 is a flowchart of an image conversion method according to an embodiment of the present invention;

fig. 2 is a schematic structural diagram of an image conversion apparatus according to an embodiment of the present invention;

fig. 3 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.

Detailed Description

In order to provide an implementation scheme for reducing the size of a PDF document by reducing the size of an image in the PDF document, embodiments of the present invention provide an image conversion method, an image conversion device, and an electronic device, and the following describes embodiments of the present invention with reference to the drawings in the specification. And the embodiments and features of the embodiments in the present application may be combined with each other without conflict.

The technical solution in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention.

In one embodiment of the present invention, there is provided an image conversion method, as shown in fig. 1, including the steps of:

s101: when a trigger operation aiming at the image conversion of the PDF document is received, the pixel value of each pixel point of an original image in the PDF document is obtained.

In this step, the triggering operation for the image conversion of the PDF document may be any preset operation that is associated with the image conversion, for example, for the mobile device, the triggering operation may be an action of pressing the mobile device by a finger or other parts of the user, a specific action type may be preset, and may be a short press with a pressing time less than a certain duration, a long press with a pressing time greater than a certain duration, or a multiple press within a preset duration, such as a double-click, any one of the actions or other operations that can perform human-computer interaction may be used as the triggering operation in the embodiment of the present invention, which is not specifically limited herein.

In an embodiment of the present invention, when a trigger operation for image conversion of a PDF document is received, an information prompt box may be selected to pop up, where the purpose of popping up the information prompt box is to prompt a user whether to determine that an image in the PDF document needs to be converted, the prompting manner may be described by a segment of text, the described content may be a simplified principle of image conversion, or may be a matter that needs to be noticed by an image conversion method or an influence that may be brought about by the image conversion method, the prompting manner may also be to display the prompt content in the information prompt box in a manner of combining pictures, pictures and text, or displaying other information, such as animation, etc., and the user may avoid an erroneous operation by popping up the information prompt box, or the user may not know about the matter that needs to be noticed by image conversion using the scheme provided by the embodiment of the present invention or the influence that may be brought about, an image conversion operation is performed.

When the user knows the content of the information prompt box, and determines that the image conversion operation is still needed, the operation of obtaining the pixel value of each pixel in the original image to be subjected to image conversion in the PDF document can be performed, because the image in the PDF document may be an RGB image with rich colors, wherein each pixel in the RGB image consists of R, G, B three primary color components, each primary color component occupies 1 byte, represents a value range of 0-255, and totally 256, the required color is displayed through different collocation of R, G, B three primary color components, of course, besides the above three primary colors, the RGB image may also include a transparency component occupying 1 byte, each pixel displays the required color through combination of RGB three primary colors plus the transparency component, when the original image is an RGB image, the obtained pixel value may be the value of the RGB three primary color components of each pixel in the RGB image, can be written as R, G and B values, and of course, when a transparency component is present, a value of transparency can also be included.

In an embodiment, the original image may also be a gray image, where each pixel point in the gray image is represented by gray, and occupies 1 byte, and the obtained pixel value may be a gray value.

S102: and judging whether the pixel value of each pixel point in the original image is smaller than a preset threshold value or not.

In this step, the preset threshold is any value between 0 and 255, for example, may be 1, and the pixel value obtained in step S101 is compared with the preset threshold to determine whether the pixel value of each pixel point in the original image is smaller than the preset threshold.

In an embodiment, the original image is an RGB image, the acquired R value, G value, and B value may be compared with a preset threshold respectively, and of course, the R value, G value, and B value may also be calculated by a certain algorithm to obtain a comprehensive colorimetric value, and the obtained comprehensive colorimetric value is compared with the preset threshold, at this time, a value range of the preset threshold may be any value including the possible existence of the comprehensive colorimetric value, and in this embodiment, a transparency component may also be added.

In one embodiment, the original image is a gray image, and the obtained gray value may be compared with a preset threshold to determine whether the gray value of each pixel point is smaller than the preset threshold.

S103: and changing the pixel value smaller than the preset threshold value into a first preset pixel value, wherein the data volume occupied by the first preset pixel value is 1 bit.

In this step, the first preset pixel value may be "0" or "1", and the occupied number thereof is 1bit, and in one embodiment, the display color corresponding to the first preset pixel value may be preset, for example, white, black, red, green, and blue, or a color corresponding to any one of 256 gray values.

In an embodiment, the original image is an RGB image, and when the R value, the G value, and the B value of a pixel point in the RGB image are all smaller than the preset threshold, the R value, the G value, and the B value of the pixel point in the RGB image may be changed to a first preset pixel value that only occupies 1bit, and correspondingly, the color displayed by the pixel point may be a color corresponding to the first preset pixel value.

In one embodiment, the original image is a gray image, and similarly, when the gray value is smaller than the preset threshold, the pixel value corresponding to the pixel point is changed to the first preset pixel value.

S104: and changing the pixel value not less than the preset threshold value into a second preset pixel value, wherein the data volume occupied by the second preset pixel value is 1bit, and the second preset pixel value is different from the first preset pixel value.

In this step, the second preset pixel value may be "0" or "1", the occupied number of the second preset pixel value is 1bit, it should be noted that the second preset pixel value is different from the first preset pixel value, when the first preset pixel value is "0", the second preset pixel value is "1", and vice versa, in one embodiment, the display color corresponding to the second preset pixel value may be preset, for example, white, black, one of red, green and blue, or a gray value corresponding to any one of 256 gray values, and when the first preset pixel value is different from the second preset pixel value, the corresponding display color should be different.

In an embodiment, the original image is an RGB image, and when any one of the R value, the G value, and the B value of a pixel in the RGB image is not less than the preset threshold, the R value, the G value, and the B value of the pixel in the RGB image may be changed to a second preset pixel value that only occupies 1bit, and correspondingly, the color displayed by the pixel may be a color corresponding to the second preset pixel value.

In one embodiment, the original image is a gray image, and similarly, when the gray value is not less than the preset threshold, the pixel value corresponding to the pixel point is changed to a second preset pixel value.

In the image conversion method provided by the embodiment of the present invention, when a trigger operation for image conversion of a PDF document is received, a pixel value of each pixel point of an original image in the PDF document is obtained, and it is determined whether the pixel value of each pixel point in the original image is smaller than a preset threshold, and the pixel value smaller than the preset threshold is changed to a first preset pixel value, where a data amount occupied by the first preset pixel value is 1bit, and the pixel value not smaller than the preset threshold is changed to a second preset pixel value, where the data amount occupied by the second preset pixel value is 1bit, and the second preset pixel value is different from the first preset pixel value, and the size of the image in the PDF document is reduced by converting the pixel value occupying 1 byte or more in the original image into the first preset pixel value or the second preset pixel value occupying only 1bit of data amount, thereby reducing the size of the PDF document.

Based on the same inventive concept, according to an image conversion method provided in an embodiment of the present invention, an embodiment of the present invention further provides an image conversion apparatus, as shown in fig. 2, the apparatus includes:

a pixel value obtaining module 201, configured to obtain a pixel value of each pixel point of an original image in a PDF document when a trigger operation for image conversion of the PDF document is received;

the judging module 202 is configured to judge whether a pixel value of each pixel point in the original image is smaller than a preset threshold;

a first pixel value changing module 203, configured to change a pixel value smaller than a preset threshold to a first preset pixel value, where a data amount occupied by the first preset pixel value is 1 bit;

the second pixel value changing module 204 is configured to change a pixel value not smaller than the preset threshold to a second preset pixel value, where the data amount occupied by the second preset pixel value is 1bit, and the second preset pixel value is different from the first preset pixel value.

Further, the original image is an RGB image, and the pixel value is an RGB value;

the determining module 202 is specifically configured to determine whether R, G, and B values of each pixel point in the original image are smaller than a preset threshold respectively;

a first pixel value changing module 203, configured to change the pixel value of the pixel point whose R value, G value, and B value are less than the preset threshold to a first preset pixel value;

the second pixel value changing module 204 is specifically configured to change the pixel value of the pixel point whose R value, G value, or B value is not less than the preset threshold value to a second preset pixel value.

Further, the original image is a gray image, and the pixel values are gray values.

Further, the pixel value obtaining module 201 is specifically configured to pop up an information prompt box when receiving a trigger operation for image conversion of the PDF document, where the information prompt box is used to prompt whether to determine to perform image conversion, and when receiving an operation to determine to perform image conversion, obtain a pixel value of each pixel point of an original image in the PDF document.

The embodiment of the present invention further provides an electronic device, as shown in fig. 3, which includes a processor 301, a communication interface 302, a memory 303, and a communication bus 304, where the processor 301, the communication interface 302, and the memory 303 complete mutual communication through the communication bus 304,

a memory 303 for storing a computer program;

the processor 301, when executing the program stored in the memory 303, implements the following steps:

when a trigger operation aiming at the image conversion of the PDF document is received, acquiring the pixel value of each pixel point of an original image in the PDF document;

judging whether the pixel value of each pixel point in the original image is smaller than a preset threshold value or not;

changing the pixel value smaller than the preset threshold value into a first preset pixel value, wherein the data volume occupied by the first preset pixel value is 1 bit;

and changing the pixel value not less than the preset threshold value into a second preset pixel value, wherein the data volume occupied by the second preset pixel value is 1bit, and the second preset pixel value is different from the first preset pixel value.

The communication bus mentioned in the electronic device may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown, but this does not mean that there is only one bus or one type of bus.

The communication interface is used for communication between the electronic equipment and other equipment.

The Memory may include a Random Access Memory (RAM) or a Non-Volatile Memory (NVM), such as at least one disk Memory. Optionally, the memory may also be at least one memory device located remotely from the processor.

The Processor may be a general-purpose Processor, including a Central Processing Unit (CPU), a Network Processor (NP), and the like; but may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic device, discrete hardware component.

In yet another embodiment provided by the present invention, a computer-readable storage medium is further provided, in which a computer program is stored, and the computer program realizes the steps of any one of the image conversion methods described above when being executed by a processor.

In yet another embodiment provided by the present invention, there is also provided a computer program product containing instructions which, when run on a computer, cause the computer to perform any one of the image conversion methods in the above embodiments.

In the above embodiments, the implementation may be wholly or partially realized by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, cause the processes or functions described in accordance with the embodiments of the invention to occur, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer instructions may be stored in a computer readable storage medium or transmitted from one computer readable storage medium to another, for example, from one website site, computer, server, or data center to another website site, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device, such as a server, a data center, etc., that incorporates one or more of the available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., Solid State Disk (SSD)), among others.

It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.

All the embodiments in the present specification are described in a related manner, and the same and similar parts among the embodiments may be referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, as for the apparatus, the electronic device, the computer-readable storage medium, and the computer program product, since they are substantially similar to the method embodiments, the description is simple, and the relevant points can be referred to the partial description of the method embodiments.

The above description is only for the preferred embodiment of the present invention, and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention shall fall within the protection scope of the present invention.

12页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:基于HTML的信息智能提取技术的方法

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!