img_Init(Int32(img_INIT_PNG.rawValue))let screenShot = SDL_CreateRGBSurface(0,640,480,32,0)SDL_Setrendertarget(renderer,texture)SDL_RenderReadPixels(renderer,nil,Uint32(SDL_PIXELFORMAT_ARGB8888),screenShot?.pointee.pixels,(screenShot?.pointee.pitch)!)let documentsPath = NSSearchPathForDirectorIEsInDomains(.documentDirectory,.userDomainMask,true)[0] as Stringimg_SavePNG(screenShot,"\(documentsPath)/image.png")SDL_FreeSurface(screenShot)
但是没有保存image.png.如果有人可以带领或帮助我.谢谢!
附加代码,保存的图像只是黑色
img_Init(Int32(img_INIT_PNG.rawValue))let screenShot = SDL_CreateRGBSurface(Uint32(SDL_SWSURFACE),0)// SDL_Setrendertarget(renderer,(screenShot?.pointee.pitch)!)// Save to documents directorylet fileManager = fileManager.defaultdo { let documentDirectory = try fileManager.url(for: .documentDirectory,in: .userDomainMask,appropriateFor: nil,create: true) let fileUrl = documentDirectory.appendingPathComponent("imageLol.png") if !fileManager.fileExists(atPath: fileUrl.path) { print("file NO exists") // Create file at path let data = Data() let createfile = fileManager.createfile(atPath: fileUrl.path,contents: data,attributes: nil) if createfile { print("Create file success") } else { print("Create file Failed") } } else { print("file exists") } let result = img_SavePNG(screenShot,fileUrl.path) print("result = \(result)") // After saving screenshot let image = UIImage(contentsOffile: fileUrl.path) let imageData = UIImagePNGRepresentation(image!) print("image length = \(String(describing: imageData?.count))") UIImageWritetoSavedPhotosAlbum(image!,nil) SDL_FreeSurface(screenShot)} catch { print("Error docs = \(error)")}解决方法 它不会在屏幕截图中显示视频帧.只有在播放视频时才会显示黑屏图像.
请尝试截取任何应用程序屏幕的屏幕截图,看看它是否正常工作.
总结以上是内存溢出为你收集整理的SDL在iOS上保存截图全部内容,希望文章能够帮你解决SDL在iOS上保存截图所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)