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工具类. 结构设计 在插入 ...
随机推荐
- Java面向对象2(G~J)
G 织女的红线(SDUT 2240) import java.util.Scanner; import java.text.DecimalFormat; class Sum { double x ...
- cdh版hbase构建Phoenix 遇到的坑
Phoenix 构建cdh版hbase遇到的坑 1. 安装phoenix 下载:在github上下载对应版本https://github.com/apache/phoenix 解压:略 编译: 修改根 ...
- Ajax请求如何设置csrf_token
1. 方式一 通过获取隐藏的input标签中的csrfmiddlewaretoken值,放置在data中发送. $.ajax({ url: "/cookie_ajax/", typ ...
- AGC009C Division into Two
题意 有\(n\)个严格升序的数,请你分成两个集合\(A\)和\(B\),其中一个集合任意两数之差不小于\(x\),另一集合任意两数之差不小于\(y\). 问方案数,集合可以为空. $n \le 10 ...
- 检测ip代理有效性
转载及总结 转载:https://xw.qq.com/amphtml/20190428A05ZS200 1.telnet 方法 经过测试,会看到存在以下问题: 即使一些代理商能够用telnet测试过关 ...
- 用tecplot提取数据用于重构模型
本方法还有诸多不完善的地方,转换代码转换格式之后还是需要自己手动分割txt文件,如果数据量太大,手动操作很是辛苦.现在只能得到点的数据,如何重构几何还是问题,UG貌似可以,欢迎交流. 首先在tecpl ...
- Java core dump
目录 生成Java core dump core dump分析 生成Java core dump 可以按照下面这个文章的指引来通过jni调用触发Java core dump Generating a ...
- 前端知识点回顾——mongodb和mongoose模块
mongodb和mongoose模块 数据库 数据库有关系型数据库(MySQL)和非关系型数据库(mongodb),两者的语法和数据存储形式不一样. mySQL 关系型数据库 类似于表格的形式,每一条 ...
- protobuf ubuntu 18.04环境下安装
(t20190518) luo@luo-All-Series:~/MyFile$ (t20190518) luo@luo-All-Series:~/MyFile$ (t20190518) luo@lu ...
- 阶段5 3.微服务项目【学成在线】_day04 页面静态化_24-页面预览-页面预览测试
通过nginx转发到预览的地址 重启nginx 添加页面预览按钮 调整下列表的列的宽度