GDI++绘图问题

截图--控件截图

    //control.CopyFromScreen
    //ok  
    //Rectangle rectangleBounds = pbx.Bounds;
    //Bitmap bit = new Bitmap(rectangleBounds.Width, rectangleBounds.Height);//实例化一个和窗体一样大的bitmap
    //Graphics g = Graphics.FromImage(bit);
    //g.CompositingQuality = CompositingQuality.HighQuality;//质量设为最高
    g.CopyFromScreen(pbx.Left, pbx.Top, 0, 0, new Size(pbx.Width, pbx.Height));//保存整个窗体为图片
    //g.CopyFromScreen(pbx.PointToScreen(Point.Empty), Point.Empty, pbx.Size);//保存整个窗体为图片
    g.CopyFromScreen(panel游戏区 .PointToScreen(Point.Empty), Point.Empty, panel游戏区.Size);//只保存某个控件(这里是panel游戏区)
    //bit.Save("签名.png");//默认保存格式为PNG,保存成jpg格式质量不是很好

    //保存dataGridView1截图
    //Bitmap newbitmap = new Bitmap(pbx.Width, pbx.Height);
    //pbx.DrawToBitmap(newbitmap, new Rectangle(0, 0, newbitmap.Width, newbitmap.Height));
    //newbitmap.Save("签名pbx.DrawToBitmap.png"); 

读取指纹文件图片,加载在picturebox中

 /// <summary>
  /// 创建画布的画板背景
  /// </summary>
  Bitmap backgroundImage = null;
  
  //this.pbx.BackgroundImage = System.Drawing.Image.FromFile(tempPath);
  using (FileStream ms = File.OpenRead(tempPath))
  {
      //File.WriteAllBytes("Fingerprint222.bmp", File.ReadAllBytes("11.png"));
      //File.WriteAllBytes("Fingerprint.bmp", imageBufFingerprint);

      //解决内存异常问题,以及this.pbx.BackgroundImage = System.Drawing.Image.FromStream(ms)导致的一般性gdi+ 问题
      using (Bitmap bt = new Bitmap(ms))
      {
          backgroundImage = new Bitmap(bt.Width, bt.Height);
          //Graphics g = pbx.CreateGraphics();
          Graphics g = Graphics.FromImage(backgroundImage);
          //g.DrawLine(Pens.Black, startPoint, e.Location);
          //g.Clear(Color.White);
          //Pen myPen = new Pen(Color.Black, int.TryParse(ConfigurationManager.AppSettings["penwidth"], out int penwidth) ? penwidth : 3);
          g.SmoothingMode = SmoothingMode.AntiAlias;
          g.CompositingQuality = CompositingQuality.HighQuality;
          g.CompositingMode = CompositingMode.SourceOver;
          g.DrawImage(bt, bt.Width, bt.Height);
          //PointF pointFstart = PointToPointF(startPoint);
          //PointF pointFend = PointToPointF(e.Location);
          //g.DrawBeziers(myPen, new PointF[] { pointFstart, pointFend });
          pbx.BackgroundImage = backgroundImage;
          g.Dispose();

          //bt.Save("Fingerprint.jpg");
          //this.pbx.BackgroundImage = System.Drawing.Image.FromStream(ms);
      }
  }
  //解决提示内存异常错误
  GC.Collect();

bmp转png 设置透明度

var  imagezzRaw2Bmp=System.IO.File.ReadAllBytes("Fingerprint.bmp");
    using (Bitmap bitmap = new Bitmap(new MemoryStream(imagezzRaw2Bmp)))
    //using (Bitmap bitmap = new Bitmap("Fingerprint.bmp"))
    {
        //bitmap.MakeTransparent(Color.FromArgb(0, Color.Transparent));
        bitmap.MakeTransparent(Color.FromArgb(0, Color.White));//设置指定颜色为透明。白色
        bitmap.Save("Fingerprint.png");
        //var bitmap1 = Untils.GeneralConvert(bitmap, Color.Blue);
        //bitmap1.Save(@"01.png");
    }

