C#剪切生成高质量缩放图片
/// <summary>
/// 高质量缩放图片
/// </summary>
/// <param name="OriginFilePath">源图的路径</param>
/// <param name="TargetFilePath">存储缩略图的路径</param>
/// <param name="DestWidth">缩放后图片宽度</param>
/// <param name="DestHeight">缩放后图片高度</param>
/// <returns>表明此次操作是否成功</returns>
public static bool ToSuolue(System.IO.Stream oStream, string TargetFilePath, int towidth, int toheight)
{
//System.Drawing.Image OriginImage = System.Drawing.Image.FromFile(OriginFilePath);
System.Drawing.Image OriginImage = System.Drawing.Image.FromStream(oStream);
System.Drawing.Imaging.ImageFormat thisFormat = OriginImage.RawFormat;
//按比例缩放
int x = , y = ;
int ow = OriginImage.Width;
int oh = OriginImage.Height; if ((double)ow / (double)oh > (double)towidth / (double)toheight)
{
oh = OriginImage.Height;
ow = OriginImage.Height * towidth / toheight;
y = ;
x = (OriginImage.Width - ow) / ;
}
else
{
ow = OriginImage.Width;
oh = OriginImage.Width * toheight / towidth;
x = ;
y = (OriginImage.Height - oh) / ;
} Bitmap bt = new Bitmap(towidth, toheight); //根据指定大小创建Bitmap实例
using (Graphics g = Graphics.FromImage(bt))
{
g.Clear(Color.White);
//设置画布的描绘质量
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.DrawImage(OriginImage, new Rectangle(, , towidth, toheight),
new System.Drawing.Rectangle(x, y, ow, oh),
System.Drawing.GraphicsUnit.Pixel);
g.Dispose();
} System.Drawing.Imaging.EncoderParameters EncoderParams = new System.Drawing.Imaging.EncoderParameters(); //取得内置的编码器
long[] Quality = new long[];
Quality[] = ;
System.Drawing.Imaging.EncoderParameter EncoderParam = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, Quality);
EncoderParams.Param[] = EncoderParam; //try
//{
//获得包含有关内置图像编码解码器的信息的ImageCodecInfo 对象
System.Drawing.Imaging.ImageCodecInfo[] arrayICI = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders();
System.Drawing.Imaging.ImageCodecInfo jpegICI = null;
for (int i = ; i < arrayICI.Length; i++)
{
if (arrayICI[i].FormatDescription.Equals("JPEG"))
{
jpegICI = arrayICI[i]; //设置为JPEG编码方式
break;
}
} if (jpegICI != null) //保存缩略图
{
bt.Save(TargetFilePath, jpegICI, EncoderParams);
}
else
{
bt.Save(TargetFilePath, thisFormat);
}
OriginImage.Dispose();
return true;
//}
//catch (System.Runtime.InteropServices.ExternalException e1) //GDI+发生一般错误
//{
// return false;
//}
//catch (Exception e2)
//{
// return false;
//}
}
C#剪切生成高质量缩放图片的更多相关文章
- java高质量缩放图片
可按照比例缩放,也可以指定宽高 import com.sun.image.codec.jpeg.JPEGImageEncoder; import com.sun.image.codec.jpeg.JP ...
- C#放缩、截取、合并图片并生成高质量新图的类
原文:C#放缩.截取.合并图片并生成高质量新图的类 using System;using System.Drawing;using System.Drawing.Imaging;using Syste ...
- atitit.thumb生成高质量缩略图 php .net c++ java
atitit.java thumb生成高质量缩略图 php .net c++ 1. 图像缩放(image scaling)---平滑度(smoothness)和清晰度(sharpness) 1 2. ...
- 移动Web—CSS为Retina屏幕替换更高质量的图片
来源:互联网 作者:佚名 时间:12-24 10:37:45 [大 中 小] 点评:Retian似乎是屏幕显示的一种趋势,这也是Web设计师面对的一个新挑战;移动应用程序的设计师们已经学会了如何为Re ...
- 使用 FFmpeg 处理高质量 GIF 图片
使用 FFmpeg 处理高质量 GIF 图片 - 为程序员服务 http://ju.outofmemory.cn/entry/169845
- C# GDI生成清晰【高质量】图片
对于GDI+,在正常的操作,Bitmap,Graphcis,DrawImage或者DrawString ,生成图片的话,会产生很多杂点,或者是图片质量不稳定.尤其是在读取图片后,生成缩略图之后,文件会 ...
- Python高质量缩放切图,抗锯齿
最近刚接触Python,以迅雷不及掩耳盗铃之势(只是迫不及待)应用到工作中去了之前用 cmd+photoshop做批量图像处理(缩放切片),在执行效率(速度)上和灵活度上有很大限制,遂转战Python ...
- Highcharts结合PhantomJS在服务端生成高质量的图表图片
项目背景 最近忙着给部门开发一套交互式的报表系统,来替换原有的静态报表系统. 老系统是基于dotnetCHARTING开发的,dotnetCHARTING的优势是图表类型丰富,接口调用简单,使用时只需 ...
- java图片高质量缩放类
import java.awt.Color;import java.awt.Graphics;import java.awt.Image;import java.awt.image.BufferedI ...
随机推荐
- OverflowError:django signed integer is greater than maximum 数据库日期字段相关错
使用django中的默认数据库sqlite3, 在pycharm中录入日期字段相关信息结果出现问题 在保存的时候如图 直接在界面选择的日期变成了时间戳, 并且在获取数据的时候报错 经过查询之后(舔大佬 ...
- Vue介绍:vue项目搭建
一.环境搭建 二.项目创建 三.认识项目 四.项目功能 一.环境搭建 *安装node 官网下载安装包,傻瓜式安装:https://nodejs.org/zh-cn/ *安装cnpm npm insta ...
- LoadRunner(5)
一.在线综合场景测试:号称能更真实模拟实际生产环境 又称为:混合交易测试 (交易就是事务 Transaction) 1.三要素: 1)多用户:根据需求指定VU数 压力的来源 2)多任务:根据需求结合多 ...
- java8 常用语法小结
// 判空 // 排序 //映射 //序列化
- js技术javascript 该重视
当下,js大有挤压php java asp.net之类后端语言的趋势,直接js html5 socket与后端python c c++ 等通信 更不用提二维 三维计算展示 方面 医院呼叫 报警 处理 ...
- string::cbegin string::cend
const_iterator cbegin() const noexcept; const_iterator cend() const noexcept;注:返回常量迭代器,不能修改 #include ...
- Spring-简介-IOC理论推导
1.Spring 1.1.简介 Spring:春天----->给软件行业带来了春天! 2002,首次推出了Spring框架的雏形:interface21框架! Spring框架即以interfa ...
- 微信 使用wScratchPad 组件时 出错
说是由于android版本bug 可访问 https://github.com/websanova/wScratchPad/issues/15 解决方法: $("#wScratchPad c ...
- [React] Reduce Code Redundancy with Custom React Hooks
In this lesson, we'll cover how to create a custom React hook for managing the state of any input. T ...
- 创建节点--DOM树
创建节点 快捷键:innerhtml outerhtml innertext outertext ==============创建节点方法有两种:============== <script s ...