CN105786997A - IOS-system-based image caching and compression method - Google Patents

IOS-system-based image caching and compression method Download PDF

Info

Publication number
CN105786997A
CN105786997A CN201610092286.XA CN201610092286A CN105786997A CN 105786997 A CN105786997 A CN 105786997A CN 201610092286 A CN201610092286 A CN 201610092286A CN 105786997 A CN105786997 A CN 105786997A
Authority
CN
China
Prior art keywords
picture
download
buffer memory
compression
cache
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201610092286.XA
Other languages
Chinese (zh)
Inventor
王雨桐
周嘉立
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Sichuan Changhong Electric Co Ltd
Original Assignee
Sichuan Changhong Electric Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Sichuan Changhong Electric Co Ltd filed Critical Sichuan Changhong Electric Co Ltd
Priority to CN201610092286.XA priority Critical patent/CN105786997A/en
Publication of CN105786997A publication Critical patent/CN105786997A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/957Browsing optimisation, e.g. caching or content distillation
    • G06F16/9574Browsing optimisation, e.g. caching or content distillation of access to content, e.g. by caching
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/955Retrieval from the web using information identifiers, e.g. uniform resource locators [URL]

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Memory System Of A Hierarchy Structure (AREA)

Abstract

The invention discloses an iOS-system-based image caching and compression method.According to the method, several steps are additionally added on the basis of a third party framework based on SDWebImage so that images can be compressed in the image caching process, and compression modes include image size compression, image user-defined size compression and image equal-proportion compression.By means of the method, the caching images which are not used for a long time can be removed automatically, and synchronous operation with a server can be conducted.

Description

