Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Material
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
Material
Commits
d4aada39
Commit
d4aada39
authored
Jul 24, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved adjustOrientation UIImage helper to UIImage instance methods
parent
ffd980fe
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
80 deletions
+61
-80
Sources/iOS/CaptureSession.swift
+1
-61
Sources/iOS/Material+UIImage.swift
+59
-0
Sources/iOS/View.swift
+1
-19
No files found.
Sources/iOS/CaptureSession.swift
View file @
d4aada39
...
@@ -575,7 +575,7 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
...
@@ -575,7 +575,7 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
if
nil
==
captureError
{
if
nil
==
captureError
{
let
data
:
NSData
=
AVCaptureStillImageOutput
.
jpegStillImageNSDataRepresentation
(
sampleBuffer
)
let
data
:
NSData
=
AVCaptureStillImageOutput
.
jpegStillImageNSDataRepresentation
(
sampleBuffer
)
if
let
image1
:
UIImage
=
UIImage
(
data
:
data
as
Data
)
{
if
let
image1
:
UIImage
=
UIImage
(
data
:
data
as
Data
)
{
if
let
image2
:
UIImage
=
s
.
adjustOrientationForImage
(
image
:
image1
)
{
if
let
image2
:
UIImage
=
image1
.
adjustOrientation
(
)
{
s
.
delegate
?
.
captureSessionStillImageAsynchronously
?(
captureSession
:
s
,
image
:
image2
)
s
.
delegate
?
.
captureSessionStillImageAsynchronously
?(
captureSession
:
s
,
image
:
image2
)
}
else
{
}
else
{
var
userInfo
:
Dictionary
<
String
,
AnyObject
>
=
Dictionary
<
String
,
AnyObject
>
()
var
userInfo
:
Dictionary
<
String
,
AnyObject
>
=
Dictionary
<
String
,
AnyObject
>
()
...
@@ -732,64 +732,4 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
...
@@ -732,64 +732,4 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
}
}
return
nil
return
nil
}
}
/**
Adjusts the orientation of the image from the capture orientation.
This is an issue when taking images, the capture orientation is not set correctly
when using Portrait.
- Parameter image: A UIImage to adjust.
- Returns: An optional UIImage if successful.
*/
private
func
adjustOrientationForImage
(
image
:
UIImage
)
->
UIImage
?
{
guard
.
up
!=
image
.
imageOrientation
else
{
return
image
}
var
transform
:
CGAffineTransform
=
.
identity
// Rotate if Left, Right, or Down.
switch
image
.
imageOrientation
{
case
.
down
,
.
downMirrored
:
transform
=
transform
.
translateBy
(
x
:
image
.
size
.
width
,
y
:
image
.
size
.
height
)
transform
=
transform
.
rotate
(
CGFloat
(
M_PI
))
case
.
left
,
.
leftMirrored
:
transform
=
transform
.
translateBy
(
x
:
image
.
size
.
width
,
y
:
0
)
transform
=
transform
.
rotate
(
CGFloat
(
M_PI_2
))
case
.
right
,
.
rightMirrored
:
transform
=
transform
.
translateBy
(
x
:
0
,
y
:
image
.
size
.
height
)
transform
=
transform
.
rotate
(
-
CGFloat
(
M_PI_2
))
default
:
break
}
// Flip if mirrored.
switch
image
.
imageOrientation
{
case
.
upMirrored
,
.
downMirrored
:
transform
=
transform
.
translateBy
(
x
:
image
.
size
.
width
,
y
:
0
)
transform
=
transform
.
scaleBy
(
x
:
-
1
,
y
:
1
)
case
.
leftMirrored
,
.
rightMirrored
:
transform
=
transform
.
translateBy
(
x
:
image
.
size
.
height
,
y
:
0
)
transform
=
transform
.
scaleBy
(
x
:
-
1
,
y
:
1
)
default
:
break
}
// Draw the underlying cgImage with the calculated transform.
guard
let
context
=
CGContext
(
data
:
nil
,
width
:
Int
(
image
.
size
.
width
),
height
:
Int
(
image
.
size
.
height
),
bitsPerComponent
:
image
.
cgImage
!.
bitsPerComponent
,
bytesPerRow
:
0
,
space
:
image
.
cgImage
!.
colorSpace
!
,
bitmapInfo
:
image
.
cgImage
!.
bitmapInfo
.
rawValue
)
else
{
return
nil
}
context
.
concatCTM
(
transform
)
switch
image
.
imageOrientation
{
case
.
left
,
.
leftMirrored
,
.
right
,
.
rightMirrored
:
context
.
draw
(
in
:
CGRect
(
x
:
0
,
y
:
0
,
width
:
image
.
size
.
height
,
height
:
image
.
size
.
width
),
image
:
image
.
cgImage
!
)
default
:
context
.
draw
(
in
:
CGRect
(
origin
:
.
zero
,
size
:
image
.
size
),
image
:
image
.
cgImage
!
)
}
guard
let
cgImage
=
context
.
makeImage
()
else
{
return
nil
}
return
UIImage
(
cgImage
:
cgImage
)
}
}
}
Sources/iOS/Material+UIImage.swift
View file @
d4aada39
...
@@ -177,4 +177,63 @@ public extension UIImage {
...
@@ -177,4 +177,63 @@ public extension UIImage {
}
}
}
.
resume
()
}
.
resume
()
}
}
/**
Adjusts the orientation of the image from the capture orientation.
This is an issue when taking images, the capture orientation is not set correctly
when using Portrait.
- Returns: An optional UIImage if successful.
*/
public
func
adjustOrientation
()
->
UIImage
?
{
guard
.
up
!=
imageOrientation
else
{
return
self
}
var
transform
:
CGAffineTransform
=
.
identity
// Rotate if Left, Right, or Down.
switch
imageOrientation
{
case
.
down
,
.
downMirrored
:
transform
=
transform
.
translateBy
(
x
:
size
.
width
,
y
:
size
.
height
)
transform
=
transform
.
rotate
(
CGFloat
(
M_PI
))
case
.
left
,
.
leftMirrored
:
transform
=
transform
.
translateBy
(
x
:
size
.
width
,
y
:
0
)
transform
=
transform
.
rotate
(
CGFloat
(
M_PI_2
))
case
.
right
,
.
rightMirrored
:
transform
=
transform
.
translateBy
(
x
:
0
,
y
:
size
.
height
)
transform
=
transform
.
rotate
(
-
CGFloat
(
M_PI_2
))
default
:
break
}
// Flip if mirrored.
switch
imageOrientation
{
case
.
upMirrored
,
.
downMirrored
:
transform
=
transform
.
translateBy
(
x
:
size
.
width
,
y
:
0
)
transform
=
transform
.
scaleBy
(
x
:
-
1
,
y
:
1
)
case
.
leftMirrored
,
.
rightMirrored
:
transform
=
transform
.
translateBy
(
x
:
size
.
height
,
y
:
0
)
transform
=
transform
.
scaleBy
(
x
:
-
1
,
y
:
1
)
default
:
break
}
// Draw the underlying cgImage with the calculated transform.
guard
let
context
=
CGContext
(
data
:
nil
,
width
:
Int
(
size
.
width
),
height
:
Int
(
size
.
height
),
bitsPerComponent
:
cgImage
!.
bitsPerComponent
,
bytesPerRow
:
0
,
space
:
cgImage
!.
colorSpace
!
,
bitmapInfo
:
cgImage
!.
bitmapInfo
.
rawValue
)
else
{
return
nil
}
context
.
concatCTM
(
transform
)
switch
imageOrientation
{
case
.
left
,
.
leftMirrored
,
.
right
,
.
rightMirrored
:
context
.
draw
(
in
:
CGRect
(
x
:
0
,
y
:
0
,
width
:
size
.
height
,
height
:
size
.
width
),
image
:
cgImage
!
)
default
:
context
.
draw
(
in
:
CGRect
(
origin
:
.
zero
,
size
:
size
),
image
:
cgImage
!
)
}
guard
let
cgImage
=
context
.
makeImage
()
else
{
return
nil
}
return
UIImage
(
cgImage
:
cgImage
)
}
}
}
Sources/iOS/View.swift
View file @
d4aada39
...
@@ -131,24 +131,6 @@ public class View: UIView {
...
@@ -131,24 +131,6 @@ public class View: UIView {
}
}
/**
/**
A property that manages the overall shape for the object. If either the
width or height property is set, the other will be automatically adjusted
to maintain the shape of the object.
*/
public
var
shape
:
ShapePreset
=
.
none
{
didSet
{
if
.
none
!=
shape
{
if
width
<
height
{
frame
.
size
.
width
=
height
}
else
{
frame
.
size
.
height
=
width
}
layoutShadowPath
()
}
}
}
/**
An initializer that initializes the object with a NSCoder object.
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
- Parameter aDecoder: A NSCoder instance.
*/
*/
...
@@ -217,7 +199,7 @@ public class View: UIView {
...
@@ -217,7 +199,7 @@ public class View: UIView {
/// Manages the layout for the shape of the view instance.
/// Manages the layout for the shape of the view instance.
internal
func
layoutShape
()
{
internal
func
layoutShape
()
{
if
.
circle
==
shape
{
if
.
circle
==
shape
Preset
{
let
w
:
CGFloat
=
(
width
/
2
)
let
w
:
CGFloat
=
(
width
/
2
)
if
w
!=
cornerRadius
{
if
w
!=
cornerRadius
{
cornerRadius
=
w
cornerRadius
=
w
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment