ASP.Net Thumbnails

C

Chris D

I'm doing some work with submitting graphics via ASP.net page to SQL 2000
server using VB.

I know how to get a graphic into the database from a filefield control. I
also know how to pull it out of the database and thumbnail it on the fly.

Creating thumbnail on the fly seems extremely inefficient to me as this has
to be done every time the image is requested. What I want to do is get the
image from the filefield control, thumbnail it and save the thumbnail to the
database along with the full size image. That way the thumbnail process is
only ran once and I'm not to concerned about the extra storage space.

What I cant figure out is how to get the image from the
postedfile.imputstream.read to a system.drawing.image to generate the
thumbnail and then send the thumbnail to the database again.

I'm new to .net so any help is greatly appreciated

Thanks
Chris D
 
S

Sherif ElMetainy

Hello

Use System.Drawing.Image.FromStream methof to get the image from the posted
file inputstream
To put the image in the database, Create a MemoryStream object and save the
image to it

System.Drawing.Image origImage =
System.Drawing.Image.FromStream(postedFile.InputStream);
postedFile.InputStream.Seek(0, SeekOrigin.Begin); // rewind the input stream
to read it again to store the original image in the database

System.Drawing.Image thumbnail = new System.Drawing.Bitmap(w, h);
//generate the thumbnail

MemoryStream ms = new MemoryStream();
thumbnail.Save(ms);
ms.Seek(0, SeekOrigin.Begin);

byte[] buffer = new byte[ms.Length];
ms.Read(buffer, 0, buffer.Length);

Best regards,

Sherif ElMetainy
 
C

Chris D

I have tried what you suggested and it seems to work. The images are in the
database.

Where I run into problems is retrieving the images processed by this code.
Is there any special way of retrieving these images. Images submitted with
my old code retrieve fine. Its almost like the format of the image is not
correct. All it does is show a 'X' image

Chris

Sherif ElMetainy said:
Hello

Use System.Drawing.Image.FromStream methof to get the image from the posted
file inputstream
To put the image in the database, Create a MemoryStream object and save the
image to it

System.Drawing.Image origImage =
System.Drawing.Image.FromStream(postedFile.InputStream);
postedFile.InputStream.Seek(0, SeekOrigin.Begin); // rewind the input stream
to read it again to store the original image in the database

System.Drawing.Image thumbnail = new System.Drawing.Bitmap(w, h);
//generate the thumbnail

MemoryStream ms = new MemoryStream();
thumbnail.Save(ms);
ms.Seek(0, SeekOrigin.Begin);

byte[] buffer = new byte[ms.Length];
ms.Read(buffer, 0, buffer.Length);

Best regards,

Sherif ElMetainy



Chris D said:
I'm doing some work with submitting graphics via ASP.net page to SQL 2000
server using VB.

I know how to get a graphic into the database from a filefield control. I
also know how to pull it out of the database and thumbnail it on the fly.

Creating thumbnail on the fly seems extremely inefficient to me as this has
to be done every time the image is requested. What I want to do is get the
image from the filefield control, thumbnail it and save the thumbnail to the
database along with the full size image. That way the thumbnail process is
only ran once and I'm not to concerned about the extra storage space.

What I cant figure out is how to get the image from the
postedfile.imputstream.read to a system.drawing.image to generate the
thumbnail and then send the thumbnail to the database again.

I'm new to .net so any help is greatly appreciated

Thanks
Chris D
 
C

Chris D

Never mind, I got it to work.

Thanks a lot for the help

Chris

Chris D said:
I have tried what you suggested and it seems to work. The images are in the
database.

Where I run into problems is retrieving the images processed by this code.
Is there any special way of retrieving these images. Images submitted with
my old code retrieve fine. Its almost like the format of the image is not
correct. All it does is show a 'X' image

Chris

Sherif ElMetainy said:
Hello

Use System.Drawing.Image.FromStream methof to get the image from the posted
file inputstream
To put the image in the database, Create a MemoryStream object and save the
image to it

System.Drawing.Image origImage =
System.Drawing.Image.FromStream(postedFile.InputStream);
postedFile.InputStream.Seek(0, SeekOrigin.Begin); // rewind the input stream
to read it again to store the original image in the database

System.Drawing.Image thumbnail = new System.Drawing.Bitmap(w, h);
//generate the thumbnail

MemoryStream ms = new MemoryStream();
thumbnail.Save(ms);
ms.Seek(0, SeekOrigin.Begin);

byte[] buffer = new byte[ms.Length];
ms.Read(buffer, 0, buffer.Length);

Best regards,

Sherif ElMetainy



Chris D said:
I'm doing some work with submitting graphics via ASP.net page to SQL 2000
server using VB.

I know how to get a graphic into the database from a filefield
control.
I this
has to
the
process
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top