Skip to content

Adds copying to C4Image #589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions C4/UI/C4Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public struct Pixel {
}

/// A C4Image provides a view-based container for displaying a single image. You can create images from files, from other image objects, or from raw image data you receive.
public class C4Image: C4View {
public class C4Image: C4View, NSCopying {

//MARK: Initializers

Expand Down Expand Up @@ -294,7 +294,25 @@ public class C4Image: C4View {

self.init(cgimage: cgim!)
}


convenience public init(c4image: C4Image) {
let cgim = c4image.cgimage
self.init(cgimage: cgim)
}

public func copyWithZone(zone: NSZone) -> AnyObject {
let uiimage = UIImage(CGImage: self.contents)
let img = C4Image(uiimage: uiimage, scale: scale)
img.frame = self.frame
img.constrainsProportions = self.constrainsProportions
img._originalSize = _originalSize
return img
}

public func mutableCopyWithZone(zone: NSZone) -> AnyObject {
return copyWithZone(zone)
}

//MARK: Properties

/// Returns the UIImageView of the object.
Expand Down Expand Up @@ -350,6 +368,11 @@ public class C4Image: C4View {
}
}

/// The scale factor of the image. (read-only)
var scale: Double {
return Double(uiimage.scale)
}

/// A variable that provides access to the width of the receiver. Animatable.
/// The default value of this property is defined by the image being created.
/// Assigning a value to this property causes the receiver to change the width of its frame. If the receiver's
Expand Down