It's being displayed on the web form. What is actually happening is the browser is translating the binary from the image field in my database into the gif, the actual image isn't on the web form itself.
Main Topics
Browse All TopicsUsing a windows application I'm converting an image to binary then selecting the binary on a web form where it is converted back to an image. The problem I have is that the image is too small and is distorted. The image isn't being displayed in a control so I need to specify the size in the code either when its converted to binary or when it's converted back to an image. Here is the code I use to convert it back to an image:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
//
string imgid =Request.QueryString["imgi
string connstr= "Connection String;";
string sql="SELECT webpic FROM faxout where recno = 98";
SqlConnection connection = new SqlConnection(connstr);
SqlCommand command = new SqlCommand(sql, connection);
connection.Open();
SqlDataReader dr = command.ExecuteReader();
if(dr.Read())
{
Response.ContentType = "image/gif";
Response.BinaryWrite( (byte[]) dr["webpic"] );
}
connection.Close();
}
Please Help!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
private System.Drawing.Image GetImage(int _id) {
//get image from your database etc
return ret;
}
private int ReadVal(string name, int def) {
int ret = def;
if(Request.QueryString[nam
try {
ret = System.Convert.ToInt32(Req
}
catch {}
}
return ret;
}
public bool ThumbnailCallback() {
return false;
}
private void Page_Load(object sender, System.EventArgs e) {
float x,y,newx,newy,deltax,delta
float scale;
int force;
if(Request.QueryString["id
throw new System.Exception("must have id") ;
}
System.Drawing.Image img = GetImage(System.Convert.To
x = ReadVal("x", img.Size.Width);
y = ReadVal("y", img.Size.Height);
force=ReadVal("force", 0);
newx = img.Size.Width;
newy = img.Size.Height;
if(img.Size.Width > x || img.Size.Height > y || force == 1) {
deltax = img.Size.Width - x;
deltay = img.Size.Height - y;
scale = deltax > deltay ? x / newx : y / newy;
newx = newx * scale;
newy = newy * scale;
}
if(newx != img.Size.Width) {
System.Drawing.Image.GetTh
img = img.GetThumbnailImage((int
}
Response.ContentType = "image/jpeg" ;
img.Save(Response.OutputSt
}
You will notice that this example is using GetThumbnailImage() ... this can cause problems if the images you are dealing with have embedded thumbnails
for example ...
I have an 800x600 image that I want to resize to 400x300 ...
if I use GetThumbNailImage() and this image has a thumbnail image it will blow up the thumbnail image to 400x300 as opposed to shrinking the 800x600 to 400x300 ... this can cause alot of loss in your image or some funnier results in images due to the thumbnail not being the same as the original image!
The following code does not have this problem but can execute slower in some circumstances.
public System.Drawing.Image ResizeImage(System.Drawing
//Detach image from its source
System.Drawing.Image oImageOriginal = (System.Drawing.Image)poIm
//Resize new image
System.Drawing.Image oResizedImage = new System.Drawing.Bitmap(poSi
System.Drawing.Graphics oGraphic = Graphics.FromImage(oResize
oGraphic.CompositingQualit
oGraphic.SmoothingMode = System.Drawing.Drawing2D.S
oGraphic.InterpolationMode
Rectangle oRectangle = new Rectangle(0, 0, poSize.Width, poSize.Height);
oGraphic.DrawImage(oImageO
oGraphic.Dispose() ;
oImageOriginal.Dispose();
return oResizedImage;
}
Cheers,
Greg
yes.
mine is ...
private System.Drawing.Image GetImage(int _id) {
MyDataLayer.Files File;
System.Drawing.Image ret = null;
MemoryStream str;
if(Request.QueryString.Cou
File = MyDataLayer.Files.GetById(
str = new MemoryStream(File.FileData
ret = System.Drawing.Image.FromS
}
return ret;
}
File Data on my object is a byte [] which I then put a memorystream around and tell the image object to parse.
Greg
private System.Drawing.Image GetImage(int _id) {
System.Drawing.Image ret = null;
string imgid =Request.QueryString["imgi
string connstr= "Connection String;";
string sql="SELECT webpic FROM faxout where recno = 98";
SqlConnection connection = new SqlConnection(connstr);
SqlCommand command = new SqlCommand(sql, connection);
connection.Open();
SqlDataReader dr = command.ExecuteReader();
if(dr.Read())
{
MemoryStream str;
str = new MemoryStream((byte[]) dr["webpic"] );
ret = System.Drawing.Image.FromS
}
return ret;
}
seems like it would be about right for you.
Greg
Business Accounts
Answer for Membership
by: icestacPosted on 2005-06-16 at 10:21:42ID: 14233497
Are you displaying the picture on the winform on a webpage?
If on a winform we can resize it there, if on a webpage, you can change the img height and width attributes.
If the picture actually a GIF?