zoukankan      html  css  js  c++  java
  • 根据图片URL获取图片的尺寸【Swift语言实现】

    import UIKit

     

    extension UIImage {

     

     

        /// 获取网络图片尺寸

        ///

        /// - Parameter url: 网络图片链接

        /// - Returns: 图片尺寸size

        class func getImageSize(_ url: String?) -> CGSize {

     

            guard let urlStr = url else {

                return CGSize.zero

            }

            let tempUrl = URL(string: urlStr)

     

            let imageSourceRef = CGImageSourceCreateWithURL(tempUrl! as CFURL, nil)

            var CGFloat = 0

            var height: CGFloat = 0

            if let imageSRef = imageSourceRef {

                let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSRef, 0, nil)

     

                if let imageP = imageProperties {

                    let imageDict = imageP as Dictionary

                    width = imageDict[kCGImagePropertyPixelWidth] as! CGFloat

                    height = imageDict[kCGImagePropertyPixelHeight] as! CGFloat

                }

            }

     

            return CGSize( width, height: height)

        }

    }

     

  • 相关阅读:
    HDU 1813 Escape from Tetris
    BZOJ 2276 Temperature
    BZOJ 4499 线性函数
    BZOJ 3131 淘金
    HDU 5738 Eureka
    POJ 2409 Let it Bead
    POJ 1286 Necklace of Beads
    POJ 1696 Space Ant
    Fox And Jumping
    Recover the String
  • 原文地址:https://www.cnblogs.com/wenxp2006/p/9469366.html
Copyright © 2011-2022 走看看