我正在创建一个本地文件传输应用。我希望用户拖放一个项目到文件传输应用程序启动文件传输,就像skype或其他信使。
当丢弃一个项目时。已触发drop事件。但是,我不知道从哪里获得项目的细节,如位置,大小等,例如,如果我掉了一张图片。我想阅读上面提到的细节。
注意:我已经启用了Drop event.If的订阅(&S),这有助于
发布于 2010-10-28 15:24:53
你的意思是文件的大小还是图像的像素大小?无论如何,使用以下代码:
private void Window_Drop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop, true))
{
string[] droppedFilePaths = e.Data.GetData(DataFormats.FileDrop, true) as string[];
foreach (var path in droppedFilePaths)
{
string location = null;
int pxWidth = 0, pxHeight = 0;
FileInfo fi = new FileInfo(path);
//fi.Length //File size
//fi.DirectoryName //Directory
using (var fs = fi.OpenRead())
{
try
{
var bmpFrame = BitmapFrame.Create(fs);
var m = bmpFrame.Metadata as BitmapMetadata;
if (m != null)
location = m.Location;
pxWidth = bmpFrame.PixelWidth;
pxHeight = bmpFrame.PixelHeight;
}
catch
{
//File isn't image
}
}
this.fileList.Items.Add(string.Format("({0}x{1}), location: {2}", pxWidth, pxHeight, location));
}
}
}https://stackoverflow.com/questions/4040428
复制相似问题