Image cache and compression method based on iOS system
Technical field
The present invention relates to the picture Processing Technique in iOS system, be specifically related to a kind of image cache based on iOS system and compression method.
Background technology
In current iOS system on the market, the buffer memory of picture and compression mainly being used some third-party frameworks, these third party's frameworks mainly include AFNetworking, FastImageCache, SDWebimage;
The basic workflow of these frameworks is download pictures;Picture processing (cutting, frame etc.);Write disk;Data are read to kernel buffers from disk;User's space (memory hierarchy copy) is copied to from kernel buffers;Decompression is condensed to bitmap (cpu is higher for consumption);If data bitmap is not byte-aligned, CoreAnimation meeting copy portion data bitmap also carries out byte-aligned;CoreAnimation renders the bitmap decompressed.
The memory cache that wherein AFNetworking provides is machine-processed, and he does not provide the operation removing buffer memory;FastImageCache has done a lot of optimization to from disk reading file, such as uses mmap internal memory to map, eliminates data and copy the operation of user's space from kernel spacing to.The decoded data bitmap of buffer memory is to disk, and next time saves the operation of decoding from disk when reading.Generate the data of byte-aligned, it is prevented that CoreAnimation copies a data again when rendering.But the not function of asynchronous download pictures;
What present stage employed up to is this third party's framework of SDWebImage.The framework provides the mode of highly stable efficient asynchronous download pictures, it is provided that the method for memory cache and disk buffering, and provide the method removing buffer memory.The basic step of this framework buffer memory picture is to start to process picture according to URL;From whether cache lookup picture is downloaded;First from whether internal memory picture cache lookup has picture, if internal memory there being image cache return UIImageView object front end exhibiting pictures;If do not had in memory cache, whether generation NSInvocationOperation adds queue to and starts from hard disk lookup picture buffered;Attempt reading picture file under hard disk cache catalogue according to URLKey;If last action read picture from hard disk, picture is added in memory cache (if free memory is too small, can first empty memory cache).And then readjustment exhibiting pictures;If read less than picture from hard disk cache catalogue, illustrate that all buffer memorys are all absent from this picture, it is necessary to download pictures;Share or regenerate a downloader and start download pictures;Data do picture decoding process after having downloaded;Picture decoding process completes at a NSOperationQueue, will not drag slow main thread UI.If necessary the picture downloaded being carried out after-treatment, also here complete, efficiency can be well a lot;Decoding completes, and informs that picture has been downloaded;Exhibiting pictures;Being saved in SDImageCache by picture, memory cache and hard disk cache preserve simultaneously;Written document also completes with independent NSInvocationOperation to hard disk, it is to avoid drag slow main thread.
But this framework cannot realize automatically detecting the use frequency of picture, must manually remove when removing buffer memory, it is impossible to realize automatically removing unused time and exceed the picture of threshold value;When buffer memory picture, the framework provides the compression to picture size, but operation dimension of picture cannot being compressed;And after picture processing, it is impossible to synchronize with server, the selective data updating server.
Summary of the invention
Instant invention overcomes third party's framework existence removing buffer memory in carrying out image cache and compression in prior art must manually remove, the deficiency simultaneously dimension of picture cannot being compressed, it is provided that the image cache based on iOS system of a kind of performance improving image cache and speed and compression method.
For achieving the above object, the present invention is by the following technical solutions:
A kind of image cache based on iOS system and compression method, the method is based on SDWebImage third party's framework, and it comprises the following steps:
S1, sends network request, according to incoming URL request picture and create a new thread;
S2, according to URL as Key judge picture whether store with in memory cache, if being stored in memory cache, directly invoking picture and using, if being not stored in memory cache, judge whether picture is stored in disk buffering again, if being stored in disk buffering, directly invoking picture and using, if being not stored in disk buffering, entering step S3;
S3, according to URL to specifying Address requests download pictures, if there is Network Abnormal, then points out error information, if normally having access to appointment address, then enters step S4;
S4, starts download pictures, if occurring downloading extremely, deletes current task, if normal, enters step S5 after the download is complete;
S5, processes the picture of download or buffer memory and preserves, and detection is downloaded or whether the picture size of buffer memory exceedes threshold values, is then enter step S51, otherwise enters step S52;
S51, carries out size compression process by the picture of download or buffer memory, and arranges erasing time threshold values;
S52, whether the size of the picture of detection download or buffer memory is the size required for iOS application, is then enter step S54, otherwise enters step S53;
S53, carries out size compression process by the picture of download or buffer memory;
S54, preserves the picture of download or buffer memory;
S6, according to demand, chooses whether to synchronize with server;When calling picture, if the picture in the picture of local cache and server is not inconsistent, it is possible to server re-request picture, buffer memory again;
S7, detects the upper erasing time threshold values whether exceeding setting interval time once used between time and current time of each pictures within the time cycle, if exceeding, system calls removing caching automatically, removes figure according to the URL of picture.
Further technical scheme is, the picture of download or buffer memory is carried out size compression process and includes picture size compression, the self-defined compression of dimension of picture or the compression of dimension of picture equal proportion by described step S53.
Compared with prior art, the invention has the beneficial effects as follows:
The present invention is on the basis based on SDWebImage third party's framework, and extra adds several step, realize in image cache process can compressed picture, compress including picture size, picture custom size compresses, and picture equal proportion is compressed;Long-time untapped buffer memory picture can be removed automatically;Synchronize operation can be carried out with server.
The present invention had both inherited advantage and the bottom architecture of SDWebImage third party's framework, again can according to the unique need of oneself, more practical approach is provided, not only improve the quantity of function, also improve performance and the speed of image cache, no matter be in the operational efficiency of development efficiency or application program itself, have bigger lifting.
Accompanying drawing explanation
Fig. 1 is the image cache based on iOS system and the compression method overall flow figure of an embodiment of the present invention.
Fig. 2 is the image cache based on iOS system and the compression process figure in compression method of an embodiment of the present invention.
Detailed description of the invention
Below in conjunction with accompanying drawing, the present invention is further elaborated.
The image cache based on iOS system as depicted in figs. 1 and 2 and compression method the method are based on SDWebImage third party's framework, and it comprises the following steps:
S1, sends network request, according to incoming URL request picture and create a new thread;
S2, according to URL as Key judge picture whether store with in memory cache, if being stored in memory cache, directly invoking picture and using, if being not stored in memory cache, judge whether picture is stored in disk buffering again, if being stored in disk buffering, directly invoking picture and using, if being not stored in disk buffering, entering step S3;
S3, according to URL to specifying Address requests download pictures, if there is Network Abnormal, then points out error information, if normally having access to appointment address, then enters step S4;
S4, starts download pictures, if occurring downloading extremely, deletes current task, if normal, enters step S5 after the download is complete;
S5, processes the picture of download or buffer memory and preserves, and detection is downloaded or whether the picture size of buffer memory exceedes threshold values, is then enter step S51, otherwise enters step S52;
S51, carries out size compression process by the picture of download or buffer memory, and arranges erasing time threshold values;
S52, whether the size of the picture of detection download or buffer memory is the size required for iOS application, is then enter step S54, otherwise enters step S53;
S53, carries out size compression process by the picture of download or buffer memory;
S54, preserves the picture of download or buffer memory;
S6, according to demand, chooses whether to synchronize with server;When calling picture, if the picture in the picture of local cache and server is not inconsistent, it is possible to server re-request picture, buffer memory again;
S7, detects the upper erasing time threshold values whether exceeding setting interval time once used between time and current time of each pictures within the time cycle, if exceeding, system calls removing caching automatically, removes picture according to the URL of picture.
The picture of download or buffer memory is carried out size compression process and includes picture size compression, the self-defined compression of dimension of picture or the compression of dimension of picture equal proportion by step S53.
The function that the present invention mainly realizes is as follows:
One is in the process of picture processing, and picture is compressed, including the compression of picture size, the self-defined compression of dimension of picture and equal proportion compression.Improve the efficiency of picture transfer.
Two are able to use frequency to detect in the picture in cache pool, no matter are in internal memory or in disk, once find that picture does not use for a long time, just deleting this picture automatically, improve the efficiency that internal memory uses.
Picture in three pictures being able to compare in buffer memory and server, if it is different, can optionally synchronize, reaches the effect that the once amendment overall situation comes into force.
The essence of the present invention is described in detail by above detailed description of the invention; but protection scope of the present invention can not be limited; apparently; under the enlightenment of the present invention; the art those of ordinary skill can also carry out many improvement and modification; it should be noted that these improve and modify within the claims all dropping on the present invention.

