网站中加入地图/ 缩略图

 

一、访问百度地图生成器:http://dev.baidu.com/wiki/static/map/API/tool/creatMap/
设置好后,点击生成代码,复制过去,给放地图的页面某标签加个id 即可。


二、等比例缩放图片

/// <summary> 

/// 根据源图片生成高清晰缩略图
/// </summary>
/// <param name="imgPath_old">源图(大图)物理路径</param>
/// <param name="imgPath_new">缩略图物理路径(生成的缩略图将保存到该物理位置)</param>
/// <param name="width">缩略图宽度</param>
/// <param name="height">缩略图高度</param>
/// <param name="mode">缩略图缩放模式(取值"HW":指定高宽缩放,可能变形;取值"W":按指定宽度,高度按比例缩放;取值"H":按指定高度,宽度按比例缩放;取值"Cut":按指定高度和宽度裁剪,不变形);取值"DB":等比缩放,以值较大的作为标准进行等比缩放</param>
/// <param name="type">即将生成缩略图的文件的扩展名(仅限:JPG、GIF、PNG、BMP)</param>
public void MakeThumbnail(string imgPath_old, string imgPath_new, int width, int height, string mode, string imageType, int xx, int yy)
{
System.Drawing.Image img = System.Drawing.Image.FromFile(imgPath_old);
int towidth = width; int toheight = height;
int x = 0; int y = 0; int ow = img.Width;
int oh = img.Height; switch (mode)
{
case "HW": //指定高宽压缩
if ((double)img.Width / (double)img.Height > (double)width / (double)height)//判断图形是什么形状
{
towidth = width;
toheight = img.Height * width / img.Width;
}
else if ((double)img.Width / (double)img.Height == (double)width / (double)height)
{
towidth = width;
toheight = height;
}
else
{
toheight = height;
towidth = img.Width * height / img.Height;
}
break;
case "W": //指定宽,高按比例
toheight = img.Height * width / img.Width;
break;
case "H": //指定高,宽按比例
towidth = img.Width * height / img.Height;
break;
case "Cut": //指定高宽裁减(不变形)
if ((double)img.Width / (double)img.Height > (double)towidth / (double)toheight)
{
oh = img.Height;
ow = img.Height * towidth / toheight;
y = yy; x = (img.Width - ow) / 2;
}
else
{
ow = img.Width;
oh = img.Width * height / towidth;
x = xx; y = (img.Height - oh) / 2;
} break;
case "DB": // 按值较大的进行等比缩放(不变形)
if ((double)img.Width / (double)towidth < (double)img.Height / (double)toheight)
{
toheight = height;
towidth = img.Width * height / img.Height;
}
else
{
towidth = width;
toheight = img.Height * width / img.Width;
} break;
default:
break;
}
//新建一个bmp图片
System.Drawing.Image bitmap = new System.Drawing.Bitmap(towidth, toheight);
//新建一个画板
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
//设置高质量插值法
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
//设置高质量,低速度呈现平滑程度
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//清空画布并以透明背景色填充
g.Clear(System.Drawing.Color.Transparent);
//在指定位置并且按指定大小绘制原图片的指定部分
g.DrawImage(img, new System.Drawing.Rectangle(0, 0, towidth, toheight),
new System.Drawing.Rectangle(x, y, ow, oh),
System.Drawing.GraphicsUnit.Pixel); try
{
//以jpg格式保存缩略图
switch (imageType.ToLower())
{
case "gif":
bitmap.Save(imgPath_new, ImageFormat.Gif);//生成缩略图
break;
case "jpg":
bitmap.Save(imgPath_new, System.Drawing.Imaging.ImageFormat.Jpeg);
break;
case "bmp":
bitmap.Save(imgPath_new, System.Drawing.Imaging.ImageFormat.Bmp);
break;
case "png":
bitmap.Save(imgPath_new, System.Drawing.Imaging.ImageFormat.Png);
break;
default:
bitmap.Save(imgPath_new, System.Drawing.Imaging.ImageFormat.Jpeg);
break;
}
保存缩略图
// bitmap.Save(imgPath_new);
}
catch (System.Exception e)
{
throw e;
}
finally
{
img.Dispose();
bitmap.Dispose(); g.Dispose();
}
}

转载于:https://www.cnblogs.com/hfzs2011/archive/2012/12/25/2832817.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值