index > Visual C# General > WIA 2.0 Image Deletion

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!

Ken_at_ELM

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




This posting is provided "AS IS" with no warranties, and confers no rights.
Peter Huang - MSFT

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));
}
}
}
}
}

Ken_at_ELM

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 :)




aserbert
aserbert
reply 4

You can use google to search for other answers

 

More Articles

• Exe path from file extension
• How many Lines in RichTextBox
• how to get the selected index of a ChildRows in a dataGrid
• Using ConnectionManagementElement
• Insert OLE Object into Access database
• Use C++ Classes in C#
• using a PointF type object in a Property
• tow ArrayLists values
• VSTO Reference
• Arraylist is populated using a custom class. Listbox Datasource s...
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• Visual Studio 2005 Screensaver
• Please read This!!! Buttons question
• TableAdapter.Update() not updating.
• Program execution "exits" afte
• Usercontrol refresh issue
• Excel Automation Addin Problem
• Communication beetween WebService and Wi
• win. service, config sect. handler, &
• SDK for software license keys?
• Packaging and Deployment Visual C# 2005
• Built a C# console app on XP, gets entry
• Why is my code not retrieving the select
• Replacing Nulls in database table
• modify gridview according to listbox
• Problem with HtmlEncode

Hot Articles

• How to make ToolStrip ComboBox resize wh
• DataGridView control with databound and
• ASCII Replacment and Printing Question...
• Async Sockets
• Static method in Remoting
• Handling popup thru WebBrowser C# 2.0 co
• Alpha value of a bitmap is not saving
• Generate Command Parameters Automaticall
• How to strip control characters from str
• Example of a C# windows Service with an
• Apps for Non-framework users
• Having difficulty running TCP remote cli
• Getting file download event of web browser
• windows processes
• How to read formatted data from an Excel

Recommend Articles

• Matrix C#
• datagrid in vs2005 (website)
• code
• Convert base type
• Resizing
• remove
• Design time problems with custom TreeVie
• Nesting Stuff...
• What values I should use?!
• NUMERIC VALUE IN THE TEXT BOX
• BitConverter
• filling a listview in
• metadata in jpeg-file in Photosop cs
• Using an OLE object without having the TLB
• Invoke a WebService automatically (using