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