从SQL读出的二进制流放在单独Page里,怎么控制图片长宽缩放
1: Response.ContentType = "image/Gif ";//设定输出文件类型,为什么一定要设置此格式,Response.ContentType =myDataReader[ "PhotoType "].ToString()却无效?
2: int length = (int)dr[ "PhotoLength "];
if (length == 0)//照片大小为0
{
Response.TransmitFile( "~/images/noPhoto.gif ");
}
else//照片大小不为0
{
Response.OutputStream.Write((byte[])dr[ "Photo "], 0, length);
dr.Close();
}
代码放置在单独Page里,别的页通过HyperLink的URL传递变量到此页,再根据变量读取SQL,得到PHOTO的字节流,类型,字节长度,现在的问题是:图片有时候非常大,或者非常小,通过HyperLink的宽度和长度无法控制, 要什么方法才能实现不管大的小的图片,都缩放到一个固定的大小(打印要求2寸照片大小)?
大侠请加我QQ:67933437
------解决方案--------------------参考:http://topic.csdn.net/t/20051212/15/4454248.html
------解决方案--------------------生成缩略图
protected void Button1_Click1(object sender, EventArgs e)
{
if (File1.PostedFile.FileName != null)
{
string namestr = Path.GetFileName(File1.PostedFile.FileName);//提取文件名
File1.PostedFile.SaveAs(Server.MapPath( ". ") + @ "\ " + namestr);
Image2.Visible = true;
Image2.ImageUrl = namestr;
System.Drawing.Image image, aNewImage;
image = System.Drawing.Image.FromStream(File1.PostedFile.InputStream);
decimal width = image.Width;
decimal height = image.Height;
int newwidth, newheight;
if (width > height)
{
newwidth = 150;
newheight = (int)(height / width * 150);
}
else
{
newheight = 150;
newwidth = (int)(width / height * 150);
}
aNewImage = image.GetThumbnailImage(newwidth, newheight, null, IntPtr.Zero);
Bitmap output = new Bitmap(aNewImage);
Graphics g = Graphics.FromImage(output);
g.DrawString( "LonoL ", new Font( "Courier New ", 9), new SolidBrush(Color.Red), 60, 60);//写版权信息及文本格式及位置
output.Save(Server.MapPath( "~/ ") + @ "\s_ &qu