-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
142 additions
and
69 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
7 changes: 7 additions & 0 deletions
7
ReproduceCGImageRotates.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
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
2 changes: 1 addition & 1 deletion
2
ReproductCGImageRotates/AppDelegate.swift → ReproduceCGImageRotates/AppDelegate.swift
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,58 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r"> | ||
<device id="retina6_12" orientation="portrait" appearance="light"/> | ||
<dependencies> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21679"/> | ||
<capability name="Safe area layout guides" minToolsVersion="9.0"/> | ||
<capability name="System colors in document resources" minToolsVersion="11.0"/> | ||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
</dependencies> | ||
<scenes> | ||
<!--View Controller--> | ||
<scene sceneID="tne-QT-ifu"> | ||
<objects> | ||
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="ReproduceCGImageRotates" customModuleProvider="target" sceneMemberID="viewController"> | ||
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC"> | ||
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<subviews> | ||
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="FOd-4T-zfP"> | ||
<rect key="frame" x="0.0" y="119" width="393" height="393"/> | ||
<constraints> | ||
<constraint firstAttribute="width" secondItem="FOd-4T-zfP" secondAttribute="height" multiplier="1:1" id="Nfy-W9-5j7"/> | ||
</constraints> | ||
</imageView> | ||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="uqd-9p-LpO"> | ||
<rect key="frame" x="132" y="612" width="129.33333333333337" height="35"/> | ||
<state key="normal" title="Button"/> | ||
<buttonConfiguration key="configuration" style="gray" title="Open Camera"/> | ||
<connections> | ||
<action selector="onTapOpenCamera:" destination="BYZ-38-t0r" eventType="touchUpInside" id="3os-Rh-qvo"/> | ||
</connections> | ||
</button> | ||
</subviews> | ||
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/> | ||
<color key="backgroundColor" systemColor="systemBackgroundColor"/> | ||
<constraints> | ||
<constraint firstItem="uqd-9p-LpO" firstAttribute="top" secondItem="FOd-4T-zfP" secondAttribute="bottom" constant="100" id="JdH-yp-njC"/> | ||
<constraint firstItem="FOd-4T-zfP" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="L3O-nr-pjB"/> | ||
<constraint firstItem="FOd-4T-zfP" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" constant="60" id="LPy-LZ-w7J"/> | ||
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="FOd-4T-zfP" secondAttribute="trailing" id="OhV-iW-x7c"/> | ||
<constraint firstItem="uqd-9p-LpO" firstAttribute="centerX" secondItem="FOd-4T-zfP" secondAttribute="centerX" id="qkg-8m-GHI"/> | ||
</constraints> | ||
</view> | ||
<connections> | ||
<outlet property="imageView" destination="FOd-4T-zfP" id="5w1-ZQ-sB7"/> | ||
</connections> | ||
</viewController> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/> | ||
</objects> | ||
<point key="canvasLocation" x="-25.190839694656489" y="-27.464788732394368"/> | ||
</scene> | ||
</scenes> | ||
<resources> | ||
<systemColor name="systemBackgroundColor"> | ||
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> | ||
</systemColor> | ||
</resources> | ||
</document> |
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
2 changes: 1 addition & 1 deletion
2
ReproductCGImageRotates/SceneDelegate.swift → ReproduceCGImageRotates/SceneDelegate.swift
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,51 @@ | ||
// | ||
// ViewController.swift | ||
// ReproduceCGImageRotates | ||
// | ||
// Created by Yuri Tsuchikawa on 2023/09/17. | ||
// | ||
|
||
import UIKit | ||
|
||
class ViewController: UIViewController { | ||
|
||
@IBOutlet weak var imageView: UIImageView! | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
} | ||
|
||
@IBAction func onTapOpenCamera(_ sender: UIButton) { | ||
if UIImagePickerController.isSourceTypeAvailable(.camera) { | ||
let imagePicker = UIImagePickerController() | ||
imagePicker.sourceType = .camera | ||
imagePicker.delegate = self | ||
self.present(imagePicker, animated: true) | ||
} | ||
} | ||
} | ||
|
||
extension ViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate { | ||
|
||
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { | ||
picker.dismiss(animated: true) | ||
guard let image = info[.originalImage] as? UIImage, let cgImage = image.cgImage, let fixedCGImage = image.fixedCGImage else { return } | ||
print(cgImage.width, cgImage.height) // Normal CGImage which rotates | ||
print(fixedCGImage.width, fixedCGImage.height) // Fixed CGImage which NOT rotates | ||
imageView.image = UIImage(cgImage: fixedCGImage) | ||
} | ||
} | ||
|
||
extension UIImage { | ||
|
||
var fixedCGImage: CGImage? { | ||
get { | ||
UIGraphicsBeginImageContext(self.size) | ||
let context = UIGraphicsGetCurrentContext() | ||
self.draw(at: .zero) | ||
let image = UIGraphicsGetImageFromCurrentImageContext() | ||
return image?.cgImage | ||
} | ||
} | ||
} |
7 changes: 0 additions & 7 deletions
7
ReproductCGImageRotates.xcodeproj/project.xcworkspace/contents.xcworkspacedata
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.