Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
zhangyongji
/
MRFramework
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
3cd86481
authored
Sep 14, 2019
by
Sarkizz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
把图片写入操作放到异步
parent
392a855d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
32 deletions
+32
-32
MRFramework/MRFramework/Extensions/UIKit/UIImage+file.swift
+32
-32
No files found.
MRFramework/MRFramework/Extensions/UIKit/UIImage+file.swift
View file @
3cd86481
...
...
@@ -36,6 +36,36 @@ extension UIImage {
if
!
FileManager
.
default
.
fileExists
(
atPath
:
url
.
absoluteString
)
{
do
{
try
FileManager
.
default
.
createDirectory
(
at
:
url
,
withIntermediateDirectories
:
true
,
attributes
:
nil
)
var
q
:
CGFloat
=
1
var
thumbPath
:
URL
?
switch
config
{
case
.
custom
(
let
size
,
let
quality
):
q
=
quality
if
let
thumbImage
=
self
.
thumbImage
(
size
)
{
thumbPath
=
url
.
appendingPathComponent
(
self
.
thumbName
(
with
:
name
,
size
:
thumbImage
.
size
))
let
error
=
thumbImage
.
writeFile
(
to
:
thumbPath
!
,
q
)
if
error
!=
nil
{
DispatchQueue
.
main
.
async
{
complate
?(
nil
,
nil
,
error
)
}
return
}
}
break
default
:
break
}
let
fullPath
=
url
.
appendingPathComponent
(
name
)
let
error
=
self
.
writeFile
(
to
:
fullPath
,
q
)
DispatchQueue
.
main
.
async
{
if
let
error
=
error
{
complate
?(
nil
,
nil
,
error
)
}
else
{
complate
?(
fullPath
,
thumbPath
,
nil
)
}
}
}
catch
let
error
{
DispatchQueue
.
main
.
async
{
complate
?(
nil
,
nil
,
error
)
...
...
@@ -43,36 +73,6 @@ extension UIImage {
return
}
}
var
q
:
CGFloat
=
1
var
thumbPath
:
URL
?
switch
config
{
case
.
custom
(
let
size
,
let
quality
):
q
=
quality
if
let
thumbImage
=
self
.
thumbImage
(
size
)
{
thumbPath
=
url
.
appendingPathComponent
(
self
.
thumbName
(
with
:
name
,
size
:
thumbImage
.
size
))
let
error
=
thumbImage
.
writeFile
(
to
:
thumbPath
!
,
q
)
if
error
!=
nil
{
DispatchQueue
.
main
.
async
{
complate
?(
nil
,
nil
,
error
)
}
return
}
}
break
default
:
break
}
let
fullPath
=
url
.
appendingPathComponent
(
name
)
let
error
=
self
.
writeFile
(
to
:
fullPath
,
q
)
DispatchQueue
.
main
.
async
{
if
let
error
=
error
{
complate
?(
nil
,
nil
,
error
)
}
else
{
complate
?(
fullPath
,
thumbPath
,
nil
)
}
}
}
}
...
...
@@ -113,9 +113,9 @@ extension UIImage {
let
wr
=
size
.
width
/
self
.
size
.
width
let
hr
=
size
.
height
/
self
.
size
.
height
if
wr
>
hr
{
return
CGSize
(
width
:
size
.
width
,
height
:
self
.
size
.
height
*
wr
)
}
else
{
return
CGSize
(
width
:
self
.
size
.
width
*
hr
,
height
:
size
.
height
)
}
else
{
return
CGSize
(
width
:
size
.
width
,
height
:
self
.
size
.
height
*
wr
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment