簡體   English   中英

如何將圖像直接從相機或智能手機拖動到C#應用程序?

[英]How To drag images directly from Camera or Smartphone to C# app?

我找到了一個腳本( http://www.codeproject.com/Articles/28209/Outlook-Drag-and-Drop-in-C ),該腳本可以將圖像拖到ac#應用程序。 (尤其是從Outlook中)fileDrop格式用於將圖像從我的硬盤復制(拖動)到c#應用程序。 當圖像存儲在硬盤上時,此方法效果很好,但是當我嘗試直接從存儲卡(從相機或智能手機(如Samsung 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”似乎在這里丟失了嗎? 誰能幫我解決這個問題? 我搜索了該網站和Google,但沒有發現任何有用的信息。

該解決方案由John Schroedl發布,並被隱藏在有關Topic的許多反應中。

這兩個“修復”解決了我的問題:

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

萬一有人需要...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM