WIA 2.0 Image Deletion

I need a programmatic way to delete images from a digital camera using WIA 2.0 Automation Layer and C#. I am referencing Interop.WIALib.dll in my project. I can find references to a CommandId for DeleteAllItems for use with ExecuteCommand method in online documentation http://msdn.microsoft.com/library/en-us/wiaaut/wia/wiax/refwiaaut/consts/commandid.asp but there appears to be no Device class available to me inside C# (only DeviceInfo, and it lacks ExecuteCommand). And I can find reference to DeleteItem method in older WIA 1.0 IWiaItem interface http://msdn.microsoft.com/library/en-us/wia/wia/refwia/ifaces/iwiaitem/deleteitem.asp but again not available from WIALib in c#. I have also tried going through Interop.WIA.dll which has more classes and Interfaces exposed, but still not able to find a way to delete items.

Any ideas, samples or direction would be much appreciated!



Answer this question

WIA 2.0 Image Deletion

  • Muhsin Zahid Uğur

    Peter,

    Thank you for your reply. I figured out how to delete images from my digital camera, plus worked out some details of gathering information from it. I'm including a simple console app below that includes the delete code. This http://www.codeproject.com/dotnet/wiascriptingdotnet.asp is also an excellent starting point, though it includes no example of how to delete an image.

    using System;
    using WIA;

    namespace WiaCameraTest
    {

    class Class1
    {
    [STAThread]
    static void Main(string[] args)
    {
    WiaCameraAccess();
    Console.Write("ENTER to exit: ");
    Console.ReadLine();
    }

    public static void WiaCameraAccess()
    {

    // Create a device manager instance
    WIA.DeviceManagerClass devMgr = new WIA.DeviceManagerClass();

    // Iterate through the device info collection. Assume the first device in the
    // collection is the the digital camera we're after. Display all of its properties,
    // connect to it, then exit the loop
    Device cameraDevice = null;
    foreach (DeviceInfo info in devMgr.DeviceInfos)
    {
    foreach(IProperty p in info.Properties)
    {
    Console.WriteLine(String.Format("PropertyID: {0} Name: {1} ",p.PropertyID,p.Name));
    }
    cameraDevice = info.Connect();
    break;
    }

    // Display the list of commands available on the camera. Don't be surprised if the only
    // available command is "Synchronize"
    foreach(WIA.DeviceCommand c in cameraDevice.Commands)
    {
    Console.WriteLine(String.Format("DeviceCommand Command: '{0}' ID: {1} Desc: {2}",
    c.Name, c.CommandID, c.Description));
    }

    // Display list of properties exposed by the camera.
    foreach(WIA.Property p in cameraDevice.Properties)
    {
    Console.WriteLine(String.Format("PropertyID: {0} Name: {1} ",p.PropertyID,p.Name));
    }

    // Delete an image from the camera. Assume we want to delete the second image.
    // Note that camera images are indexed 1, 2, 3, ... (i.e. not zero-based)
    // Note that the Items collection of the camera device is assumed to be the collection of
    // images (warning: this relationship can apparently vary by camera make and model)
    int removeItemIdx = 2;
    cameraDevice.Items.Remove(removeItemIdx); // remove the item from the device Items collection
    cameraDevice.ExecuteCommand(WIA.CommandID.wiaCommandSynchronize); // synchronize camera to Items collection

    // Display commands available per remaining image items
    foreach(WIA.Item item in cameraDevice.Items)
    {
    string itemName = item.ItemID;
    int iCount = item.Commands.Count;
    int j = iCount;
    foreach(WIA.DeviceCommand c in item.Commands)
    {
    Console.WriteLine(String.Format("Device '{3}' ItemCommand: '{0}' ID: {1} Desc: {2}",
    c.Name, c.CommandID, c.Description, itemName));
    }
    }
    }
    }
    }


  • Gary Spence

    you should read the readme file of wia:

    Getting Started
    ---------------

    To install the Windows Image Acquisition Library v2.0,
    copy the contents of this compressed file to a directory on your hard drive.

    Copy the wiaaut.chm and wiaaut.chi files to your Help directory (usually located at C:\Windows\Help)

    Copy the wiaaut.dll file to your System32 directory (usually located at C:\Windows\System32)

    From a Command Prompt in the System32 directory run the following command:

    RegSvr32 WIAAut.dll

  • Lechal

    Hi,

    Based on my understanding, you can not find the Device class in the Interop.WIA.dll assembly which have the method ExecuteCommand.

    If I misunderstood, please feel free let me know.

    Based on my test, I can not reproduce the problem. Here is my reproduce steps.
    1. Add a com reference to Microsoft Windows Image Acquisition Library v2.0
    2. The IDE will generate the assembly Interop.WIA.dll
    3. Press Ctrl+Atl+J to open the Object Browser
    4. Expand the Interop.WIA and then expand the WIA namespace
    5. We will find a Device interface and its implement class DeviceClass
    6. We will find the Method ExecuteCommand
    public virtual WIA.Item ExecuteCommand(string CommandID)
    Member of WIA.DeviceClass

    If you still have any concern, please feel free to post here.

    Best regards,
    Peter Huang



  • cues7a

    Hi...

    I am trying to also delete a picture from a camera and am trying to use the Interop.WIA and am getting this error:

    An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in WiaEasyImage.exe

    Additional information: COM object with CLSID {E1C5D730-7E97-4D8A-9E42-BBAE87C2059F} is either not valid or not registered.

    I get this with this piece of code:

    DeviceManagerClass devMgr = new WIA.DeviceManagerClass();

    Any thoughts would be great, this hasn't been going so well.

    Thanks in advance :)



  • WIA 2.0 Image Deletion