bmp图片缩放问题

/// <summary>
/// 缩小比例
/// </summary>
/// <param name="originalSize"></param>
/// <param name="targetSize"></param>
/// <returns></returns>
public static Size CalculateNewSize(Size originalSize, Size targetSize)
{
    int newWidth, newHeight;
    // 如果原始宽度大于目标宽度,则按宽度比例缩放
    if (originalSize.Width > targetSize.Width)
    {
        newWidth = targetSize.Width;
        newHeight = (int)(((float)originalSize.Height) * (float)((float)targetSize.Width / (float)originalSize.Width));
    }
    // 如果原始高度大于目标高度,则按高度比例缩放
    else if (originalSize.Height > targetSize.Height)
    {
        newHeight = targetSize.Height;
        newWidth = originalSize.Width * targetSize.Height / originalSize.Height;
    }
    // 如果原始尺寸小于或等于目标尺寸,则不需要缩放
    else
    {
        newWidth = originalSize.Width;
        newHeight = originalSize.Height;
    }

    return new Size(newWidth, newHeight);
}

/// <summary>
/// 放大缩小
/// </summary>
/// <param name="originalSize"></param>
/// <param name="targetSize"></param>
/// <param name="isScale"></param>
/// <returns></returns>
public static Size CalculateSize(Size originalSize, Size targetSize, bool isScale = true)
{
    int newWidth, newHeight;
    if (isScale)
    {
        // 如果原始宽度大于目标宽度,则按宽度比例缩放
        if (originalSize.Width > targetSize.Width)
        {
            newWidth = targetSize.Width;
            newHeight = originalSize.Height * targetSize.Width / originalSize.Width;
        }
        // 如果原始高度大于目标高度,则按高度比例缩放
        else if (originalSize.Height > targetSize.Height)
        {
            newHeight = targetSize.Height;
            newWidth = originalSize.Width * targetSize.Height / originalSize.Height;
        }
        // 如果原始尺寸小于或等于目标尺寸,则不需要缩放
        else
        {
            newWidth = originalSize.Width;
            newHeight = originalSize.Height;
        }
    }
    else
    {
        // 如果原始宽度大于目标宽度,则按宽度比例放大
        if (originalSize.Width < targetSize.Width)
        {
            newWidth = targetSize.Width;
            newHeight = targetSize.Height * targetSize.Width / originalSize.Width;
        }
        // 如果原始高度大于目标高度,则按高度比例缩放
        else if (originalSize.Height < targetSize.Height)
        {
            newHeight = targetSize.Height;
            newWidth = originalSize.Width * targetSize.Height / originalSize.Height;
        }
        // 如果原始尺寸小于或等于目标尺寸,则不需要缩放
        else
        {
            newWidth = originalSize.Width;
            newHeight = originalSize.Height;
        }
    }
    return new Size(newWidth, newHeight);
}


调用
  //缩小保存
  int signWidth = int.TryParse(ConfigurationManager.AppSettings["fingerprintWidth"], out int signwidth) ? signwidth : 25;
  int signHeight = int.TryParse(ConfigurationManager.AppSettings["fingerprintHeight"], out int signheight) ? signheight : 36;

  // 计算等比缩放后的尺寸
  Size newSize = Untils.CalculateNewSize(pbxFingerprint.Image.Size, new Size(signWidth, signHeight));

  using (Bitmap resizedImage = new Bitmap(pbxFingerprint.Image, newSize))
  {

      // 获取PNG图像编码器
      ImageCodecInfo imageCodecInfo = Untils.GetEncoderInfo("image/png"); //ImageCodecInfo.GetImageEncoders().Where(a=>a.MimeType== "image/png").First();
      // 设置PNG图像编码参数
      EncoderParameters encoderParameters = new EncoderParameters(1);
      EncoderParameter encoderParameter = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L); // 设置质量为100%
      encoderParameters.Param[0] = encoderParameter;

      // 保存Bitmap为PNG格式
      //bitmap.MakeTransparent(Color.FromArgb(0, Color.Transparent));
      resizedImage.MakeTransparent(Color.FromArgb(0, Color.White));//设置指定颜色为透明。白色
      resizedImage.Save(tempLocalFingerPrintPath, imageCodecInfo, encoderParameters);
  }

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/570940.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

