可以将图像从在Windows编程方式使用的CreateFile的iPhone阅读?(Can imag

2019-07-29 21:31发布

当iPhone连接到一个计算机的Win7,该图像可以使用资源管理器(和我的应用程序的打开文件对话框)来查看。 但是,文件位置不包含驱动器号。

例如Computer\Apple iPhone\Internal Storage\DCIM\800AAAAA\IMG_0008.JPG而不是E:\DCIM\800AAAAA\IMG_0008.JPG这是常见sdcards,USB驱动器等...

我已经使用CreateFileW从一个iPhone读取的图像尝试,但它失败“(错误代码:3),该系统找不到指定的路径” 我也尝试使用Chrome访问他们失败了。

有什么建议?

Answer 1:

该文件夹其实就是所谓的“虚拟文件夹”,并没有在文件系统上的完整路径。 您将需要使用从打开的对话框返回的外壳项目获得该文件的内容,而不是使用的CreateFile。

这些数据应该可以访问,但你应该遵循的指示的MSDN文档 。 我敢肯定,有可能是更好的例子(因为这只是给指导)。

编辑粗略的过程是得到IFileOpenDialog中的IShellItem,然后绑定到数据流,然后读取流(假设仅读出) -请记住,这个代码是非常没有错误处理或检查或安全:

if (pitem->GetDisplayName(SIGDN_NORMALDISPLAY, &destName) == S_OK) {
    std::cout << destName << std::endl;
    CoTaskMemFree(destName);
}
IStream *pistream;
if (pitem->BindToHandler(0, BHID_Stream, IID_PPV_ARGS(&pistream)) == S_OK) {
    char input[1024];
    long to_read = 1024;
    unsigned long read;
    while (S_OK == pistream->Read(input, to_read, &read)) {
       std::cout << input << std::endl;
    }
    pistream->Release();
}
pitem->Release();


Answer 2:

大多数情况下这种设备插入到Windows资源管理器作为外壳空间扩展,而不是像一个USB记忆棒的盘符。 最喜欢的CopyFile(..),使用FindFirst()或GetFileInfo(..)正常的文件的命令不能在这样的外壳命名空间扩展直接使用。 只有CopyHere(..)工作。 我需要很长一段时间来弄清楚如何与vb.net程序枚举文件上的数码相机,现在也是在Android设备上和我的照片复制到我的Windows PC:

Public Const MyComputer As Integer = &H11&

Sub EnumMyComputer()
  Dim oItem As Object
  Dim res As Integer

  For Each oItem In DirectCast(CreateObject("Shell.Application").Namespace(MyComputer).Items, System.Collections.IEnumerable)
    Debug.Print(oItem.Type.ToString)
    if oItem.Type.ToString="Tragbares Medienwiedergabegerät" then '<- check, adopt!
      res = EnumNamespaceItems(oItem, "", oItem.Name.ToString, 0)
    End If
  Next oItem
End Sub

Function EnumNamespaceItems(oItem As Object, SrcCPath As String, SrcDPath As String, folderLevel As Integer) As Integer
  Dim y As Object
  Dim tempFullFileName As String

  Debug.Print(StrDup(folderLevel, "  ") & "\" & oItem.Name.ToString & "  (" & oItem.Path.ToString & ")")
  For Each y In DirectCast(oItem.GetFolder.items, System.Collections.IEnumerable)
    'Debug.Print(StrDup(folderLevel, "  ") & SrcDPath & y.Name.ToString)
    If y.IsFolder = True Then
      Dim n1 As Integer
      n1 = EnumNamespaceItems(y, SrcCPath & y.Path.ToString & "\", SrcDPath & y.Name.ToString & "\", 1 + folderLevel)
      If n1 < 0 Then 'failure: Cancel
        EnumNamespaceItems = n1
        Exit Function
      End If
    Else 'it's a file:
      Debug.Print(StrDup(folderLevel, "  ") & " " & y.Name.ToString)
      tempFullFileName = System.IO.Path.GetTempPath() & y.Name.ToString
      ' CopyFile is not possible here if SrcCPath is like "::{…}…":
      ' My.Computer.FileSystem.CopyFile(SrcCPath & y.Name.ToString , fFile.FullName)
      Dim suc As Integer = CopyHereFileWait(y, My.Computer.FileSystem.SpecialDirectories.Temp)
      If suc >= 0 Then 'now we can do things like this:
        Dim MyFileInfo As System.IO.FileInfo = My.Computer.FileSystem.GetFileInfo(tempFullFileName)
        Dim fileDate As Date = MyFileInfo.LastWriteTime
      End If 'suc
    End If 'else y.IsFolder
  Next y
  EnumNamespaceItems = 0
End Function


Function CopyHereFileWait(sourceNamespaceObject As Object, targetFolder As String) As Integer
  Dim fsMyStream As System.IO.FileStream
  Dim n1 As Integer
  Dim taregetFullFileName As String

  n1 = Len(targetFolder)
  If Mid(targetFolder, n1, 1) = "\" Then
    targetFolder = Microsoft.VisualBasic.Left(targetFolder, n1 - 1)
  End If
  taregetFullFileName = targetFolder & "\" & sourceNamespaceObject.Name.ToString
  Dim oNsTargetFolder As Object
  oNsTargetFolder = CreateObject("Shell.Application").Namespace(CStr(targetFolder))
  oNsTargetFolder.copyHere(sourceNamespaceObject)
  'returns immediately and is doing the work in the background
  n1 = 0
  Do
    Threading.Thread.Sleep(50) 'ms
    Try
      fsMyStream = System.IO.File.Open(taregetFullFileName, IO.FileMode.Open, IO.FileAccess.ReadWrite)
      fsMyStream.Close()
      CopyHereFileWait = n1
      Exit Function
    Catch ex As Exception
      Debug.Print(ex.Message)
    End Try
    n1 = n1 + 1
  Loop While n1 < 400 'timeout 400*50ms = 20s
  CopyHereFileWait = -n1
End Function

您可以添加,以检查文件夹与y.Name.ToString =“DCIM”(上folderLevel = 1)和文件以“.jpg”。



文章来源: Can images be read from an iPhone programmatically using CreateFile in Windows?