0
我正在運行便攜式設備API以自動從連接的智能手機獲取照片。我擁有一切正確的傳輸。我使用的代碼是標準DownloadFile()函數:C#:WPD - 下載帶有meta標籤的圖片
public PortableDownloadInfo DownloadFile(PortableDeviceFile file, string saveToPath)
{
IPortableDeviceContent content;
_device.Content(out content);
IPortableDeviceResources resources;
content.Transfer(out resources);
PortableDeviceApiLib.IStream wpdStream;
uint optimalTransferSize = 0;
var property = new _tagpropertykey
{
fmtid = new Guid(0xE81E79BE, 0x34F0, 0x41BF, 0xB5, 0x3F, 0xF1, 0xA0, 0x6A, 0xE8, 0x78, 0x42),
pid = 0
};
resources.GetStream(file.Id, ref property, 0, ref optimalTransferSize, out wpdStream);
System.Runtime.InteropServices.ComTypes.IStream sourceStream =
// ReSharper disable once SuspiciousTypeConversion.Global
(System.Runtime.InteropServices.ComTypes.IStream)wpdStream;
var filename = Path.GetFileName(file.Name);
if (string.IsNullOrEmpty(filename))
return null;
FileStream targetStream = new FileStream(Path.Combine(saveToPath, filename),
FileMode.Create, FileAccess.Write);
try
{
unsafe
{
var buffer = new byte[1024];
int bytesRead;
do
{
sourceStream.Read(buffer, 1024, new IntPtr(&bytesRead));
targetStream.Write(buffer, 0, 1024);
} while (bytesRead > 0);
targetStream.Close();
}
}
finally
{
Marshal.ReleaseComObject(sourceStream);
Marshal.ReleaseComObject(wpdStream);
}
return pdi;
}
}
有兩個問題與此標準代碼: 1) - 當圖像保存到Windows機器,沒有EXIF信息。這個信息是我需要的。我如何保存它? 2)保存的文件非常臃腫。例如,源jpeg是1,045,807字節,而下載的文件是3,942,840字節!它與所有其他文件類似。我會認爲不安全{}部分中的某些部分會將其輸出爲字節?有沒有更好的方式來傳輸數據? (一種安全的方式?)
你不能關閉你的問題嗎? –