LEADTOOLS Support
General
General Questions
Re: Saving and restoring image to SQL Server...
This topic and its replies were posted before the current version of LEADTOOLS was released and may no longer be applicable.
#1
Posted
:
Thursday, November 15, 2007 7:31:51 AM(UTC)
Groups: Registered
Posts: 9
Prior to utilising Leadtools I used a standard picturebox control. What my application does is capture the screen graphics in the following:
Private MyBitMap As Bitmap
I then have converted to Leadtools rasterimage type which works fine and display the image fine in the rasterviewer (code below):
Dim myCovertImg As Leadtools.RasterImage = New Leadtools.RasterImage(MyBitMap)
Me.rasterViewer.Image = myCovertImg
My problem now comes when trying to save the image. The field within the database is of image type. Before I convert the image in the picturebox into a system.io.memorystream and saved this to the database as follows:
'Read image into byte
' save image to stream...
Dim clsStream1 As New System.IO.MemoryStream
' Todo
Me.picBox.Image.Save(clsStream1, System.Drawing.Imaging.ImageFormat.Jpeg)
' read bytes from stream...
Dim emptyByte As Byte = Nothing
Dim b As Byte() = DirectCast(Array.CreateInstance(GetType(Byte), clsStream1.Length), Byte())
clsStream1.Position = 0
clsStream1.Read(b, 0, b.Length)
clsStream1.Close()
Dim myInsertCmd As New OleDb.OleDbCommand("spInsertComm")
myInsertCmd.CommandType = CommandType.StoredProcedure
OleDb.OleDbParameter("@commImage", OleDb.OleDbType.LongVarBinary, b.Length, ParameterDirection.Input, False, emptyByte, emptyByte, "commImage", DataRowVersion.Current, b))
However I am now strugling to save the same using rasterImage control. Could you please give an example code of how to do this?
Also I am adding annotation to the image, using Leadtools functionality, what is the best way for me to save not only the image but also the annotation to the database? Are you able to supply a code example?
Sorry for asking for code examples but I have a deadline in the next day and I have been trying to sort this out for a while now.
Thank you in advance
Simon
#2
Posted
:
Friday, November 16, 2007 6:31:28 AM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 764
I don't know the full requirements, so this may not be an option for you...
Why are you using a System.Drawing.Image? If you are saving the Image as a JPEG to a MemoryStream and putting that into the database, why not just use the RasterCodecs.Save method? You can load and save RasterImage objects from MemoryStreams, so you might not need the System.Drawing.Image object at all unless you need it for something else in your application.
Whether or not you can eliminate using the System.Drawing.Image, I think you'll need to save the RasterImage into a MemoryStream anyways. That way you can then save the MemoryStream into your database.
There are a couple of things to consider in regards to the annotations. If you want to be able to modify the annotations at another time, you'll have to save the annotations either to a separate file or into the actual image. You can only save the annotations into a TIF, so you will likely need to do a separate file since you're saving them as JPEGs. Use the AnnCodecs.Save function for both of these options. Similarly, you can save them to file, or to a MemoryStream. Therefore you'll need to add a new property in the database to go with each image for the annotation file. When you load the image, you'll need to load the annotations afterwards with AnnCodecs.Load.
If you don't want to edit the annotations, then just Realize the annotations to the bitmap and then you won't need to worry about loading/saving annotations.
The help file has examples of how to use all of these functions.
#3
Posted
:
Friday, November 16, 2007 6:54:40 AM(UTC)
Groups: Registered
Posts: 9
Thank you for your response, I understand the annotation bit, however are you able to give me an example of how to save the image from a rasterImageViewer to a stream and then to the database. The examples that I find in the help file are all reading from a file not from the rasterImageViewer control it self.
The code that I posted previously was how I was saving the image within a pictureBox, hence the use of system.io.memorystream.
Any help would really be appreshaited
Thatnks in advance
Simon
#4
Posted
:
Monday, November 19, 2007 4:16:26 AM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 764
I don't have any specific examples of this. Using a separate RasterImage object and using the RasterImageViewer isn't going to be any problem. The RasterImageViewer.Image property IS a RasterImage, so wherever you see RasterImage, just replace it with [RasterImageViewer].Image where [RasterImageViewer] is the name of your viewer. We don't have any examples of saving the memoryStream to the database because that has nothing to do with LEADTOOLS. We give you the ability to save a file to a System.IO.Stream object and after that is' all Microsoft programming and interfacing with your database.
LEADTOOLS Support
General
General Questions
Re: Saving and restoring image to SQL Server...
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.