【问题标题】:How To drag images directly from Camera or Smartphone to C# app?如何将图像直接从相机或智能手机拖到 C# 应用程序?
【发布时间】:2015-06-10 14:51:21
【问题描述】:

我找到了一个脚本 (http://www.codeproject.com/Articles/28209/Outlook-Drag-and-Drop-in-C),它可以将图像拖到 c# 应用程序中。 (尤其是来自 Outlook) fileDrop 格式用于将图像从我的硬盘复制(拖动)到 c# 应用程序。 这在图像存储在我的硬盘上时效果很好,但是当我尝试直接从我的存储卡(从相机或智能手机(如三星 S3)中)拖动图像时,它就不起作用了。 这些是我从这些图像中获得的拖动格式:

(0): "Shell IDList Array"
(1): "FileContents"
(2): "FileGroupDescriptorW"
(3): "WPD Storage Attributes"
(4): "Preferred DropEffect"
(5): "WPD NSE"
(6): "WPD NSE PnPDevicePath"
(7): "WPD NSE StoragePUID"
(8): "UsingDefaultDragImage"
(9): "DragImageBits"
(10): "DragContext"
(11): "DragSourceHelperFlags"
(12): "InShellDragLoop"
(13): "IsShowingLayered"
(14): "DragWindow"
(15): "IsComputingImage"
(16): "DataObjectAttributes"
(17): "DisableDragText"
(18): "IsShowingText"
(19): "DropDescription"
(20): "ComputedDragImage"
(21): "Logical Performed DropEffect"
(22): "Performed DropEffect"
(23): "Paste Succeeded"

当我尝试访问“FileGroupDescriptorW”时,我收到了非法访问冲突错误。另外,这里似乎缺少“FileGroupDescriptor”? 谁能帮我解决这个问题?我搜索了这个网站和谷歌,但没有找到任何有用的东西。

【问题讨论】:

    标签: c# image winforms drag sd-card


    【解决方案1】:

    解决方案由 John Schroedl 发布,并隐藏在该主题的许多反应中。

    这两个“修复”解决了我的问题:

    http://www.codeproject.com/Articles/28209/Outlook-Drag-and-Drop-in-C?msg=3535951#xx3535951xx

    旧 C#:

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
    public sealed class FILEGROUPDESCRIPTORA
    {
        public uint cItems;
        public FILEDESCRIPTORA[] fgd;
    }
    
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    public sealed class FILEGROUPDESCRIPTORW
    {
        public uint cItems;
        public FILEDESCRIPTORW[] fgd;
    }
    

    固定 C#:

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
    public sealed class FILEGROUPDESCRIPTORA
    {
        public uint cItems;
        public FILEDESCRIPTORA fgd;
    }
    
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    public sealed class FILEGROUPDESCRIPTORW
    {
        public uint cItems;
        public FILEDESCRIPTORW fgd;
    }
    

    这个修复:http://www.codeproject.com/Articles/28209/Outlook-Drag-and-Drop-in-C?msg=3551197#xx3551197xx

    旧:

    case "FileContents":
        //override the default handling of FileContents which returns the
        //contents of the first file as a memory stream and instead return
        //a array of MemoryStreams containing the data to each file dropped
    
        //get the array of filenames which lets us know how many file contents exist
        string[] fileContentNames = (string[])this.GetData("FileGroupDescriptor");
    

    修复:

    case "FileContents":
        //override the default handling of FileContents which returns the
        //contents of the first file as a memory stream and instead return
        //a array of MemoryStreams containing the data to each file dropped
        //
        // FILECONTENTS requires a companion FILEGROUPDESCRIPTOR to be
        // available so we bail out if we don't find one in the data object.
    
        string fgdFormatName;
    
        if (GetDataPresent("FileGroupDescriptorW"))
            fgdFormatName = "FileGroupDescriptorW";
        else if (GetDataPresent("FileGroupDescriptor"))
            fgdFormatName = "FileGroupDescriptor";
        else
            return null;
    
        //get the array of filenames which lets us know how many file contents exist
        string[] fileContentNames = (string[])this.GetData(fgdFormatName);
    

    万一有人需要...

    【讨论】:

      猜你喜欢
      • 2013-06-28
      • 2011-11-25
      • 1970-01-01
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多