I'm trying to load and image into a DB and alongside the image also a
thumbnailed version of the image, but somewhere in my code, the stream
doesn't take the thumbnail data. When I just change toe bitmap.save()
to a file instead of a stream it works just fine.
Dim bm As Bitmap = System.Drawing.Image.FromStream(fs)
Dim newHeight As Integer = 40
Dim newWidth As Integer = (newHeight / bm.Height) * bm.Width
Dim resized As Bitmap = New Bitmap(newWidth, newHeight)
Dim g As Graphics = Graphics.FromImage(resized)
g.InterpolationMode =
System.Drawing.Drawing2D.InterpolationMode.HighQua lityBicubic
g.DrawImage(bm, New Rectangle(0, 0, resized.Width,
resized.Height), 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixel)
g.Dispose()
'Problems starts here
Dim imgStream As New IO.MemoryStream
resized.Save(imgStream, ImageFormat.Jpeg)
Dim c(imgStream.Length() - 1) As Byte
imgStream.Read(c, 0, c.Length)
imgStream.Close()
'problems end here
somehere in between there something goes bad. and I don't know what.
the workaround is to save the img in a tempfile and read a stream from
that but that's absurd.
Please don't direct me to a guide, or suggest to me to rework my whole
code, I only need to get a filled stream.
/Bennie 2 2209
Try this: 'Problems starts here
Dim imgStream As New IO.MemoryStream resized.Save(imgStream, ImageFormat.Jpeg) Dim c(imgStream.Length() - 1) As Byte
'Reposition the MemoryStream pointer to the start of the stream after the
save
imgStream.Position = 0
imgStream.Read(c, 0, c.Length) imgStream.Close()
'problems end here
HTH,
Jody
<cr*******@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com... I'm trying to load and image into a DB and alongside the image also a thumbnailed version of the image, but somewhere in my code, the stream doesn't take the thumbnail data. When I just change toe bitmap.save() to a file instead of a stream it works just fine.
Dim bm As Bitmap = System.Drawing.Image.FromStream(fs) Dim newHeight As Integer = 40 Dim newWidth As Integer = (newHeight / bm.Height) * bm.Width
Dim resized As Bitmap = New Bitmap(newWidth, newHeight) Dim g As Graphics = Graphics.FromImage(resized) g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQua lityBicubic g.DrawImage(bm, New Rectangle(0, 0, resized.Width, resized.Height), 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixel) g.Dispose()
'Problems starts here
Dim imgStream As New IO.MemoryStream resized.Save(imgStream, ImageFormat.Jpeg) Dim c(imgStream.Length() - 1) As Byte imgStream.Read(c, 0, c.Length) imgStream.Close()
'problems end here
somehere in between there something goes bad. and I don't know what. the workaround is to save the img in a tempfile and read a stream from that but that's absurd.
Please don't direct me to a guide, or suggest to me to rework my whole code, I only need to get a filled stream.
/Bennie
thanks alot, it finally worked :) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: John Scott |
last post by:
I am storing an image in an SQL database and have one field as an image
datatype. I am also using a webservice to transport data.
I want to be able to resize the image and pass back a thumbnail...
|
by: Ed Sutton |
last post by:
I have been searching for how to get an icon resource and load it into an
ImageList. I added an *.ico file to my project and set the files "Build
Action" to "Embedded Resource". Is there any easy...
|
by: Detlef Hüttenbach |
last post by:
Whereas loading tiffs and pngs from file into an Image WebControl work, the
images aren't shown when loaded from streams:
In a WebForm, the image's property "ImageUrl" is set to a handler, and...
|
by: Metallicraft |
last post by:
I have a vb6 application. On the main form is a picture
box with one or two images and several pieces of text
displayed in it. These are created on the fly using gdi32
routines that are all in a...
|
by: Nathan Sokalski |
last post by:
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving,...
| |
by: gsmith |
last post by:
Hello,
I am developing a video recording (mjpeg) system which records large
binary files. I need to read the JPEG data from the binary file and
create a bitmap object to be displayed....
|
by: poifull |
last post by:
Hi All,
I have the following task:
1. create an image object in memory (a rectangle with nothing on it)
2. write some text on the rectangle
3. rotate the image 90 degree
4. save the image to a...
|
by: Chris Ashley |
last post by:
Hi,
If I create a Bitmap object from a stream, is the data making up the
image from that stream duplicated in the Bitmap object, or does the
Bitmap just point to the stream somehow without...
|
by: Joe Duchtel |
last post by:
Hello -
I have the following code to get a bitmap from the clipboard and to
save it to a *.png file ...
Dim lData As IDataObject = Clipboard.GetDataObject()
If...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |