ios HXPhotoPicker swift5 图片视频选择器 选取图片 照片

ios HXPhotoPicker swift5 图片视频选择器 选取图片 照片,第1张

文章目录 1.demo截图2.选取头像:需要把demo中WxMomentHeaderView.m和WxMomentViewController.m中对HXPhotoManager的设置合并在一起

1.demo截图

swift版本的项目打开会有一些语法错误, 所以我还是用的oc版本的

HXPhotoPicker - github





2.选取头像:需要把demo中WxMomentHeaderView.m和WxMomentViewController.m中对HXPhotoManager的设置合并在一起
//
//  GetImageTest.swift
//  Fei
//
//  Created by macivi on 2022/3/30.
//

import UIKit

var GImage:UIImage = UIImage()

class GetImageTest: UIViewController {

    @IBAction func compressBtnClick(_ sender: UIButton) {
        let data = GImage.compressImage()
        imageView.image = UIImage(data: data)
        printXY(data.count, obj: self, line: #line)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        imageView.image = UIImage(named: "banner")
    }

    @IBOutlet var imageView: UIImageView!
    @IBOutlet var btn: UIButton!
    
    lazy var manager:HXPhotoManager = {
        let manager = HXPhotoManager()
        manager.configuration.type = .wxMoment
        manager.configuration.localFileName = "hx_WxMomentPhotoModels"
        manager.configuration.showOriginalBytes = true
        manager.configuration.showOriginalBytesLoading = true
        manager.selectPhotoFinishDismissAnimated = true
        manager.cameraFinishDismissAnimated = true
        manager.type = .photo
        manager.configuration.singleJumpEdit = true
        manager.configuration.singleSelected = true
        manager.configuration.lookGifPhoto = false
        manager.configuration.lookLivePhoto = false
        manager.configuration.photoEditConfigur.aspectRatio = .type_1x1
        manager.configuration.photoEditConfigur.onlyCliping = true
        return manager
    }()
    
    @IBAction func btnClick(_ sender: Any) {
        print("点击事件")
        let model1 = HXPhotoBottomViewModel()
        model1.title = "更换头像"
        model1.titleColor = .hexColor(hexValue: 0x999999)
        model1.cellHeight = 40
        model1.titleFont = UIFont.systemFont(ofSize: 13)
        model1.canSelect = false
        
        let model2 = HXPhotoBottomViewModel()
        model2.title = "拍一张"
        
        let model3 = HXPhotoBottomViewModel()
        model3.title = "从手机相册选择"
        
        weak var weakSelf = self
        
        HXPhotoBottomSelectView.show(withModels: [model1,model2,model3]) { (index, photoBottomViewModel) in
            printXY(index, obj: self, line: #line)
            if index == 1{
                //拍照
                weakSelf?.hx_presentCustomCameraViewController(with: weakSelf?.manager, done: { (photoModel, customCameraViewController) in
                    photoModel?.getAssetURL(success: { (url, photoModelMediaSubType, bool, photoModel) in
                        printXY(url, obj: self, line: #line)
                        let nsdata = NSData(contentsOf: url!)
                        let data:Data = nsdata as! Data
                        let image = UIImage(data: data)
                        GImage = image!
                        weakSelf?.imageView.image = image
                        printXY(image, obj: self, line: #line)
                        printXY(data.count, obj: self, line: #line)
                    }, failed: nil)
                }, cancel: nil)
                
            }else if index == 2{
                //从相册选择
                weakSelf?.hx_presentSelectPhotoController(with: weakSelf?.manager, didDone: { (photoModelAllLists, photoModelPhotoLists, photoModelVideoLists, isOriginal, viewController, photoManager) in
                    let model = photoModelAllLists?.first
                    // 因为是编辑过的照片所以直接取
                    let image = model?.photoEdit?.editPreviewImage
                    GImage = image!
                    weakSelf?.imageView.image = image
                }, cancel: nil)
            }
        } cancelClick: {}
        
    }

}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/993195.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存