开发者

WIA performance issues

开发者 https://www.devze.com 2023-02-18 18:47 出处:网络
I\'m using WIA 2.0 in a WPF application to grab images from a camera when a shot is taken (using the wiaEventItemCreated event).

I'm using WIA 2.0 in a WPF application to grab images from a camera when a shot is taken (using the wiaEventItemCreated event).

This works fine except for a performance issue which I can't seem to find a way around. My application stores customer's photos and you can browse the customers, and change which customer you're looking at. When the camera takes a photo, the photo will be stored against the selected customer. The problem arises when I take, say, 10 shots in quick succession with customer A selected then select customer B, and shoot another 10 shots. It seems that WIA waits for each photo to be transferred over before firing the next event, so almost queueing them rather than sending the events directly when the shot is fi开发者_JAVA技巧red? I'm 99% sure that my code isn't causing this behaviour and I'm thinking that it's probably built in behaviour?

Has anyone come across and conquered this? Anyone got any other suggestions that might suit what I'm trying to do? Happy to post more information or code.

I don't have the code at hand, but it's something like this:

// Set up the handler
var manager = new DeviceManagerClass();
manager.RegisterEvent(...wiaEventItemCreated);
manager.OnEvent += ...(DeviceEventHandler);

// the handler, don't quote me on the order of parameters, i'm doing this from memory!
void DeviceEventHandler(string deviceId, string eventId, string itemId) {

    if (eventId == ...wiaEventItemCreated) {
        // Get the currently selected object
        var selectedCustomer = _customerService.GetCurrentCustomer();

        // Put the itemId and selectedCustomerId in a queue to be processed later
        _queue.Enqueue(new ProcessFileMessage { CustomerId = selectedCustomer.Id,
            ItemId = itemId);
    }

}

So the code tries to grab the currently selected customer and the itemId to be processed at a later time. The queue is processed in a BackgroundWorker and does the .Transfer() and .SaveAs(). What I'm seeing though is the DeviceEventHandler taking ages to fire, I would have expected that the event gets fired as soon as a new photo is created.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号