-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from DeveloperAcademy-POSTECH/soi
Feat: 음악 검색 기능, 이미지 저장 기능
- Loading branch information
Showing
7 changed files
with
194 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// Screenshot.swift | ||
// Recorder | ||
// | ||
// Created by 이지원 on 2022/06/15. | ||
// | ||
|
||
import SwiftUI | ||
|
||
// 이미지 저장 기능을 위한 확장 | ||
extension View { | ||
|
||
func screenshot() -> UIImage { | ||
|
||
var image: UIImage? | ||
let scenes = UIApplication.shared.connectedScenes | ||
let windowScenes = scenes.first as? UIWindowScene | ||
guard let currentView = windowScenes?.windows.first(where: { $0.isKeyWindow })?.layer else { return UIImage() } | ||
let screenScale = UIScreen.main.scale | ||
|
||
// image capture | ||
UIGraphicsBeginImageContextWithOptions(currentView.frame.size, false, screenScale) | ||
guard let currentContext = UIGraphicsGetCurrentContext() else { return UIImage() } | ||
currentView.render(in: currentContext) | ||
image = UIGraphicsGetImageFromCurrentImageContext() | ||
UIGraphicsEndImageContext() | ||
|
||
// crop image | ||
let cropRect: CGRect = .init(origin: CGPoint(x: 0, y: 250), size: CGSize(width: 1500 , height: 2000)) | ||
let imageRef = image!.cgImage!.cropping(to: cropRect); | ||
let newImage = UIImage(cgImage: imageRef!, scale: image!.scale, orientation: image!.imageOrientation) | ||
|
||
return newImage | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.