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. 【概率论】1-4:事件的的并集(Union of Events and Statical Swindles)

    title: [概率论]1-4:事件的的并集(Union of Events and Statical Swindles) categories: Mathematic Probability key ...

  2. 在C语言中破坏函数调用堆栈

    // 这段代码显示,在C语言修改函数的返回地址 int test1() { ; } int test2(int a) { *(&a-) = (int)test1; // 将返回地址修改为tes ...

  3. CF1140F Extending Set of Points 【按时间分治,并查集】

    题目链接:洛谷 首先我们考虑没有撤回操作的情况,就是将每一行和每一列看做一个点(代表行的称为白点,代表列的称为黑点),每个点$(x,y)$看做一条边. Extend操作实际上就是$x_1$行与$y_1 ...

  4. 【新词发现】基于SNS的文本数据挖掘、短语挖掘

    互联网时代的社会语言学:基于SNS的文本数据挖掘 python实现 https://github.com/jtyoui/Jtyoui/tree/master/jtyoui/word  这是一个无监督训 ...

  5. 主机,路由器,应用程序,sockets api的关系

  6. C语言指针方法对字符串进行去重

    自己编写了3种方法,都是使用指针的.(在LR中编写的) 1.先在原字符串进行比较,然后再放入目标字符串 Action() { char *srt="aadfeedeewwffggecccew ...

  7. 小程序开发:用原生还是选框架(wepy/mpvue/uni-app/taro)?

    小程序开发:用原生还是选框架(wepy/mpvue/uni-app/taro)? 自 2017-1-9微信小程序诞生以来,历经2年多的迭代升级,已有数百万小程序上线,成为继Web.iOS.Androi ...

  8. Dubbo系列(三)dubbo的核心技术--RPC调用

    dubbo的核心技术--RPC调用:分为俩部分RPC协议Protocol和方法调用Invoke: 一.RPC协议Protocol(Remote Procedure Call)远程过程调用协议 1.我们 ...

  9. Leetcode题目337:打家劫舍 III(树形DP-中等)

    题目描述: 在上次打劫完一条街道之后和一圈房屋后,小偷又发现了一个新的可行窃的地区.这个地区只有一个入口,我们称之为“根”. 除了“根”之外,每栋房子有且只有一个“父“房子与之相连.一番侦察之后,聪明 ...

  10. 文本处理三剑客之awk

    简介 awk是一种处理文本文件的语言,是一个强大的文本编辑工具.简单来说awk就是把文件逐行的读入,以空格为默认分隔符将每行切片,切开的部分在进行各种分析处理. gawk 用法:gawk [optio ...