473,486 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

from bitmap to stream?

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

Nov 19 '05 #1
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

Nov 19 '05 #2
thanks alot, it finally worked :)

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4333
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...
4
48947
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...
11
5264
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...
13
3284
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...
7
2282
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,...
8
4377
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....
9
1909
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...
1
1149
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...
20
6964
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...
0
7126
Oralloy
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,...
0
7175
jinu1996
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...
1
6842
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...
0
7330
tracyyun
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...
0
5434
agi2029
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,...
1
4865
isladogs
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...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
262
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.