从像素缓冲区到设备上下文的最快方法(Fastest method for blitting from a pixel buffer into a device context)
晚上好,
我在内存缓冲区中有几个32位图像,我希望快速将其“blit”到设备上下文。 速度是一个问题,因为缓冲区将被不断地操纵,需要反复进入DC。
缓冲区的颜色深度为32位,因此它已经是DIB预期的SetDIBits()格式。 然而,这是相当麻烦的,因为在操作之前不能将SetDIBits()的位图目标选择到DC中。 因此,我需要不断更换DC的位图,调用SetDIBits(),将位图交换回DC,然后将DC blit到Window的DC。 对我来说,这似乎是CPU上的大量工作量和Windows API中的过多分支; 对于最佳性能来说太过分了。
我有兴趣使用DirectX,如果它没有强迫我使用设备上下文进行2D操作,或者在显示之前将纹理上传到视频内存,因为图像的内容不断变化。
我的问题很简单(尽管篇幅很长)。 对于我来说,将图像从内存中的像素缓冲区blit到屏幕上的最快方法是什么? 直接访问DC的像素缓冲区会很棒,但我知道这不会发生。
感谢您阅读我的长篇文章。
Good evening,
I have several 32-bit images in memory buffers that I wish to "blit" to a device context, quickly. Speed is an issue here because the buffer will be manipulated constantly and need to be blitted to the DC repeatedly.
The color depth of the buffer is 32-bits, so it is already in the DIB-expected format of SetDIBits(). However, this is rather cumbersome since the bitmap target of SetDIBits() cannot be already selected into the DC prior to the operation. So I will need to constantly swap out the DC's bitmap, call SetDIBits(), swap the bitmap back into the DC, and then blit the DC to the Window's DC. To me, that just seems like a LOT of workload on the CPU and too much branching in the Windows API; way too much for optimal performance.
I would be interested in using DirectX if it didn't force me to use Device Contexts for 2D operations, or uploading textures to video memory before displaying them, because the contents of the image are constantly changing.
My question is simple (despite the long writeup). What would be the fastest way for me to blit an image from a pixel buffer in memory onto the screen? Direct access to the pixel buffer of a DC would be great, but I know that's not going to happen.
Thanks for reading my long writeup.
原文:https://stackoverflow.com/questions/4721078
最满意答案
在类的顶部创建一个可变数组,并且不要放任何“?” 要么 ”!” 消息传出后。
var news: NSMutableArray = []
您还需要在connectionDidFinishLoading方法结束时在表视图上调用reloadData
Create a mutable array at the top of your class, and don't put any "?" or "!" after news.
var news: NSMutableArray = []
You also need to call reloadData on your table view at the end of the connectionDidFinishLoading method
相关问答
更多-
在Swift中编码和解码字符串数组的JSON字典(Encode and decode JSON dictionaries of arrays of strings in Swift)[2024-04-29]
1-您的字典已经输入,它是Dictionary> ,因此您只需使用NSJSONSerialization来创建JSON数据: do { let jsonData = try NSJSONSerialization.dataWithJSONObject(arithmeticalDict, options: NSJSONWritingOptions.PrettyPrinted) // now you can export "jsonData" to ... -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
你需要给字典类型: var myNewDictArray: [Dictionary
] = [] 要么 var myNewDictArray = [Dictionary ]() 编辑 :您也可以使用较短的语法: var myNewDictArray: [[String:Int]] = [] 要么 var myNewDictArray = [[String:Int]]() You need to give types to the dictionarie ... -
Swift - 在JSON文件中读取(Swift--Reading in JSON file)[2022-05-06]
AnyObject确实不是可订阅的(你试图下载一个类型为AnyObject的变量?带有["feed"] )。 您还应该尽可能避免使用NSArray和NSDictionary等Cocoa容器类型。 这是一个如何从条目数组的名称数组中获取标签的示例: import Foundation func labels(feedDictionary:[String:AnyObject]) -> [String] { guard let entries = feedDictionary["entry"] as? ... -
在类的顶部创建一个可变数组,并且不要放任何“?” 要么 ”!” 消息传出后。 var news: NSMutableArray = [] 您还需要在connectionDidFinishLoading方法结束时在表视图上调用reloadData Create a mutable array at the top of your class, and don't put any "?" or "!" after news. var news: NSMutableArray = [] You also ne ...
-
[ Swift 4 ]你可以使用Codable模型来轻松管理你的tableviewcell。 请参阅下面的代码并在操场上运行,您会明白我已经创建了易于循环和管理的模型对象: var json = """ [ { "userId": 2, "userName": "jhonsmith", "password": "1234", "userTypeId": 3, "firstName": "jhon", "l ...
-
这有点矫枉过正,但你可以将json转换为[String:[String:[[String]]]] let json = try? JSONSerialization.jsonObject(...) as? [String:[String:[[String]]]] 否则,例如,如果字典包含嵌套字典以外的元素,则只需将顶级字典强制转换为[String:Any]并单独转换嵌套元素。 if let json = try? JSONSerialization.jsonObject(...) as? [String: ...
-
您无法使用数组初始化元组值,因为它们是两种不同的类型。 元组是一种独特的类型,必须包含您为其指定的元素数量。 因此,如果您将字典声明为存储2元素元组,则必须使用两个元素存储其中的内容。 因此,您可以使用以下内容初始化字典: var mydict: [String: (key1: String, key2: String)] = ["dict_key1" : (key1: "", key2: "")] 但是,如果你想在字典中存储一个数组,我建议你只需输入字典: var mydict: [String : [ ...
-
Json数据分组,包含Swift 4中的字典数组(Grouping from Json data, which contain array of dictionaries in Swift 4)[2021-12-14]
的init(分组:由:) 您应该返回关闭中的名称键值。 let arr = [ [ "name": "Abc", "number": 123, "marks": 78 ], [ "name": "xyz", "number": 456, "marks": 50 ], [ "name": "Abc", "number": 789, "marks": 78 ] ] let dict = Dictionary(grouping: arr) { $0["name"] as! String } print(di ... -
array.forEach({ object in dict[object.id] = object }) 或更短: array.forEach({ dict[$0.id] = $0 }) array.forEach({ object in dict[object.id] = object }) or shorter: array.forEach({ dict[$0.id] = $0 })