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的拷贝及一个图像工具类的更多相关文章

  1. 分享一个Snackbar工具类 SnackbarUtils;

    分享一个Snackbar工具类,源代码也是在Github上面找的,自己做了一下修改: 功能如下: 1:设置Snackbar显示时间长短                 1.1:Snackbar.LEN ...

  2. java中定义一个CloneUtil 工具类

    其实所有的java对象都可以具备克隆能力,只是因为在基础类Object中被设定成了一个保留方法(protected),要想真正拥有克隆的能力, 就需要实现Cloneable接口,重写clone方法.通 ...

  3. 编写Java程序,创建一个数学工具类,将该类设计为final类,Final 修饰符的使用。

    返回本章节 返回作业目录 需求说明: 创建一个数学工具类. 将该类设计为final类. 将该类的构造方法的访问权限定义为私有,以防止外界实例化该类. 在该类定义静态double类型常量π,其值为3.1 ...

  4. [分享]一个String工具类,也许你的项目中会用得到

    每次做项目都会遇到字符串的处理,每次都会去写一个StringUtil,完成一些功能. 但其实每次要的功能都差不多: 1.判断类(包括NULL和空串.是否是空白字符串等) 2.默认值 3.去空白(tri ...

  5. 调用CMD命令的一个.NET工具类(MyWindowsCmd)

    功能大概描述一下如果直接StandardOutput.ReadToEnd()这种方法,有很多限制 这类方式必须把命令全部执行一次写入并标记为exit,而且返回内容的获取会一直等待,如果在主线程里使用会 ...

  6. 编写一个数组工具类, 编写本软件的 帮助文档(API文档)

    本文档是对静态成员的练习. 一. 建立一个ArrayTool(数组工具)的类,在此类中对传入数组进行一些操作(选最大值.先最小值.冒泡排正序.选择排反序.输出数组元素), 二. 建立一个Test的类, ...

  7. 基于数组阻塞队列 ArrayBlockingQueue 的一个队列工具类

    java语言基于ArrayBlockingQueue 开发的一个根据特定前缀和后缀的队列.每天自动循环生成. 1.定义队列基类 Cookie package com.bytter.util.queue ...

  8. 分享一个FileUtil工具类,基本满足web开发中的文件上传,单个文件下载,多个文件下载的需求

    获取该FileUtil工具类具体演示,公众号内回复fileutil20200501即可. package com.example.demo.util; import javax.servlet.htt ...

  9. 手写一个LRU工具类

    LRU概述 LRU算法,即最近最少使用算法.其使用场景非常广泛,像我们日常用的手机的后台应用展示,软件的复制粘贴板等. 本文将基于算法思想手写一个具有LRU算法功能的Java工具类. 结构设计 在插入 ...

随机推荐

  1. 图的基本存储的基本方式一(SDUT 3116)

    Problem Description 解决图论问题,首先就要思考用什么样的方式存储图.但是小鑫却怎么也弄不明白如何存图才能有利于解决问题.你能帮他解决这个问题么? Input 多组输入,到文件结尾. ...

  2. 系统信息的管理函数API

    1.Windows系统信息 1.1获取系统版本:   BOOL WINAPI GetVersionEx( __in_out LPOSVERSIONINFO lpVersionInfo ); lpVer ...

  3. springboot中web应用的统一异常处理

    在web应用中,请求处理过程中发生异常是非常常见的情况.springboot为我们提供了一个默认的映射:/error,当处理中抛出异常之后,会转到该请求中处理,并且该请求有一个全局的错误页面用来展示异 ...

  4. 走进JavaWeb技术世界3:JDBC的进化与连接池技术

    走进JavaWeb技术世界3:JDBC的进化与连接池技术 转载公众号[码农翻身] 网络访问 随着 Oracle, Sybase, SQL Server ,DB2,  Mysql 等人陆陆续续住进数据库 ...

  5. Maven的概述和基础(学习整理)

    1. Maven是啥 Maven是一个项目管理工具,包含了一个项目对象模型(POM),一组标准集合,一个项目生命周期(Lifecycle),一个依赖管理系统,和用来运行定义在生命周期阶段中的插件目标的 ...

  6. 从源码看Java集合之ArrayList

    Java集合之ArrayList - 吃透增删查改 从源码看初始化以及增删查改,学习ArrayList. 先来看下ArrayList定义的几个属性: private static final int ...

  7. Chrome浏览器报错:ERR_UNSAFE_PORT

    今天用Chrome浏览器打开一个页面发现报错了:ERR_UNSAFE_PORT. 所以,去搜了一下发现Chrome浏览器是默认一些端口号为非安全端口的. 遇到这个问题建议更换端口号或者更换浏览器打开. ...

  8. PostgreSQL判断一个表是否存在

    postgresql判断一个表是否存在: 方法一: select count(*) from pg_class where relname = 'tablename'; 方法二: select cou ...

  9. 【SpringBoot】转载 springboot使用thymeleaf完成数据的页面展示

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/weixin_36380516/artic ...

  10. Socket概述

    Socket套接字概述: 网络上具有唯一标识的IP地址和端口号组合在一起才能构成唯一能识别的标识符套接字. 通信的两端都有Socket. 网络通信其实就是Socket间的通信. 数据在两个Socket ...