我这个是webservice的,放到IIS上,是这样的 例如:用户A在浏览器输入192.168.1.199/image/i.jpg 不能让他出现i.jpg的图片
必须是用我们这个软件后才能得到图片,单纯输入ip地址获取图片 不可以,当单纯输入IP地址/image这样的就直接给跳转到其他页面
必须是用我们这个软件后才能得到图片,单纯输入ip地址获取图片 不可以,当单纯输入IP地址/image这样的就直接给跳转到其他页面
并且直接把所有的 */image/* 重定向到你需要的错误页或者提示页。
思路都是吧,这个后缀或者路径的,访问之前增加逻辑判断
{
contenttype = "image/jpeg";
}
else if(img.RawFormat==ImageFormat.Gif)
{
contenttype = "image/gif";
}
else if (img.RawFormat == ImageFormat.Bmp)
{
contenttype = "image/bmp";
}
else if (img.RawFormat == ImageFormat.Png)
{
contenttype = "image/png";
}
else if (img.RawFormat == ImageFormat.Tiff)
{
contenttype = "image/tiff";
}
MemoryStream ms = new MemoryStream(); int maxWidth = 100;
int maxHeight = 100; if (string.IsNullOrEmpty(Request.QueryString["height"]) == false && int.TryParse(Request.QueryString["height"], out maxHeight) == false)
{
maxHeight = 100;
}
if (string.IsNullOrEmpty(Request.QueryString["width"]) == false && int.TryParse(Request.QueryString["width"], out maxWidth) == false)
{
maxWidth = 100;
} Size _newSize = ResizeImage(img.Width, img.Height, maxWidth, maxHeight); if (_newSize.Width < maxWidth && _newSize.Height < maxHeight)
{
try
{
img.Save(ms, img.RawFormat);
Response.ClearContent();
Response.ContentType = contenttype;
Response.BinaryWrite(ms.ToArray());
Response.End();
return View();
}
finally
{
img.Dispose();
}
} Graphics g = null;
Bitmap b = null;
try
{
b = new Bitmap(_newSize.Width, _newSize.Height);
g = Graphics.FromImage(b);
g.InterpolationMode = InterpolationMode.High;
g.SmoothingMode = SmoothingMode.HighQuality;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.CompositingQuality = CompositingQuality.HighQuality;
//清除整个绘图面并以透明背景色填充
g.Clear(Color.White); g.DrawImage(img, new Rectangle(0, 0, _newSize.Width, _newSize.Height), new Rectangle(0, 0, img.Width, img.Height), GraphicsUnit.Pixel);
EncoderParameters parameters = new EncoderParameters(1);
parameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, ((long)95L));
b.Save(ms, img.RawFormat); Response.ClearContent();
Response.ContentType = contenttype;
Response.BinaryWrite(ms.ToArray());
Response.End();
return View();
}
finally
{
b.Dispose();
g.Dispose();
img.Dispose();
}
图片转数据流存到数据库
string fileName = openFileDialog1.FileName;
FileInfo fi = new FileInfo(fileName); FileStream fs = fi.OpenRead();
byte[] bytes = new byte[fs.Length];
fs.Read(bytes, 0, Convert.ToInt32(fs.Length));
数据库字段varbinary(MAX)= bytes;读出来转文件(基本上什么格式都可以)
FileStream fs = new FileStream(@"d:\11.xls".ToString(), FileMode.CreateNew);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(((kuan1)bind.Current).picbin2.ToArray(), 0, ((kuan1)bind.Current).picbin2.Length);
bw.Close();
fs.Close(); string strFileName = @"d:\11.xls";
Object refmissing = System.Reflection.Missing.Value;如果是图片文件直接显示
MemoryStream ms = new MemoryStream(数据库字段.ToArray());
pictureBox1.Image = Image.FromStream(ms);//
http://www.cnblogs.com/ghfsusan/archive/2011/02/25/1964579.html
建议使用 ISAPI_Rewrite# 防盗链
# RewriteCond Host: (.+)
# RewriteCond Referer: (?!http://\1.*).*
# RewriteCond Referer: (?!http://(.*)(www\.你的URL\.com|\.你的URL\.com|\.baidu\.com|\.google\.com|\.google\.cn|\.g\.cn|\.gougou\.com|\.soso\.com|\.sogou\.com|\.youdao\.com|\.bing\.com|\.yahoo\.com|\.yahoo\.cn)).+
# RewriteRule .*\.(?:gif|jpg|png|jpeg|bmp|) /block.gif [I,O,N]