c# bitmap的拷贝及一个图像工具类
using (Bitmap bmp = new Bitmap(scanImgPath))
{
Bitmap bitmap = new Bitmap(bmp.Width, bmp.Height, PixelFormat.Format16bppRgb555);
using (Graphics draw = Graphics.FromImage(bitmap))
{
draw.DrawImage(bmp, , , bitmap.Width, bitmap.Height);
picScanImg.Image = bitmap as Image;
}
}
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text; namespace TJCFinanceWriteOff.BizLogic.Common
{
public class ImageUtil
{
/// <summary>
/// 图片镜像翻转
/// </summary>
/// <param name="imagePath">图片路径</param>
/// <param name="isCover">是否覆盖</param>
/// <returns></returns>
public static Image ImageFlip(string imagePath,bool isCover = false)
{
Bitmap bitmap = Bitmap.FromFile(imagePath) as Bitmap;
bitmap.RotateFlip(RotateFlipType.Rotate180FlipY); //图片镜像翻转
if (isCover is true) bitmap.Save(imagePath,System.Drawing.Imaging.ImageFormat.Jpeg);
return bitmap;
} /// <summary>
/// 图片顺时针旋转180度
/// </summary>
/// <param name="imagePath">图片路径</param>
/// <param name="isCover">是否覆盖</param>
/// <returns></returns>
public static Image ImageRotate(string imagePath,bool isCover = false)
{
Bitmap bitmap = Bitmap.FromFile(imagePath) as Bitmap;
bitmap.RotateFlip(RotateFlipType.Rotate180FlipNone); //图片顺时针180度
if (isCover is true) bitmap.Save(imagePath,System.Drawing.Imaging.ImageFormat.Jpeg);
return bitmap;
} /// <summary>
/// 图片等比缩放
/// </summary>
/// <param name="imagePath"></param>
/// <returns></returns>
public static Image ImageScaleZoom(string imagePath, double process)
{
Bitmap bitmap = Bitmap.FromFile(imagePath) as Bitmap;
double width = bitmap.Width * process; ;//图片最终的宽
double height = bitmap.Height * process;//图片最终的高
return bitmap.GetThumbnailImage((int)width, (int)height, () => { return false; }, IntPtr.Zero);
} public static Image ImageScaleZoom(Image sourceImage, double process)
{
double width = sourceImage.Width * process; ;//图片最终的宽
double height = sourceImage.Height * process;//图片最终的高
try
{
System.Drawing.Imaging.ImageFormat format = sourceImage.RawFormat;
Bitmap targetPicture = new Bitmap((int)width, (int)height);
Graphics g = Graphics.FromImage(targetPicture);
g.DrawImage(sourceImage, , , (int)width, (int)height);
sourceImage.Dispose();
return targetPicture;
}
catch (Exception ex)
{ }
return null;
} public static Image ImageAssignZoom(Image sourceImage, int targetWidth, int targetHeight)
{
int width;//图片最终的宽
int height;//图片最终的高
try
{
System.Drawing.Imaging.ImageFormat format = sourceImage.RawFormat;
Bitmap targetPicture = new Bitmap(targetWidth, targetHeight);
Graphics g = Graphics.FromImage(targetPicture); if (sourceImage.Width > targetWidth && sourceImage.Height <= targetHeight)
{
width = targetWidth;
height = (width * sourceImage.Height) / sourceImage.Width; //噶
}
else if (sourceImage.Width <= targetWidth && sourceImage.Height > targetHeight)
{
height = targetHeight;
width = (height * sourceImage.Width) / sourceImage.Height;
}
else if (sourceImage.Width <= targetWidth && sourceImage.Height <= targetHeight)
{
width = sourceImage.Width;
height = sourceImage.Height;
}
else
{
width = targetWidth;
height = (width * sourceImage.Height) / sourceImage.Width;
if (height > targetHeight)
{
height = targetHeight;
width = (height * sourceImage.Width) / sourceImage.Height;
}
}
g.DrawImage(sourceImage, , , width, height);
sourceImage.Dispose(); return targetPicture;
}
catch (Exception ex)
{ }
return null;
}
}
}
c# bitmap的拷贝及一个图像工具类的更多相关文章
- 分享一个Snackbar工具类 SnackbarUtils;
分享一个Snackbar工具类,源代码也是在Github上面找的,自己做了一下修改: 功能如下: 1:设置Snackbar显示时间长短 1.1:Snackbar.LEN ...
- java中定义一个CloneUtil 工具类
其实所有的java对象都可以具备克隆能力,只是因为在基础类Object中被设定成了一个保留方法(protected),要想真正拥有克隆的能力, 就需要实现Cloneable接口,重写clone方法.通 ...
- 编写Java程序,创建一个数学工具类,将该类设计为final类,Final 修饰符的使用。
返回本章节 返回作业目录 需求说明: 创建一个数学工具类. 将该类设计为final类. 将该类的构造方法的访问权限定义为私有,以防止外界实例化该类. 在该类定义静态double类型常量π,其值为3.1 ...
- [分享]一个String工具类,也许你的项目中会用得到
每次做项目都会遇到字符串的处理,每次都会去写一个StringUtil,完成一些功能. 但其实每次要的功能都差不多: 1.判断类(包括NULL和空串.是否是空白字符串等) 2.默认值 3.去空白(tri ...
- 调用CMD命令的一个.NET工具类(MyWindowsCmd)
功能大概描述一下如果直接StandardOutput.ReadToEnd()这种方法,有很多限制 这类方式必须把命令全部执行一次写入并标记为exit,而且返回内容的获取会一直等待,如果在主线程里使用会 ...
- 编写一个数组工具类, 编写本软件的 帮助文档(API文档)
本文档是对静态成员的练习. 一. 建立一个ArrayTool(数组工具)的类,在此类中对传入数组进行一些操作(选最大值.先最小值.冒泡排正序.选择排反序.输出数组元素), 二. 建立一个Test的类, ...
- 基于数组阻塞队列 ArrayBlockingQueue 的一个队列工具类
java语言基于ArrayBlockingQueue 开发的一个根据特定前缀和后缀的队列.每天自动循环生成. 1.定义队列基类 Cookie package com.bytter.util.queue ...
- 分享一个FileUtil工具类,基本满足web开发中的文件上传,单个文件下载,多个文件下载的需求
获取该FileUtil工具类具体演示,公众号内回复fileutil20200501即可. package com.example.demo.util; import javax.servlet.htt ...
- 手写一个LRU工具类
LRU概述 LRU算法,即最近最少使用算法.其使用场景非常广泛,像我们日常用的手机的后台应用展示,软件的复制粘贴板等. 本文将基于算法思想手写一个具有LRU算法功能的Java工具类. 结构设计 在插入 ...
随机推荐
- 8月清北学堂培训 Day4
今天上午是赵和旭老师的讲授~ 概率与期望 dp 概率 某个事件 A 发生的可能性的大小,称之为事件 A 的概率,记作 P ( A ) . 假设某事的所有可能结果有 n 种,每种结果都是等概率,事件 A ...
- 1625: 【例 1】反素数 Antiprime
1625: [例 1]反素数 Antiprime [题目描述] 原题来自:POI 2001 如果一个大于等于 1 的正整数 n,满足所有小于 n 且大于等于 1 的所有正整数的约数个数都小于 n 的约 ...
- Dubbo——基础
一.分布式基础理论 1.1 什么是分布式系统? “分布式系统是若干独立计算机的集合,这些计算机对于用户来说就像单个相关系统” 分布式系统(distributed system)是建立在网络之上的软件系 ...
- 1.1 OC class new summary
1.http://www.cnblogs.com/mjios/archive/2013/04/06/3002814.html 2.How to create a oc class? 3. 3.1 In ...
- jQuery源代码学习之十——动画Animate
一.Animate模块的代码结构 // 定义了一些变量 tweeners = {}; function createFxNow() {} function createTween() {} funct ...
- 基本PSO算法实现(Java)
一.算法流程 Step1:初始化一群粒子(粒子个数为50个),包括随即位置和速度: Step2:计算每个粒子的适应度fitness: Step3:对每个粒子,将其适应度与其进过的最好位置(局部)pbe ...
- asp.net MVC AngularJS
http://www.cnblogs.com/powertoolsteam/category/834105.html
- Java FTP客户端开源类库 edtFTPj
edtFTPj/Free是免费的流行的Java FTP库,全球公司依靠edtFTPj /Free 为它们的Java应用程序添加FTP客户端功能. (收费的支持SFTP.FTPS的edtFTPj/PRO ...
- 阶段5 3.微服务项目【学成在线】_day03 CMS页面管理开发_03-自定义查询页面-前端
下拉选择框 <!--查询表单--> <el-form :model="params"> <el-select v-model="params ...
- 海康大华RTSP格式
海康实时流:rtsp://admin:12345@192.2.82.50:554/h264/ch4/main/av_stream海康回放流(模拟通道):rtsp://admin:12345@192.2 ...