Determine if file copied into clipboard is an image

后端 未结 3 1944
时光说笑
时光说笑 2021-01-05 08:58

The user right clicks on a file(say on the desktop) and clicks \'copy\' . Now how do I determine in C# if the file copied to the clipboard is an image type ?

Clipbo

3条回答
  •  忘掉有多难
    2021-01-05 09:20

    Get the filename(s) from the clipboard(copying a file to the clip-board just copies its name). Then check if file(s) are image(s).

    There are two ways to do that:

    1. By file extension
    2. Open the file and check for magic-bytes indicating the common image formats

    I prefer the second one because it works even if a file has the wrong extension. On slow media it might be slower though since you need to access the file instead of just working the filename which you got from the clipboard.

提交回复
热议问题