Commit 374db0dc by Sarkizz

添加图片扩展,用于转换成前端的DataURL格式字符串

parent ac3c7fe5
......@@ -18,6 +18,7 @@
A70210532320FE8B009F8BC6 /* MRAlbumCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A70210502320FE8B009F8BC6 /* MRAlbumCell.swift */; };
A70210542320FE8B009F8BC6 /* MRCheckBoxImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = A70210512320FE8B009F8BC6 /* MRCheckBoxImage.swift */; };
A702105823225148009F8BC6 /* SAMutableSelectionAlbum.swift in Sources */ = {isa = PBXBuildFile; fileRef = A702105723225148009F8BC6 /* SAMutableSelectionAlbum.swift */; };
A7021067232742D7009F8BC6 /* UIImage+util.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7021066232742D7009F8BC6 /* UIImage+util.swift */; };
A73E5C8F23136605000C379B /* UIColor+util.swift in Sources */ = {isa = PBXBuildFile; fileRef = A73E5C8E23136605000C379B /* UIColor+util.swift */; };
A73E5C922313767C000C379B /* UIButton+util.swift in Sources */ = {isa = PBXBuildFile; fileRef = A73E5C912313767C000C379B /* UIButton+util.swift */; };
A73E5C95231376D6000C379B /* NamespaceWrappable.swift in Sources */ = {isa = PBXBuildFile; fileRef = A73E5C94231376D6000C379B /* NamespaceWrappable.swift */; };
......@@ -76,6 +77,7 @@
A70210502320FE8B009F8BC6 /* MRAlbumCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MRAlbumCell.swift; sourceTree = "<group>"; };
A70210512320FE8B009F8BC6 /* MRCheckBoxImage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MRCheckBoxImage.swift; sourceTree = "<group>"; };
A702105723225148009F8BC6 /* SAMutableSelectionAlbum.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SAMutableSelectionAlbum.swift; sourceTree = "<group>"; };
A7021066232742D7009F8BC6 /* UIImage+util.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImage+util.swift"; sourceTree = "<group>"; };
A73E5C8E23136605000C379B /* UIColor+util.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+util.swift"; sourceTree = "<group>"; };
A73E5C912313767C000C379B /* UIButton+util.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIButton+util.swift"; sourceTree = "<group>"; };
A73E5C94231376D6000C379B /* NamespaceWrappable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NamespaceWrappable.swift; sourceTree = "<group>"; };
......@@ -261,6 +263,7 @@
isa = PBXGroup;
children = (
A7B8E139230B9EE200999DF2 /* UIImage+file.swift */,
A7021066232742D7009F8BC6 /* UIImage+util.swift */,
A7B8E172230FCE4D00999DF2 /* UIScreen+util.swift */,
A7B8E174230FDA5200999DF2 /* UIView+util.swift */,
A7B8E176230FDEB200999DF2 /* CAGradientLayer+util.swift */,
......@@ -564,6 +567,7 @@
A7B8E177230FDEB200999DF2 /* CAGradientLayer+util.swift in Sources */,
A73E5CA12314CCBC000C379B /* String+util.swift in Sources */,
A70210522320FE8B009F8BC6 /* MRAlbumListViewController.swift in Sources */,
A7021067232742D7009F8BC6 /* UIImage+util.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
//
// UIImage+util.swift
// MRFramework
//
// Created by Sarkizz on 2019/9/10.
// Copyright © 2019 sarkizz. All rights reserved.
//
import UIKit
import Foundation
extension UIImage {
public var jpegDataURL: String? {
return jpegDataURL()
}
public func jpegDataURL(_ quality: CGFloat = 1) -> String? {
if let data = jpegData(compressionQuality: quality), let base64 = data.base64String {
return formatDataURL(with: .image_jpeg, dataType: .base64, content: base64)
}
return nil
}
public var pngDataURL: String? {
if let data = pngData(), let base64 = data.base64String {
return formatDataURL(with: .image_png, dataType: .base64, content: base64)
}
return nil
}
}
extension UIImage {
private func formatDataURL(with contentType: String.DataURLContentType,
dataType: String.DataURLDataType, content: String) -> String {
return "data:" + contentType.rawValue + ";" + dataType.rawValue + "," + content
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment