Skip to content

Instantly share code, notes, and snippets.

@thekan23
thekan23 / ElasticView.swift
Created Oct 13, 2018
DisplayLink + BezierPath를 사용한 애니메이션
View ElasticView.swift
import Foundation
import UIKit
class ElasticView: UIView {
private let topControlPointView = UIView()
private let leftControlPointView = UIView()
private let rightControlPointView = UIView()
private let bottomControlPointView = UIView()
@thekan23
thekan23 / UIImage+Extension.swift
Created Nov 4, 2018
UIKit 프레임워크를 사용한 이미지 리사이징
View UIImage+Extension.swift
extension UIImage {
func resizeUI(size:CGSize) -> UIImage? {
UIGraphicsBeginImageContextWithOptions(size, true, self.scale)
self.drawInRect(CGRect(origin: CGPointZero, size: size))
let resizedImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return resizedImage
}
}
@thekan23
thekan23 / UIImage+Extension.swift
Created Nov 4, 2018
CoreGraphics를 사용한 이미지 리사이징
View UIImage+Extension.swift
extension UIImage {
func resizeCG(size:CGSize) -> UIImage? {
let bitsPerComponent = CGImageGetBitsPerComponent(self.CGImage)
let bytesPerRow = CGImageGetBytesPerRow(self.CGImage)
let colorSpace = CGImageGetColorSpace(self.CGImage)
let bitmapInfo = CGImageGetBitmapInfo(self.CGImage)
let context = CGBitmapContextCreate(nil, Int(size.width), Int(size.height), bitsPerComponent, bytesPerRow, colorSpace, bitmapInfo.rawValue)
CGContextSetInterpolationQuality(context, .High)
@thekan23
thekan23 / UIImage+Extension.swift
Created Nov 4, 2018
vImage를 사용한 이미지 리사이징 (가장 빠르고 정확)
View UIImage+Extension.swift
extension UIImage {
func resizeVI(size:CGSize) -> UIImage? {
let cgImage = self.CGImage!
var format = vImage_CGImageFormat(bitsPerComponent: 8, bitsPerPixel: 32, colorSpace: nil,
bitmapInfo: CGBitmapInfo(rawValue: CGImageAlphaInfo.First.rawValue),
version: 0, decode: nil, renderingIntent: CGColorRenderingIntent.RenderingIntentDefault)
var sourceBuffer = vImage_Buffer()
defer {
sourceBuffer.data.dealloc(Int(sourceBuffer.height) * Int(sourceBuffer.height) * 4)