本文整理汇总了C#中ImageType.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# ImageType.GetHashCode方法的具体用法?C# ImageType.GetHashCode怎么用?C# ImageType.GetHashCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageType
的用法示例。
在下文中一共展示了ImageType.GetHashCode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Resizepic
//.........这里部分代码省略.........
//当选择XY模式时,mwidth,mheight为必须值
if (swidth < 0 || sheight < 0)
{
checkmessage.Append("error:XY模式,mwidth,mheight为必须值;");
}
#endregion
; break;
default:
#region 默认XY模式
//当默认XY模式时,mwidth,mheight为必须值
if (swidth < 0 || sheight < 0)
{
checkmessage.Append("error:你当前未选择缩略模式,系统默认XY模式,mwidth,mheight为必须值;");
}
; break;
#endregion
}
#endregion
}
else
{
checkmessage.Append("error:未能找到缩略原图片," + picpath + ";");
}
if (string.IsNullOrEmpty(checkmessage.ToString()))
{
//创建bitmap对象
_currimg_common = new System.Drawing.Bitmap((int)swidth, (int)sheight);
_g_common = Graphics.FromImage(_currimg_common);
//设置画笔
_g_common.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
_g_common.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
_g_common.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
//绘制图片
_g_common.DrawImage(_sourceimg_common, new Rectangle(0, 0, (int)swidth, (int)sheight), new Rectangle(0, 0, _sourceimg_common.Width, _sourceimg_common.Height), GraphicsUnit.Pixel);
//保存图片
string _spath_common_mappath = "";
//获取图片类型的hashcode值,生成图片后缀名
int extro = imgtype.GetHashCode();
string extend = extro == 0 ? ".jpg" : (extro == 1 ? ".gif" : (extro == 2 ? ".png" : ".jpg"));
//全局文件名
spath = spath + Guid.NewGuid().ToString() + extend;
FileExistMapPath(spath, FileCheckModel.M, out _spath_common_mappath);
switch (imgtype)
{
case ImageType.JPEG: _currimg_common.Save(_spath_common_mappath, System.Drawing.Imaging.ImageFormat.Jpeg); break;
case ImageType.GIF: _currimg_common.Save(_spath_common_mappath, System.Drawing.Imaging.ImageFormat.Gif); break;
case ImageType.PNG: _currimg_common.Save(_spath_common_mappath, System.Drawing.Imaging.ImageFormat.Png); break;
}
//释放
_sourceimg_common.Dispose();
_currimg_common.Dispose();
_g_common.Dispose();
//处理原文件
int filecachecode = filecache.GetHashCode();
//文件缓存方式:Delete,删除原文件
if (filecachecode == 1)
{
System.IO.File.Delete(_sourceimg_common_mappath);
}
//返回相对虚拟路径
warning = "";
return spath;
}
//释放
if (_sourceimg_common != null)
{
_sourceimg_common.Dispose();
}
if (_currimg_common != null)
{
_currimg_common.Dispose();
}
if (_g_common != null)
{
_g_common.Dispose();
}
warning = checkmessage.ToString().TrimEnd(';');
return "";
}
示例2: makewatermark
//.........这里部分代码省略.........
; break;
case WaterType.CenterDown:
_sourceimg_water_point_x = (_sourceimg_common_width - _sourceimg_water_width) / 2;
_sourceimg_water_point_y = _sourceimg_common_height - _sourceimg_water_height;
; break;
case WaterType.CenterUp:
_sourceimg_water_point_x = (_sourceimg_common_width - _sourceimg_water_width) / 2;
_sourceimg_water_point_y = 0;
; break;
case WaterType.LeftDown:
_sourceimg_water_point_x = 0;
_sourceimg_water_point_y = _sourceimg_common_height - _sourceimg_water_height;
; break;
case WaterType.LeftUp:
; break;
case WaterType.Random:
Random r = new Random();
int x_random = r.Next(0, _sourceimg_common_width);
int y_random = r.Next(0, _sourceimg_common_height);
_sourceimg_water_point_x = x_random > (_sourceimg_common_width - _sourceimg_water_width)
? _sourceimg_common_width - _sourceimg_water_width : x_random;
_sourceimg_water_point_y = y_random > (_sourceimg_common_height - _sourceimg_water_height)
? _sourceimg_common_height - _sourceimg_water_height : y_random;
; break;
case WaterType.RightDown:
_sourceimg_water_point_x = _sourceimg_common_width - _sourceimg_water_width;
_sourceimg_water_point_y = _sourceimg_common_height - _sourceimg_water_height;
; break;
case WaterType.RightUp:
_sourceimg_water_point_x = _sourceimg_common_width - _sourceimg_water_width;
_sourceimg_water_point_y = 0;
; break;
}
#endregion
//从源图创建画板
System.Drawing.Graphics _g_common = Graphics.FromImage(_sourceimg_common);
//设置画笔
_g_common.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
_g_common.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
_g_common.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
//绘制水印图片
_g_common.DrawImage(_sourceimg_water, new Rectangle(_sourceimg_water_point_x, _sourceimg_water_point_y, _sourceimg_water_width, _sourceimg_water_height), new Rectangle(0, 0, _sourceimg_water_width, _sourceimg_water_height), GraphicsUnit.Pixel);
//保存图片
string _spath_common_mappath = "";
//全局文件名
//获取图片类型的hashcode值,生成图片后缀名
int extro = imgtype.GetHashCode();
string extend = extro == 0 ? ".jpg" : (extro == 1 ? ".gif" : (extro == 2 ? ".png" : ".jpg"));
spath = spath + Guid.NewGuid().ToString() + extend;
FileExistMapPath(spath, FileCheckModel.M, out _spath_common_mappath);
switch (imgtype)
{
case ImageType.JPEG: _sourceimg_common.Save(_spath_common_mappath, System.Drawing.Imaging.ImageFormat.Jpeg); break;
case ImageType.GIF: _sourceimg_common.Save(_spath_common_mappath, System.Drawing.Imaging.ImageFormat.Gif); break;
case ImageType.PNG: _sourceimg_common.Save(_spath_common_mappath, System.Drawing.Imaging.ImageFormat.Png); break;
}
//释放
_sourceimg_common.Dispose();
_sourceimg_water.Dispose();
_g_common.Dispose();
//处理原文件
int filecachecode = filecache.GetHashCode();
//删除原文件
if (filecachecode == 1)
{
System.IO.File.Delete(_sourceimg_common_mappath);
}
warning = "";
return spath;
}
#endregion
//释放
if (_sourceimg_common != null)
{
_sourceimg_common.Dispose();
}
if (_sourceimg_water != null)
{
_sourceimg_water.Dispose();
}
warning = checkmessage.ToString().TrimEnd(';');
return "";
}