The method and system that a kind of picture compression uploads
Technical field
The present invention relates to mobile law enforcement scene exhibit uploading file field, more particularly to a kind of method that picture compression uploads
And system.
Background technology
The exhibit transferred during in order to ensure to handle a case is consistent with the exhibit collected during on-site law-enforcing, and raising was enforced the law
The degrees of overtness and transparency of journey, typically require that on-site law-enforcing personnel directly take pictures the exhibit obtained at the scene, then by photo
Central server is reached, in case checking.
At present, on-site law-enforcing personnel typically use mobile phone photograph, and photo is preserved to local, when network stabilization, then
Central server is uploaded to after photo is compressed.
But because requirement of the picture transfer to network transfer speeds is higher, so, when live exhibit picture is more, i.e.,
Compressed picture, obtained compressed file or bigger, then in picture upload procedure, it may appear that uploading speed
Slowly, time-consuming, in addition interrupt, situation about can not upload so that mobile law enforcement scene exhibit picture can not smoothly on
Pass, influence being smoothed out for enforcing law.
The content of the invention
It is an object of the invention to provide the method and system that a kind of picture compression uploads, so as to solve to deposit in the prior art
Foregoing problems.
To achieve these goals, the technical solution adopted by the present invention is as follows:
A kind of method that picture compression uploads, comprises the following steps:
S1, obtain single picture to be uploaded;
S2, the picture is write in file in the form of byte stream, form stream file;
S3, judge the size of the stream file, if the size of the stream file reaches threshold value, the stream file is entered
Line flag simultaneously uploads, while performs S4;If the size of the stream file is not up to threshold value, the stream file is carried out
Pass, while perform S6;
S4, circulation perform S2-S3, until traveling through the picture, obtain multiple stream files of the picture, and will be described more
Individual stream file is marked and uploaded;
S5, server merge the multiple stream file according to the mark, generate the complete stream of the picture
File;
S6, repeat S1-S5, all pictures to be uploaded of searching loop.
Preferably, using the processing mode of multithreading.
Preferably, S2 uses quality compression method and picture at least one of size compression method in proportion.
Specifically, the picture in proportion size compression method include according to path obtain picture and compression method and according to
Bitmap picture compression methods.
Preferably, in S2, the size of the byte stream is 3072-4096 bytes.
It is highly preferred that in S2, the size of the byte stream is 4096 bytes.
Preferably, in S3, the threshold value is 512-2048kb.
It is highly preferred that in S2, the threshold value is 2048kb.
Further, after S6, in addition to step, the compressed file of the picture is decompressed, obtains original picture.
The system that a kind of picture compression uploads, including
Client and background server,
The client includes image generating module, picture compression module and stream file uploading module;
The background server includes stream file receiving module and stream file merging module;
The image generating module is used to obtain picture waiting for transmission;
The picture compression module is used in the form of byte stream write the picture in file, forms the picture
Stream file;
The stream file uploading module is used to the stream file is marked and uploaded;
The stream file receiving module is used to receive the stream file;
The stream file merging module is used to merge all stream files according to the mark, described in generation
The compressed file of picture.
The beneficial effects of the invention are as follows:The present invention carries out sectional compression by on-site law-enforcing mobile terminal to single picture, point
Duan Shangchuan, background server subsection receiing, the mode remerged, realize that the compression of picture uploads, due to the file of sectional compression
Small, so uploading speed is fast, the flow of consumption is low, and the requirement to network will not be influenceed than relatively low by network stabilization,
It can realize and smoothly transmit, so as to ensure that being smoothed out for enforcing law.
Brief description of the drawings
Fig. 1 is the method flow schematic diagram that picture compression provided in an embodiment of the present invention uploads;
Fig. 2 is the system structure diagram that picture compression provided in an embodiment of the present invention uploads.
Embodiment
In order to make the purpose , technical scheme and advantage of the present invention be clearer, below in conjunction with accompanying drawing, the present invention is entered
Row is further described.It should be appreciated that embodiment described herein is not used to only to explain the present invention
Limit the present invention.
Embodiment one
As shown in figure 1, the embodiments of the invention provide a kind of method that picture compression uploads, comprise the following steps:
S1, obtain single picture to be uploaded;
S2, the picture is write in file in the form of byte stream, form stream file;
S3, judge the size of the stream file, if the size of the stream file reaches threshold value, the stream file is entered
Line flag simultaneously uploads, while performs S4;If the size of the stream file is not up to threshold value, the stream file is carried out
Pass, while perform S6;
S4, circulation perform S2-S3, until traveling through the picture, obtain multiple stream files of the picture, and will be described more
Individual stream file is marked and uploaded;
S5, server merge the multiple stream file according to the mark, generate the complete stream of the picture
File;
S6, repeat S1-S5, all pictures to be uploaded of searching loop.
In practical implementation, on-site law-enforcing personnel can be clapped the material evidence of acquirement or other data by mobile phone
According to, or the picture for obtaining and needing to upload directly is browsed, and preserve to local, generate file to be uploaded.
In order to improve compression speed and uploading rate, ensure also can smoothly complete text in the case where network is not sufficiently stable
The transmission of part, and transmission rate can be improved, reduce and transmit flow used, in the embodiment of the present invention, single picture is carried out
Sectional compression, after the threshold size for reaching setting, the compressed file is marked and uploaded, if first compression, will
Whole picture compression is completed, then while uploading, continues that picture is continued to compress, travel through whole picture, circulate aforesaid operations,
, will compression and upload procedure so as to the file by a picture compression for multiple decomposition, and in order to improve compression uploading speed
Carry out Asynchronous loading;After all decomposition files are transmitted to server, then all decomposition files are merged, obtained
Complete picture compression file.Uploaded so as to complete the compression of full picture.
Upload is compressed to a full picture and completes and then travel through other pictures, circulates aforesaid operations, is completed
Compression to all pictures uploads.
In the above method, due in compression and upload procedure, needing Documents Comparison to be processed small every time, therefore, Ke Yiji
Big raising speed, and the requirement to network stabilization can be greatly reduced, the smooth of all decomposition files can be ensured
Transmission.
The method that picture compression provided in an embodiment of the present invention uploads, the processing mode of multithreading can be used.So as to
Uploading speed is compressed with further improve, and then the file for ensureing to need to upload can as soon as possible will in the case of network stabilization
File waiting for transmission is transmitted.
For example picture to be uploaded is 6, then in practical implementation, 6 threads can be set, each thread is equal
The method that above-mentioned compression uploads only is performed to a picture;3 threads can also be set, then each thread performs to two pictures
The method that above-mentioned compression uploads;2 threads can also be set, then each thread performs the side that above-mentioned compression uploads to three pictures
Method.Certainly, as will be understood by the skilled person in the art, 1 thread can also be set, then 6 pictures enter in the thread
Row processing.
In the embodiment of the present invention, S2 uses quality compression method and picture at least one of size compression method in proportion.Its
In, size compression method is included according to path acquisition picture and compression method and according to Bitmap picture compression methods picture in proportion.
In the embodiment of the present invention, when being compressed to picture, quality compression method can be used, can also be used according to path
Obtain picture and compression method and quality compression method combine, can also use according to Bitmap picture compressions method and quality compression method knot
Close.Two kinds of compression methods are combined, and picture is compressed, can further reduce compressed file, so as to improve compression and upload
Speed.
Quality compression method:
ByteArrayOutputStream baos=new ByteArrayOutputStream ();
Image.compress (Bit map.compressformat.JPEG, 100, baos), 100 represent not compress here, compressing
Data afterwards are put into baos.Int option=100, while (baos.toByteArray () .length/1024>
100), if whether picture is more than 100kb after cycle criterion compression, if greater than continuing to compress.Baos.reset () is reset
Baos empties image.compress (Bitmap.CompressFormat.JPEG, options, baos);Here compress
Options%, the data after compression are stored in options-=10 in baos;10 are reduced every time }.
ByteArrayInputStream isBm=new ByteArrayInputStream (baos.toByteArray ());Pressure
Data baos after contracting is stored in Bitmap bitmap=in ByteArrayInputStream
BitmapFactory.decodeStream(isBm,null,null);ByteArrayInputStream data are generated picture
return bitmap。
Picture is obtained according to path and compressed:
BitmapFactory.Options newOpts=new BitmapFactory.Options ();Start reading figure
Piece, options.inJustDecodeBounds is now set back true,
NewOpts.inJustDecodeBounds=true;Bitmap bitmap=
BitmapFactory.decodeFile(srcPath,newOpts);Bm is now returned as sky
NewOpts.inJustDecodeBounds=false;Int w=newOpts.outWidth;
Int h=newOpts.outHeight;Relatively mostly present main flow mobile phone is 800*480 resolution ratio, so height and width
We are arranged to float hh=800f;It is 800f float ww=480f to set height;Setting width is 480f pantograph ratios.
Due to being fixed proportion scaling, only carrying out calculating with high or wide one of data can int be=1;Be=1 is represented not
Scale if (w>h&&w>Ww) { scaled if width is big according to width fixed size, be=(int)
(newOpts.outWidth/ww);}else if(w<h&&h>Hh) scaled if height is high according to width fixed size,
Be=(int) (newOpts.outHeight/hh);if(be<=0) be=1;
NewOpts.inSampleSize=be;Scaling is set, picture is read in again, pays attention to now
Options.inJustDecodeBounds is set back false,
Bitmap=BitmapFactory.decodeFile (srcPath, newOpts);
return compressImage(bitmap);Quality compression is carried out again after having compressed scale.
According to Bitmap picture compressions:
If judging that picture is more than 1M, it is compressed and avoids overflowing when generating picture, reset object, compression ratio is set
Example, the picture after preservation is put into object.Pantograph ratio is set, due to being fixed proportion scaling, only with high or wide by wherein one
Individual data are calculated, and judge the width of picture, are scaled if width is big according to width fixed size, are judged height
Degree, scaled if height is high according to width fixed size, scaling is set, picture is read in again, pays attention to now
Options.inJustDecodeBounds is set back false, quality compression is carried out again after having compressed scale.
In the embodiment of the present invention, in S2, the size of the byte stream is 3072-4096 bytes, for new technology file system
For, the allocation unit size (cluster size) of acquiescence is 4096 bytes, due to cluster be the minimum unit of storage information on hard disk (just
It is to say that a cluster can not be simultaneously to two file use), therefore even the file of one byte of storage, will also take the big of cluster
Small (4096 byte);And when the file of one 4097 byte of preservation, because it is more than a cluster, two will be taken on disk
Individual cluster (8192 byte), if it is too small and disk size can be wasted, therefore byte stream size should be controlled in 3072-4096 bytes
Between.
During picture compression, byte stream size can be according to the size of picture in itself, the stability of network and mobile phone
Performance of client etc. is selected and set.For example if picture itself is bigger, bigger byte can be selected
Stream, if network stabilization is bad, can set smaller byte stream, if the performance comparision of cell-phone customer terminal is good, read
The speed ratio for evidence of fetching is very fast, then can select bigger byte stream.
In the embodiment of the present invention, in S2, the size of the byte stream is 4096 bytes.
Because being new technology file system in the system, the allocation unit size (cluster size) of acquiescence is 4096 bytes, therefore
4096 bytes of selection are made full use of for hard disk resources.
In the embodiment of the present invention, in S3, the threshold value is 512-2048kb
Theoretically file is smaller the more uploads the more fast, but speed can also be influenceed by frequently splitting.Due to the upload of website
Ceiling restriction, it will be unable to upload more than the website upper limit.So picture file is divided into the range of 512-2048kb (general opinion
The scope of altar annex selection).
In the embodiment of the present invention, in S3, the threshold value is 2048kb.
2048kb is limited to because the system uploads, so selection is divided into the file of 2048kb sizes to be uploaded, is subtracted
The frequency split less simultaneously improves the speed of upload.
In the embodiment of the present invention, after S6, in addition to step, the compressed file of the picture is decompressed, obtained original
Picture.
Law enfrocement official when checking compressed file, can decompress to it for the demand of handling a case, obtain original image.
Embodiment two
As shown in Fig. 2 the embodiments of the invention provide the system that a kind of picture compression uploads, including
Client and background server,
The client includes image generating module, picture compression module and stream file uploading module;
The background server includes stream file receiving module and stream file merging module;
The image generating module is used to obtain picture waiting for transmission;
The picture compression module is used in the form of byte stream write the picture in file, forms the picture
Stream file;
The stream file uploading module is used to the stream file is marked and uploaded;
The stream file receiving module is used to receive the stream file;
The stream file merging module is used to merge all stream files according to the mark, described in generation
The compressed file of picture.
The method and system that picture compression provided in an embodiment of the present invention uploads, can be used for during law enforcement for environmental protection, enters
Row issues task and evidence obtaining result uploads.Wherein, task is issued:, can be related by task when army unit leader carries out mission dispatching
Annex picture is issued down by the form taken pictures, while law enfrocement official is handed down to, picture is first uploaded to service
Device, after the law enfrocement official receives task, obtained on the server.Issue people and executor so as to reach and can see together
One task annex;As a result upload:When on-site law-enforcing is carried out, site inspection evidence obtaining can be carried out, law enfrocement official holds PDA
Or mobile phone, by the picture of scene evidence taking and notes information together upload, upload onto the server, it is pending after put on record or
Filing.
The method and system that picture compression provided in an embodiment of the present invention uploads, has following function or effect:First, protect
File is deposited, is consistent foreground and background data, synchrodata, if in mobile phone terminal maloperation, file imprudence is deleted, may be used also
In a manner of by synchrodata file is obtained from backstage;Second, after picture is compressed, picture size is not only reduced,
And uploading speed is improved, reduce the use of data in mobile phone flow;3rd, the integrality and authenticity of picture are saved,
It is authentic and valid to reach evidence obtaining.
By using above-mentioned technical proposal disclosed by the invention, following beneficial effect has been obtained:The present invention passes through scene
Law enforcement mobile terminal carries out sectional compression to single picture, and segmentation uploads, background server subsection receiing, and the mode remerged is real
The compression of existing picture uploads, and because the file of sectional compression is small, so uploading speed is fast, the flow of consumption is low, and to network
It is required that than relatively low, it will not be influenceed by network stabilization, it is possible to achieve smoothly transmit, so as to ensure that the suitable of enforcing law
Profit is carried out.
Each embodiment in this specification is described by the way of progressive, what each embodiment stressed be with
The difference of other embodiment, between each embodiment identical similar part mutually referring to.
Those skilled in the art should be understood that the sequential for the method and step that above-described embodiment provides can be entered according to actual conditions
Row accommodation, also can concurrently it be carried out according to actual conditions.
All or part of step in the method that above-described embodiment is related to can by program come instruct the hardware of correlation come
Complete, described program can be stored in the storage medium that computer equipment can be read, for performing the various embodiments described above side
All or part of step described in method.The computer equipment, such as:Personal computer, server, the network equipment, intelligent sliding
Dynamic terminal, intelligent home device, wearable intelligent equipment, vehicle intelligent equipment etc.;Described storage medium, such as:RAM、
ROM, magnetic disc, tape, CD, flash memory, USB flash disk, mobile hard disk, storage card, memory stick, webserver storage, network cloud storage
Deng.
Finally, it is to be noted that, herein, such as first and second or the like relational terms be used merely to by
One entity or operation make a distinction with another entity or operation, and not necessarily require or imply these entities or operation
Between any this actual relation or order be present.Moreover, term " comprising ", "comprising" or its any other variant meaning
Covering including for nonexcludability, so that process, method, commodity or equipment including a series of elements not only include that
A little key elements, but also the other element including being not expressly set out, or also include for this process, method, commodity or
The intrinsic key element of equipment.In the absence of more restrictions, the key element limited by sentence "including a ...", is not arranged
Except other identical element in the process including the key element, method, commodity or equipment being also present.
Described above is only the preferred embodiment of the present invention, it is noted that for the ordinary skill people of the art
For member, under the premise without departing from the principles of the invention, some improvements and modifications can also be made, these improvements and modifications also should
Depending on protection scope of the present invention.