如何在Windows窗体应用程序中保存/检索磁盘中的图像? [英] How to save/retrieve images from disk in windows form application?

查看:102
本文介绍了如何在Windows窗体应用程序中保存/检索磁盘中的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的是,我想在每个故障单生成时保存一个图像(扫描的收据图像)并将其参考(图像名称)存储在mssql数据库中。

What I am trying to do is, I want to save an image ("scanned image of receipt") upon each ticket generation and store its reference(image name) in mssql database.

场景:
用户将通过OpenDialogBox& amp;将单击保存按钮。现在我想让我的应用程序做的是,从源文件复制文件,将其文件名更改为TicketID(TicketID每次都是唯一的,因此图像名称将始终保持唯一)然后保存到特定文件夹(将存储所有图像)并将文件名存储在数据库中。

Scenario: The user will select the image from a source through OpenDialogBox & will click save button. Now what I want my application to do is, copy the file from source, change its file name to TicketID (TicketID will be unique everytime so the image name will always remain unique) and then save to a specific folder (which will store all images) and store the filename in database.

之前我从未在C#中使用过图像,所以我不知道如何实际操作。所以如果有人可以将我链接到教程或其他内容,我真的很感激...

I have never used images in C# before, so I have no idea on how to actually do it. So I would really appreciate if someone could link me to a tutorial or something...

P.S。我正在使用visual studio 2012和MQ SQL Server 2012.

P.S. I am using visual studio 2012 and MQ SQL Server 2012.

推荐答案

您可以执行以下操作

1-在保存事件中,假设您的扫描图像名为image

1- on the save event assuming that your scanned Image called image

var ticketID=Guid.NewGuid().ToString(); // this method will ensure that the name of image will be unique all the time
var path="savingPath" + "/" + ticketID + ".jpg";
// the image path you can save it in the database
image.Save(path);

2-当你想加载图片时

2- when you want to load the image

// retrieve the image path from database
var image=Image.FromFile(path);

希望这能帮到你

这篇关于如何在Windows窗体应用程序中保存/检索磁盘中的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