为什么浏览器打印后会有一个undefined

问题&#xff1a; 原因&#xff1a;浏览器中调试代码&#xff0c;浏览器会默认输出打印语句返回值&#xff0c;多行调试命令返回时只执行最后一个返回值 1、这里没有打印操作&#xff0c;但是返回了1。控制台输出的是调试命令的【返回值】 2、如果调试命令本身就带有打印的语…

C系统编程:从零手搓一个shell

背景 这么久没更新就是在干这件事&#xff01;&#xff01;因为系统编程已经学的差不多了&#xff0c;所以想找几个项目练练手&#xff0c;之前就一直想写一个自己的shell&#xff01;&#xff01;现在终于有机会实现了。 首先说明一下我的操作系统&#xff1a;Arch linux 服务…

HFSS端口介绍2---波端口

前面我们讨论了Lumped Port设定相关的内容,这节我们继续讨论Wave Port(波端口)使用相关的问题。 波端口使用范围 封闭结构:如波导、同轴电缆等 包含多个传播模式的模型 端口平面在求解区域外的模型 模型中包含均匀的波导或者传输线结构 波端口的大小 对于封闭的传输线结构:边…

【C++】vector常用函数总结及其模拟实现

目录 一、vector简介 二、vector的构造 三、vector的大小和容量 四、vector的访问 五、vector的插入 六、vector的删除 简单模拟实现 一、vector简介 vector容器&#xff0c;直译为向量&#xff0c;实践中我们可以称呼它为变长数组。 使用时需添加头文件#include<v…

【御控工业物联网】JAVA JSON结构转换、JSON结构重构、JSON结构互换(5):对象To对象——转换映射方式

御控官网&#xff1a;https://www.yu-con.com/ 文章目录 御控官网&#xff1a;[https://www.yu-con.com/](https://www.yu-con.com/)一、JSON结构转换是什么&#xff1f;二、术语解释三、案例之《JSON对象 To JSON对象》四、代码实现五、在线转换工具六、技术资料 一、JSON结构…

MySQL索引为什么选择B+树,而不是二叉树、红黑树、B树?

12.1.为什么没有选择二叉树? 二叉树是一种二分查找树,有很好的查找性能,相当于二分查找。 二叉树的非叶子节值大于左边子节点、小于右边子节点。 原因: 但是当N比较大的时候,树的深度比较高。数据查询的时间主要依赖于磁盘IO的次数,二叉树深度越大,查找的次数越多,性能…

openstack-镜像封装 7

再克隆两台主机并且安装图形化组件和虚拟化组件 进入图形化界面并安装一个虚拟化管理器 根下创建一个目录&#xff0c;虚拟化管理器新添加一个路径 创建虚拟化 配置虚拟化主机 设置虚拟化主机配置 安装所需软件 清理创建云主机时安装的组件 主机安装虚拟化工具 清理虚拟化缓存 …

Mysql全局优化总结

Mysql全局优化总结 从上图可以看出SQL及索引的优化效果是最好的&#xff0c;而且成本最低&#xff0c;所以工作中我们要在这块花更多时间 服务端系统参数 官方文档&#xff1a;https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_max_connections…

x汽车登陆网站登陆rsa加密逆向

声明&#xff1a; 本文章内容仅供学习交流&#xff0c;不用于其他其他任何目的&#xff0c;严禁用于商业用途和非法用途&#xff0c;否则由此产生的一切后果均与作者无关&#xff0c; 各位看官好哇&#xff0c;今天给大家带来一篇web自动化逆向的文章&#xff0c;如下图当前我…

CMplot rMVP | 全基因组曼哈顿图和QQ图轻松可视化!

