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工具类. 结构设计 在插入 ...
随机推荐
- 2019CCPC-江西省赛
目录 Contest Info Solutions A. Cotree C.Trap D.Wave F.String G. Traffic H.Rng I. Budget J. Worker K. C ...
- [报错解决] 关于windows下 使用Anaconda3安装的python无法使用ssl模块问题.关联pip无法下载https
关联错误: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not ...
- Spring Cloud Gateway(一):认识Spring Cloud Gateway
1.Spring Cloud Gateway 简介 Spring Cloud Gateway 系列目录 Spring Cloud Gateway(一):认识Spring Cloud Gateway S ...
- 微信小程序之简单记账本开发记录(五)
样式表和大致布局在昨天已构建好,今天完成页面结构部分 结果如下图所示
- elasticsearch _update api 更新部分字段内容
https://www.elastic.co/guide/cn/elasticsearch/guide/current/partial-updates.htmlupdate 请求最简单的一种形式是接收 ...
- 【面试题总结】1、统计字符串中某个字符出现的次数(2-Python实现)
1.可以使用Python的字典实现,对于一个特定的字符串,使用for循环遍历其中的字符,并保存成字典形式.字典的key为字符,value为字符在整个字符串中出现的次数. 2.拓展:如果题目为比较两个字 ...
- Facebook币Libra学习-3.小试牛刀第一笔交易
我们提供了一个命令行界面(CLI)客户端来与区块链进行交互. 假设 本文档中的所有命令均假定: 您运行的是Linux(基于Red Hat或Debian)或macOS系统. 您可以稳定地连接到互联网. ...
- hashMap 底层原理+LinkedHashMap 底层原理+常见面试题
1.源码 java1.7 hashMap 底层实现是数组+链表 java1.8 对上面进行优化 数组+链表+红黑树 2.hashmap 是怎么保存数据的. 在hashmap 中有这样一个结构 ...
- java多线程面试题整理及答案(2019年)
1) 什么是线程? 线程是操作系统能够进行运算调度的最小单位,它被包含在进程之中,是进程中的实际运作单位.程序员可以通过它进行多处理器编程,你可以使用多线程对 运算密集型任务提速.比如,如果一个线程完 ...
- Handler常见两种用法
1.Handler在Android的两个功能 1.1表示未来某时做某事 1.2线程间通信 2.演示源码如下: package com.example.datastrorage; import andr ...