Claims (2)

1., based on the image cache of iOS system and a compression method, the method is based on SDWebImage third party's framework, it is characterised in that: it comprises the following steps:
S1, sends network request, according to incoming URL request picture and create a new thread;
S2, according to URL as Key judge picture whether store with in memory cache, if being stored in memory cache, directly invoking picture and using, if being not stored in memory cache, judge whether picture is stored in disk buffering again, if being stored in disk buffering, directly invoking picture and using, if being not stored in disk buffering, entering step S3;
S3, according to URL to specifying Address requests download pictures, if there is Network Abnormal, then points out error information, if normally having access to appointment address, then enters step S4;
S4, starts download pictures, if occurring downloading extremely, deletes current task, if normal, enters step S5 after the download is complete;
S5, processes the picture of download or buffer memory and preserves, and detection is downloaded or whether the picture size of buffer memory exceedes threshold values, is then enter step S51, otherwise enters step S52;
S51, carries out size compression process by the picture of download or buffer memory, and arranges erasing time threshold values;
S52, whether the size of the picture of detection download or buffer memory is the size required for iOS application, is then enter step S54, otherwise enters step S53;
S53, carries out size compression process by the picture of download or buffer memory;
S54, preserves the picture of download or buffer memory;
S6, according to demand, chooses whether to synchronize with server;When calling picture, if the picture in the picture of local cache and server is not inconsistent, it is possible to server re-request picture, buffer memory again;
S7, detects the upper erasing time threshold values whether exceeding setting interval time once used between time and current time of each pictures within the time cycle, if exceeding, system calls removing caching automatically, removes picture according to the URL of picture.
2. according to claim 1, it is characterised in that the picture of download or buffer memory is carried out size compression process and includes picture size compression, the self-defined compression of dimension of picture or the compression of dimension of picture equal proportion by described step S53.
CN201610092286.XA 2016-02-19 2016-02-19 IOS-system-based image caching and compression method Pending CN105786997A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610092286.XA CN105786997A (en) 2016-02-19 2016-02-19 IOS-system-based image caching and compression method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610092286.XA CN105786997A (en) 2016-02-19 2016-02-19 IOS-system-based image caching and compression method

Publications (1)

Publication Number Publication Date
CN105786997A true CN105786997A (en) 2016-07-20

Family

ID=56403536

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610092286.XA Pending CN105786997A (en) 2016-02-19 2016-02-19 IOS-system-based image caching and compression method

Country Status (1)

