在 asp.net 中将上传的文件转换为位图图像
我有一个 FileUpload
框和 按钮
。在我的场景中,要上传的文件是图像文件。我想将这些图像文件转换为位图并将它们临时存储在缓冲区中。
我有一个函数,它接受两个位图输入并告诉我们这两个文件是否匹配。
其中一个文件将来自 ButtonClick
事件上的 FileUpload
控件,另一个位图将从数据库读取。
谁能告诉我如何将这些文件转换为位图并将这两个位图对象传递给函数。
I have a FileUpload
box and button
. In my scenario the files that are going to be uploaded are image files. I want to convert these image files into bitmaps and store them temporarily in a buffer.
I have a function which takes two bitmap inputs and tells us whether the two files match or not.
One of the file will come from the FileUpload
control on ButtonClick
event and the other bitmap will be read from Database.
Can anyone tell me as to how do I convert these files to bitmaps and pass both the bitmap objects to the function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以按如下方式获取上传图像的位图:
然后获取存储的副本(希望将其存储为字节数组,并且您有一个 ID 来获取它),然后将其转换为位图,如下所示将
两个位图手(bmpPostedImage和bmpStoredImage),然后可以调用该函数进行比较。首先,您可以从 http://www.dreamincode.net/code/snippet2859 尝试此功能。 htm 看看效果如何。可能有更有效的函数可以进行比较,尝试谷歌搜索将是一个很好的尝试。
编辑
下面找到从数据库检索图像的代码,假设我在下面的注释中放入:
然后将 ImageService.GetImageData(imageID) 更改为 GetImageData(imageID);
另请注意,此处未解决错误处理问题,因此可能必须将其纳入最终代码中。
You can get a bitmap of your uploaded image as follows:
You then get the stored copy (which hopefully is stored as a byte array and you have an ID to get it), and then convert it to bitmap as follows
With the two bitmaps in hand (bmpPostedImage and bmpStoredImage), you can then call the function to do the comparison. For a start you can try this function from http://www.dreamincode.net/code/snippet2859.htm and see how it it goes. there may be more efficient functions out there to do the comparison, trying out a google search for that will be a goo thing to try.
EDIT
Find below the code to retrieve image from the database with the assumptions I put in the comment below:
and then change ImageService.GetImageData(imageID) to GetImageData(imageID);
Note also, that error handling is not addressed here, so might have to factor that into your final code.