Post

Replies

Boosts

Views

Activity

RealityKit MeshResource generated from SwiftUI shape
On Scenekit, using SCNShapewe can create SCN geometry from SwiftUI 2D shapes/beziers:https://developer.apple.com/documentation/scenekit/scnshape Is there an equivalent in RealityKit? Could we use the generate(from:) for that?https://developer.apple.com/documentation/realitykit/meshresource/3768520-generate https://developer.apple.com/documentation/realitykit/meshresource/3768520-generate
2
0
1.2k
Mar ’22
CoreGraphics resizing function from iOS (UIImage) to MacOS (NSImage)
Goal: Rewrite CoreGraphics resizing function from iOS (UIImage) to MacOS (NSImage) Problem: Getting error on this line of code: let bytesPerPixel = cgImage.bitsPerPixel / bitsPerComponent Error: Value of type '(UnsafeMutablePointer?, NSGraphicsContext?, [NSImageRep.HintKey : Any]?) - CGImage?' (aka '(OptionalUnsafeMutablePointer, Optional, OptionalDictionaryNSImageRep.HintKey, Any) - Optional') has no member 'bitsPerPixel' Question: how can I replace "cgImage.bitsPerPixel" for something that works with NSImage? iOS: UIImage extension UIImage { // Resizeing using CoreGraphics func resize(to size:CGSize) - UIImage? { let cgImage = self.cgImage! let destWidth = Int(size.width) let destHeight = Int(size.height) let bitsPerComponent = 8 let bytesPerPixel = cgImage.bitsPerPixel / bitsPerComponent let destBytesPerRow = destWidth * bytesPerPixel let context = CGContext(data: nil, width: destWidth, height: destHeight, bitsPerComponent: bitsPerComponent, bytesPerRow: destBytesPerRow, space: cgImage.colorSpace!, bitmapInfo: cgImage.bitmapInfo.rawValue)! context.interpolationQuality = .high context.draw(cgImage, in: CGRect(origin: CGPoint.zero, size: size)) return context.makeImage().flatMap { UIImage(cgImage: $0) } } } MacOS: NSImage extension NSImage { // Resizeing using CoreGraphics func resize(to size:CGSize) - NSImage? { let cgImage = self.cgImage let destWidth = Int(size.width) let destHeight = Int(size.height) let bitsPerComponent = 8 let bytesPerPixel = cgImage.bitsPerPixel / bitsPerComponent let destBytesPerRow = destWidth * bytesPerPixel let context = CGContext(data: nil, width: destWidth, height: destHeight, bitsPerComponent: bitsPerComponent, bytesPerRow: destBytesPerRow, space: cgImage.colorSpace!, bitmapInfo: cgImage.bitmapInfo.rawValue)! context.interpolationQuality = .high context.draw(cgImage, in: CGRect(origin: CGPoint.zero, size: size)) return context.makeImage().flatMap { NSImage(cgImage: $0) } } }
1
0
2.2k
Apr ’21
SwiftUI: export multiple images with .fileExporter
Goal: export multiple images with .fileExporter What I did: Code 1 bellow works fine for MacOS, export multiple files. Problem: When I replace for UIImage, it exports only 1 image Question: How can I export multiple images using .fileExporter in iOS? Code 1 bellow works fine for MacOS, export multiple files. import SwiftUI class AppContext: ObservableObject {     @Published var fileSaveDialogShown = false } @main struct FocalApp: App {   @StateObject var appContext = AppContext()   var body: some Scene {     WindowGroup {       ContentView()         .environmentObject(self.appContext)         .fileExporter(           isPresented: $appContext.fileSaveDialogShown,           documents: [             ImageDocument(image: NSImage(named: "1")),             ImageDocument(image: NSImage(named: "2"))           ],           contentType: .jpeg // Match this to your representation in ImageDocument         ) { url in           print("Saved to", url) // [URL]         }     }   } } import SwiftUI import UniformTypeIdentifiers struct ImageDocument: FileDocument {   static var readableContentTypes: [UTType] { [.jpeg, .png, .tiff] }   var image: NSImage   init(image: NSImage?) {     self.image = image ?? NSImage()   }   init(configuration: ReadConfiguration) throws {     guard let data = configuration.file.regularFileContents,           let image = NSImage(data: data)     else {       throw CocoaError(.fileReadCorruptFile)     }     self.image = image   }   func fileWrapper(configuration: WriteConfiguration) throws - FileWrapper {     // You can replace tiff representation with what you want to export     return FileWrapper(regularFileWithContents: image.tiffRepresentation!)   } } struct ContentView: View {          @EnvironmentObject var appContext: AppContext          var body: some View {         VStack {             Button(action: {                 appContext.fileSaveDialogShown.toggle()             }, label: {                 Text("Button")             })         }         .frame(width: 200, height: 200)     } } When I replace for UIImage, it exports only 1 image import SwiftUI class AppContext: ObservableObject {     @Published var fileSaveDialogShown = false } @main struct FocalApp: App {   @StateObject var appContext = AppContext()   var body: some Scene {     WindowGroup {       ContentView()         .environmentObject(self.appContext)         .fileExporter(           isPresented: $appContext.fileSaveDialogShown,           documents: [             ImageDocument(image: UIImage(named: "1")),             ImageDocument(image: UIImage(named: "2"))           ],           contentType: .jpeg // Match this to your representation in ImageDocument         ) { url in           print("Saved to", url) // [URL]         }     }   } } import SwiftUI import UniformTypeIdentifiers struct ImageDocument: FileDocument {   static var readableContentTypes: [UTType] { [.jpeg, .png, .tiff] }   var image: UIImage   init(image: UIImage?) {     self.image = image ?? UIImage()   }   init(configuration: ReadConfiguration) throws {     guard let data = configuration.file.regularFileContents,           let image = UIImage(data: data)     else {       throw CocoaError(.fileReadCorruptFile)     }     self.image = image   }   func fileWrapper(configuration: WriteConfiguration) throws - FileWrapper {     // You can replace tiff representation with what you want to export     return FileWrapper(regularFileWithContents: image.jpegData(compressionQuality: 1)!)   } } struct ContentView: View {          @EnvironmentObject var appContext: AppContext          var body: some View {         VStack {             Button(action: {                 appContext.fileSaveDialogShown.toggle()             }, label: {                 Text("Button")             })         }         .frame(width: 200, height: 200)     } }
0
0
1.2k
Apr ’21
WWDC20 session 10012: Discover Ray Tracing with Metal.
I am trying to build scover "Ray Tracing with Metal" on iMac Pro 2017, but got this error: 2020-06-25 14:29:35.233058+0200 MTLRaytracingSample-macOS[3602:145531] Failed to set (contentViewController) user defined inspected property on (NSWindow): Ray tracing isn't supported on this device Xcode 12 Big Sur 11.0 Beta (20A4299v) iMac Pro 2017 3,2 GHz 8-Core Intel Xeon W 32 GB 2666 MHz DDR4 Radeon Pro Vega 56 8 GB What is the required hardware configuration?
7
0
2.5k
Jun ’20
Shape Edit App - "untitled" screen
I am trying to build the App example on wwdc20-10037, but get only a "untitled" screen, followed by this error: 2020-06-25 12:26:28.639346+0200 ShapeEdit[2093:54298] [Type Declaration Issues] Type "com.example.ShapeEdit.shapes" was expected to be declared and exported in the Info.plist of ShapeEdit.app, but it was not found. How can I properly build it? Edit Shape Code - https://developer.apple.com/forums/content/attachment/759f7b02-e8a7-495b-a4b5-ea41cde9b948
0
0
528
Jun ’20