1

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.

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.

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. I am using visual studio 2012 and MQ SQL Server 2012.

Cœur
  • 37,241
  • 25
  • 195
  • 267
NewbieProgrammer
  • 874
  • 2
  • 18
  • 50

2 Answers2

0

If you don't need anything overly fancy in terms of processing the System.Drawing library should meet your needs.

Depending on how you want to architect your app you can pass a directory path directly into the constructor of your Image implementation. e.g.

var myImage = new Bitmap("C:\\somepath\\filename.jpg");

Or you could abstract away the location access you can just pass in a stream (which comes from a byte array, file operation, web request, whatever)

var myImage = new Bitmap(stream);

Saving an image is easy. The image class has a save method

image.Save("C:\\somepath\\filename2.jpg")

http://msdn.microsoft.com/en-us/library/9t4syfhh(v=vs.110).aspx

Piers MacDonald
  • 563
  • 1
  • 5
  • 18
0

you can do the following

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- when you want to load the image

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

hope that this will help you

Monah
  • 6,714
  • 6
  • 22
  • 52