首页 > 编程语言 >C# 获取指定固定范围内的比例固定的实际图片大小

C# 获取指定固定范围内的比例固定的实际图片大小

时间:2022-12-14 18:35:19浏览次数:41  
标签:C# Image pic Height Width imageHeight 固定 imageWidth 图片大小

Rectangle? getImageRegion(PictureBox pic)
        {
            if (pic.Image == null)
                return null;

            var picHeight = pic.Width * pic.Image.Height / pic.Image.Width;
            if (picHeight > pic.Height)
            {
                var imageHeight = pic.Height;
                var imageWidth = imageHeight * pic.Image.Width / pic.Image.Height;
                return new Rectangle((pic.Width - imageWidth) / 2, (pic.Height - imageHeight) / 2, imageWidth, imageHeight);
            }
            else
            {
                var imageWidth = pic.Width;
                var imageHeight = imageWidth * pic.Image.Height / pic.Image.Width;
                return new Rectangle((pic.Width - imageWidth) / 2, (pic.Height - imageHeight) / 2, imageWidth, imageHeight);
            }
        }

 

标签:C#,Image,pic,Height,Width,imageHeight,固定,imageWidth,图片大小
From: https://www.cnblogs.com/nanfei/p/16982918.html

相关文章

  • 基于Sharding-Jdbc 实现的读写分离实现
    1.pom文件依赖<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.2.2.RELEASE</version......
  • Elasticsearch+Logstash+Kiabana 日志管理
       日志是分析线上问题的重要手段,通常我们会把日志输出到控制台或者本地文件中,排查问题时通过根据关键字搜索本地日志,但越来越多的公司,项目开发中采用分布式的架构,日......
  • HttpURLConnection Authorization 取得问题
    HttpURLConnection.setRequestProperty("Authorization","Y2U0ZDQyY2QtNDE");//设置AuthorizationHttpURLConnection.getRequestProperty("Authorization");//无法取......
  • CSS pointer-events 属性
    pointer-events属性用于设置元素是否对鼠标事件做出反应。CSS语法pointer-events:auto|none;属性值属性值描述auto默认值,设置该属性链接可以正常点击访问。......
  • 使用Power Automate设置定时任务,调用Action
    使用PowerAutomate设置定时任务,调用Action前言使用PowerAutomate设置定时任务,调用的Action是我之前写的那边文章中的Action,附文章:创建自定义Action(全局)1.打开PowerAu......
  • CentOS7更换国内的yum源
    前言CentOS有个很方便的软件安装工具yum,但是默认安装完CentOS,系统里使用的是国外的CentOS更新源,这就造成了我们使用默认更新源安装或者更新软件时速度很慢的问题,甚至更新失......
  • 《ASP.NET Core 6 框架揭秘》第五章读书笔记 - 配置选项(上)
    5.1读取配置信息.NET的配置支持多样化的数据源。内存变量、环境变量、命令行参数及各种格式的配置文件都可以作为配置的数据来源。 5.1.1编程模型三要素从编程层面......
  • CSS变量
    /*全局变量保存的地方*/:root{--main-bg-color:red;/*变量名必须以--开头*/}var(custom-property-name,value)值描述custom-property-name必需。自定......
  • pycharm SSH远程连接服务器
    开始连接首先呢,我们思考两个问题。为什么项目在自己的PC上,但却能在服务器上运行呢?那是因为服务器上也有一个和你PC上的项目一模一样的项目。那么,问题又来了,为什么我修改......
  • How can I get an entiity by id and include navigation
    HowcanIgetanentiitybyidandincludenavigationTogetanentitybyitsIDandincludeitsnavigationproperties,youcanusetheIncludemethodinEnti......