[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Uploading Image to db and resizing

Posted on 2004-04-08
6
Medium Priority
?
370 Views
Last Modified: 2010-04-15
I'm using this code in a page to upload an image to a Sql2000 database.  Everything is working as I have it, but I want to automatically resize the image height and width before it gets uploaded to the db.  I don't really care about file size, just dimensions.  I can't find any way to check the width or height of the file that is being uploaded.  

aspx page:
<input id="browse" type="file" runat="server" NAME="browse"><asp:button id="btnNewPhoto" runat="server" Text="Change Photo" Visible="False" />

code behind:

Stream imgStream = browse.PostedFile.InputStream;
int imgLen = browse.PostedFile.ContentLength;
string imgContentType = browse.PostedFile.ContentType;
byte[] imgBinaryData = new byte[imgLen];
int n = imgStream.Read(imgBinaryData,0,imgLen);

.
.
Lines Omitted for clarity
.
.

SqlParameter parmPhoto = cmd.Parameters.Add("@photo", SqlDbType.Image);
parmPhoto.Value = imgBinaryData;

SqlParameter parmPhotoType = cmd.Parameters.Add("@photoType",SqlDbType.NVarChar, 50);
parmPhotoType.Value = imgContentType;




Thank you for viewing,
dave
0
Comment
Question by:KaiserSose
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 12

Expert Comment

by:dfiala13
ID: 10784197
To get the image size load the stream nto an image object

 System.Drawing.Image  img = Image.FromStream(imgStream)
 RectangleF r = GetBounds(GraphicsUnit.Pixel);

float h = r.Height;
float w = r.Width;
0
 
LVL 2

Author Comment

by:KaiserSose
ID: 10786004
That looks like it should work, but the code just doesn't compile.  It doesnt like GetBounds and it throws an 'ambiguoous' error on the Image.FromStream.

dave
0
 
LVL 2

Author Comment

by:KaiserSose
ID: 10786169
I got it to work like this:

System.Drawing.Image img = System.Drawing.Image.FromStream(imgStream);

I don't know why I have to specify System.Drawing beacuse I'm 'using' it at the top of the page.

It still doesn't like the GetBounds.  I can't even get to that in msdn if i use the C# filter.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 12

Accepted Solution

by:
dfiala13 earned 2000 total points
ID: 10786254
Sorry, bad typing, should have just cut and paste.

RectangleF r = img.GetBounds(GraphicsUnit.Pixel);

need to use full namespace because Image belongs to more than one namespace, hence ambigutiy error
0
 
LVL 2

Author Comment

by:KaiserSose
ID: 10786310
I got it working using this:

System.Drawing.Image img = System.Drawing.Image.FromStream(imgStream);
                  int w = img.Width;
                  int h = img.Height;

and an if statement to check for my bounds.  You were close enough though, thanks for the help.
0
 
LVL 12

Expert Comment

by:dfiala13
ID: 10786325
Much slicker.  sorry I was so sloppy on my initial post.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question