|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Bitmap and MemoryStreamtoo big...but it shouldn't be. Here's what I got: Dim bmpDocument As Bitmap = Bitmap.FromHbitmap(hDibCopy) ' get image from scanner Dim bmpResize As New Bitmap(bmpDocument, 680, 880) mySQLManager.InsertDBImage(elmImageIndex, intNextDocument, bmpResize) Public Function InsertDBImage(ByVal ImageElement As XmlElement, _ ByVal DocumentID As Integer, _ ByVal tImage As System.Drawing.Bitmap) Dim st As New System.IO.MemoryStream tImage.Save(st, System.Drawing.Imaging.ImageFormat.Bmp) Dim bytBLOBData(st.Length - 1) As Byte 'st.Position = 0 st.Seek(0, IO.SeekOrigin.Begin) st.Read(bytBLOBData, 0, st.Length) MsgBox(bytBLOBData.Length) ' this displays 2393654...way too big Now if I save the image to file and then use that file (as opposed to the hDibCopy) the lenght is 87467...which is small enough to insert into my database. Am I doing something wrong? Why is it so big? Any help is greatly appreciated. -bruce duncan Hi,
You have to store the image in binary format. Storeimage converts image to binary format. ConvertToBitmap converts it back. Note the offset for the northwind database is 78 my storeimage function has a offset of 0. Private Function StoreImage(ByVal bm As Bitmap) As Object Dim ms As New MemoryStream Try bm.Save(ms, Imaging.ImageFormat.Jpeg) Return ms.GetBuffer Catch Return Convert.DBNull End Try End Function Private Function ConvertToBitmap(ByVal data() As Byte, ByVal offset As Integer) As Bitmap Dim ms As New System.IO.MemoryStream Dim bm As Bitmap ms = New MemoryStream ms.Write(data, offset, data.Length - offset) bm = New Bitmap(ms) Return bm End Function Ken ---------------------- "Bruce D" <brucexwxdunc***@hotmail.com> wrote in message I'm having a problem saving my bitmap in my MySQL database. Apparently it'snews:1155hu3t54cru3e@corp.supernews.com... too big...but it shouldn't be. Here's what I got: Dim bmpDocument As Bitmap = Bitmap.FromHbitmap(hDibCopy) ' get image from scanner Dim bmpResize As New Bitmap(bmpDocument, 680, 880) mySQLManager.InsertDBImage(elmImageIndex, intNextDocument, bmpResize) Public Function InsertDBImage(ByVal ImageElement As XmlElement, _ ByVal DocumentID As Integer, _ ByVal tImage As System.Drawing.Bitmap) Dim st As New System.IO.MemoryStream tImage.Save(st, System.Drawing.Imaging.ImageFormat.Bmp) Dim bytBLOBData(st.Length - 1) As Byte 'st.Position = 0 st.Seek(0, IO.SeekOrigin.Begin) st.Read(bytBLOBData, 0, st.Length) MsgBox(bytBLOBData.Length) ' this displays 2393654...way too big Now if I save the image to file and then use that file (as opposed to the hDibCopy) the lenght is 87467...which is small enough to insert into my database. Am I doing something wrong? Why is it so big? Any help is greatly appreciated. -bruce duncan Thanks Ken...your code works but I have a question:
The size of object that is returned is ~2MB in size. If I first save the file to disk then use FileStream...the size is 84K. I guess I don't fully understand why the memorystream is so large. Is it holding extra data? If it's got extra data, can I just extract what I need? -bruce Show quoteHide quote "Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message news:uvrXJZgOFHA.2568@TK2MSFTNGP14.phx.gbl... > Hi, > > You have to store the image in binary format. Storeimage converts > image to binary format. ConvertToBitmap converts it back. Note the offset > for the northwind database is 78 my storeimage function has a offset of 0. > > Private Function StoreImage(ByVal bm As Bitmap) As Object > > Dim ms As New MemoryStream > > Try > > bm.Save(ms, Imaging.ImageFormat.Jpeg) > > Return ms.GetBuffer > > Catch > > Return Convert.DBNull > > End Try > > End Function > > Private Function ConvertToBitmap(ByVal data() As Byte, ByVal offset As > Integer) As Bitmap > > Dim ms As New System.IO.MemoryStream > > Dim bm As Bitmap > > ms = New MemoryStream > > ms.Write(data, offset, data.Length - offset) > > bm = New Bitmap(ms) > > Return bm > > End Function > > Ken >
2D array of string
Equivalent to Mid function but read from right of the string Opening a browser from vb.net from need clarification from M S Herfried K. Wagner 2GB memory limit Help using Right() string function? Command Line Compiling with license file How to set the default value of a date picker to nothing (blank) Datagrid Question Parameter it doesn't work (for me) IIII |
|||||||||||||||||||||||