文章目录 1.CMplot1.1 CMplot介绍1.2 CMplot-DEMO1.3 CMplot参数 2.rMVP2.1 rMVP介绍2.2 rMVP-DEMO2.3 rMVP参数 1.CMplot 1.1 CMplot介绍 CMplot&#xff1a;https://github.com/YinLiLin/CMplot 这是一个做全基因组对SNP可视化神器了&#xff0c;尹立林教授写的R包。主打两…

Uptime Kuma 使用指南:一款简单易用的站点监控工具

我平时的工作会涉及到监控&#xff0c;而站点是一个很重要的监控项。项目上线后&#xff0c;我们通常会将站点监控配置到云平台上&#xff0c;以检测各站点的连通性。但随着项目不断增多&#xff0c;云平台上的配额就有点捉急了。针对这个情况&#xff0c;我们可以试试这个开源…

GPT-SoVITS声音克隆训练和推理(新手教程,附整合包)

环境: Win10 专业版 GPT-SoVITS-0421 整合包 问题描述: GPT-SoVITS声音克隆如何训练和推理教程 解决方案: Zero-shot TTS: Input a 5-second vocal sample and experience instant text-to-speech conversion.零样本 TTS:输入 5 秒的人声样本并体验即时文本到语音转换…

CentOS-7安装Mysql并允许其他主机登录

一、通用设置&#xff08;分别在4台虚拟机设置&#xff09; 1、配置主机名 hostnamectl set-hostname --static 主机名2、修改hosts文件 vim /etc/hosts 输入&#xff1a; 192.168.15.129 master 192.168.15.133 node1 192.168.15.134 node2 192.168.15.136 node33、 保持服…

设计模式-00 设计模式简介之几大原则

设计模式-00 设计模式简介之几大原则 本专栏主要分析自己学习设计模式相关的浅解&#xff0c;并运用modern cpp 来是实现&#xff0c;描述相关设计模式。 通过编写代码&#xff0c;深入理解设计模式精髓&#xff0c;并且很好的帮助自己掌握设计模式&#xff0c;顺便巩固自己的c…

【架构方法论(一)】架构的定义与架构要解决的问题

文章目录 一. 架构定义与架构的作用1. 系统与子系统2. 模块与组件3. 框架与架构4. 重新定义架构&#xff1a;4R 架构 二、架构设计的真正目的-别掉入架构设计的误区1. 是为了解决软件复杂度2. 简单的复杂度分析案例 三. 案例思考 本文关键字 架构定义 架构与系统的关系从业务逻…

【亲测有用】idea2024.1中前进后退按钮图标添加

idea更新后&#xff0c;前进后退按钮消失了&#xff0c;现在说下怎么设置 具体操作如下&#xff1a; 1、选择 File / Settings(windows版)&#xff0c;或者Preferences(mac版) 2、打开 Appearance & Behavior 并选择 Menus and Toolbars 3、选择右侧的 “Main toolbar lef…

第四百七十七回

文章目录 1. 知识回顾2. 使用方法2.1 源码分析2.2 常用属性 3. 示例代码4. 内容总结 我们在上一章回中介绍了"Get包简介"相关的内容&#xff0c;本章回中将介绍GetMaterialApp组件.闲话休提&#xff0c;让我们一起Talk Flutter吧。 1. 知识回顾 我们在上一章回中已经…

C++:模板(初级)

hello&#xff0c;各位小伙伴&#xff0c;本篇文章跟大家一起学习《C&#xff1a;模板&#xff08;初级&#xff09;》&#xff0c;感谢大家对我上一篇的支持&#xff0c;如有什么问题&#xff0c;还请多多指教 &#xff01; 如果本篇文章对你有帮助&#xff0c;还请各位点点赞…

Docker 网络与资源控制

一 Docker 网络实现原理 Docker使用Linux桥接&#xff0c;在宿主机虚拟一个Docker容器网桥(docker0)&#xff0c;Docker启动一个容器时会根 据Docker网桥的网段分配给容器一个IP地址&#xff0c;称为Container-IP&#xff0c;同时Docker网桥是每个容器的默 认网关。因为在同…