Country Link
CN (1) CN105786997A (en)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106294663A (en) * 2016-08-04 2017-01-04 网宿科技股份有限公司 A kind of electronic equipment and application image processing method and system
CN106354847A (en) * 2016-08-31 2017-01-25 张北江 Application method and system of image scheduling in instant messaging
CN106528442A (en) * 2016-10-27 2017-03-22 北京小米移动软件有限公司 Cache cleaning method and device
CN107273541A (en) * 2017-07-05 2017-10-20 武汉斗鱼网络科技有限公司 Network picture display method, device and electric terminal
CN109587232A (en) * 2018-11-28 2019-04-05 陕西天诚软件有限公司 Document breakpoint transmission method based on iOS network
CN111597479A (en) * 2020-04-18 2020-08-28 北京奇保信安科技有限公司 Intelligent picture loading method and device for terminal and electronic equipment

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103559009A (en) * 2013-10-30 2014-02-05 浙江省公众信息产业有限公司 Geographic information terminal and geographic information presentation method
CN103888602A (en) * 2014-03-03 2014-06-25 广州金山网络科技有限公司 Method and device for controlling display list in mobile terminal
US20140280515A1 (en) * 2013-03-15 2014-09-18 Yottaa Inc. System and method for managing multiple variants of an http object
CN104808907A (en) * 2015-05-20 2015-07-29 腾讯科技(深圳)有限公司 Method and device for displaying content in same screen, and terminal equipment

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140280515A1 (en) * 2013-03-15 2014-09-18 Yottaa Inc. System and method for managing multiple variants of an http object
CN103559009A (en) * 2013-10-30 2014-02-05 浙江省公众信息产业有限公司 Geographic information terminal and geographic information presentation method
CN103888602A (en) * 2014-03-03 2014-06-25 广州金山网络科技有限公司 Method and device for controlling display list in mobile terminal
CN104808907A (en) * 2015-05-20 2015-07-29 腾讯科技(深圳)有限公司 Method and device for displaying content in same screen, and terminal equipment

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
卡祖利诺等著: "《C#Web应用程序入门经典》", 31 December 2013 *
无线互联3G学院: ""对SDWebImage的浅分析"", 《百度文库,HTTP://WENKU.BAIDU.COM/VIEW/BFF6A934804D2B160A4EC04F.HTML》 *

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106294663A (en) * 2016-08-04 2017-01-04 网宿科技股份有限公司 A kind of electronic equipment and application image processing method and system
CN106354847A (en) * 2016-08-31 2017-01-25 张北江 Application method and system of image scheduling in instant messaging
CN106528442A (en) * 2016-10-27 2017-03-22 北京小米移动软件有限公司 Cache cleaning method and device
CN107273541A (en) * 2017-07-05 2017-10-20 武汉斗鱼网络科技有限公司 Network picture display method, device and electric terminal
CN109587232A (en) * 2018-11-28 2019-04-05 陕西天诚软件有限公司 Document breakpoint transmission method based on iOS network
CN111597479A (en) * 2020-04-18 2020-08-28 北京奇保信安科技有限公司 Intelligent picture loading method and device for terminal and electronic equipment

Similar Documents

Publication Publication Date Title
CN105786997A (en) IOS-system-based image caching and compression method
TWI691931B (en) Picture loading method and device
WO2016101757A1 (en) Image processing method and device based on mobile device
CN106453572A (en) Method and system for synchronizing images based on cloud server
CN102223681B (en) IOT system and cache control method therein
CN104010151A (en) Method for compressing monitoring video file
CN101714161A (en) Cache device and method for embedded browser
US10031948B1 (en) Idempotence service
CN111447370B (en) Camera access method, camera access device, terminal equipment and readable storage medium
WO2017166760A1 (en) Method, apparatus, mobile terminal, and electronic device for reviewing image file
WO2017202175A1 (en) Method and device for video compression and electronic device
CN107463378A (en) A kind of local cache implementation method, storage device and electronic equipment based on note
WO2016202215A1 (en) Method and device for previewing dynamic image, and method and device for displaying expression package
US11521025B2 (en) Selective image compression of an image stored on a device based on user preferences
WO2018040964A1 (en) Network image loading method, device and system
CN114422807B (en) Transmission optimization method based on Spice protocol
CN109587232A (en) Document breakpoint transmission method based on iOS network
CN103544221A (en) Method and system for generating video thumbnail in Android system
CN102855602B (en) Picture processing method and picture processing device
WO2023143545A1 (en) Resource processing method and apparatus, electronic device, and computer-readable storage medium
CN110941597B (en) Method and device for cleaning decompressed file, computing equipment and computer storage medium
TWI423682B (en) Image processing method
CN103942120B (en) A kind of reading/writing method and system based on Intel Virtualization Technology
CN109582417A (en) A kind of method for showing interface, client and picture servers
CA2930061A1 (en) Variants of files in a file system

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20160720

RJ01 Rejection of invention patent application after publication