Works
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1230"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "FC74E21A2591889F00ACBBFF"
|
||||
BuildableName = "ImageCreation"
|
||||
BlueprintName = "ImageCreation"
|
||||
ReferencedContainer = "container:ImageCreation.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "FC74E21A2591889F00ACBBFF"
|
||||
BuildableName = "ImageCreation"
|
||||
BlueprintName = "ImageCreation"
|
||||
ReferencedContainer = "container:ImageCreation.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
<EnvironmentVariables>
|
||||
<EnvironmentVariable
|
||||
key = "CGBITMAP_CONTEXT_LOG_ERRORS"
|
||||
value = "1"
|
||||
isEnabled = "YES">
|
||||
</EnvironmentVariable>
|
||||
</EnvironmentVariables>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "FC74E21A2591889F00ACBBFF"
|
||||
BuildableName = "ImageCreation"
|
||||
BlueprintName = "ImageCreation"
|
||||
ReferencedContainer = "container:ImageCreation.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Bucket
|
||||
uuid = "2AB13B00-E21B-4223-B6C7-A546E02EE846"
|
||||
type = "1"
|
||||
version = "2.0">
|
||||
</Bucket>
|
||||
@@ -10,5 +10,13 @@
|
||||
<integer>0</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>SuppressBuildableAutocreation</key>
|
||||
<dict>
|
||||
<key>FC74E21A2591889F00ACBBFF</key>
|
||||
<dict>
|
||||
<key>primary</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
//
|
||||
// main.swift
|
||||
// ImageCreation
|
||||
@@ -7,5 +8,113 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
print("Hello, World!")
|
||||
let width = 2048
|
||||
let height = width
|
||||
|
||||
let bitmapBytesPerRow = Int(width) * 4
|
||||
let bitmapByteCount = bitmapBytesPerRow * height
|
||||
|
||||
enum Color {
|
||||
case red
|
||||
case green
|
||||
case blue
|
||||
case white
|
||||
}
|
||||
|
||||
func nextColor(_ color: Color) -> Color {
|
||||
switch color {
|
||||
case .red:
|
||||
return .green
|
||||
case .green:
|
||||
return .blue
|
||||
case .blue:
|
||||
return .white
|
||||
case .white:
|
||||
return .red
|
||||
}
|
||||
}
|
||||
|
||||
func redVal(_ currentColor: Color) -> UInt8 {
|
||||
switch currentColor {
|
||||
case .red:
|
||||
return 255
|
||||
case .green:
|
||||
return 0
|
||||
case .blue:
|
||||
return 0
|
||||
case .white:
|
||||
return 255
|
||||
}
|
||||
}
|
||||
|
||||
func greenVal(_ currentColor: Color) -> UInt8 {
|
||||
switch currentColor {
|
||||
case .red:
|
||||
return 0
|
||||
case .green:
|
||||
return 255
|
||||
case .blue:
|
||||
return 0
|
||||
case .white:
|
||||
return 255
|
||||
}
|
||||
}
|
||||
|
||||
func blueVal(_ currentColor: Color) -> UInt8 {
|
||||
switch currentColor {
|
||||
case .red:
|
||||
return 0
|
||||
case .green:
|
||||
return 0
|
||||
case .blue:
|
||||
return 255
|
||||
case .white:
|
||||
return 255
|
||||
}
|
||||
}
|
||||
|
||||
func createPixels() -> [UInt8] {
|
||||
var bitmapData = [UInt8](repeating: 0, count: bitmapByteCount)
|
||||
|
||||
var currentColor = Color.red
|
||||
|
||||
let rectWidth = 256 / 4
|
||||
let rectHeight = Int(Double(rectWidth) * 1.5)
|
||||
|
||||
for i in stride(from: 0, through: bitmapByteCount - 4, by: 4) {
|
||||
bitmapData[i + 0] = redVal(currentColor)
|
||||
bitmapData[i + 1] = greenVal(currentColor)
|
||||
bitmapData[i + 2] = blueVal(currentColor)
|
||||
bitmapData[i + 3] = 255 // alpha
|
||||
|
||||
if i % rectWidth == 0 && (i % (bitmapBytesPerRow * rectHeight)) != 0{
|
||||
currentColor = nextColor(currentColor)
|
||||
}
|
||||
}
|
||||
|
||||
return bitmapData
|
||||
}
|
||||
|
||||
func createBitmap() -> CGContext {
|
||||
|
||||
let colorSpace = CGColorSpaceCreateDeviceRGB()
|
||||
|
||||
var bitmapData = createPixels()
|
||||
let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.premultipliedLast.rawValue)
|
||||
|
||||
let context = CGContext.init(data: &bitmapData, width: width, height: height, bitsPerComponent: 8, bytesPerRow: bitmapBytesPerRow, space: colorSpace, bitmapInfo: bitmapInfo.rawValue)
|
||||
|
||||
return context!
|
||||
}
|
||||
|
||||
func buildImage() {
|
||||
let context = createBitmap()
|
||||
|
||||
let image = context.makeImage()
|
||||
let url = URL(fileURLWithPath: "/Users/jon/Documents/testImage.png")
|
||||
let dest = CGImageDestinationCreateWithURL(url as CFURL, kUTTypePNG, 1, nil)
|
||||
CGImageDestinationAddImage(dest!, image!, nil)
|
||||
CGImageDestinationFinalize(dest!)
|
||||
}
|
||||
|
||||
buildImage()
|
||||
|
||||
Reference in New Issue
Block a user