C#快速获取JPG图片大小及英寸分辨率

实验五-jpg解码 一、实验原理 1.jpg编码 JPEG(Joint Photographic Experts Group),文件后缀名为.jpg,.jpeg,是一种常用的图像文件格式。采用有损压缩方式去除冗余的图像和彩色数据,在获得极高压缩率的同时能展现十分丰富生动的图像。 编码过程如图示: 解码为编码的逆过程。 2.jpg文件格式 jpeg文件以Segment的形式组织,均以0xFF开始,后面跟1 阅读详情
        public static int getJpgSize(string FileName, out Size JpgSize, out float Wpx, out float Hpx)
        {//C#快速获取JPG图片大小及英寸分辨率
            JpgSize = new Size(0, 0);
            Wpx = 0; Hpx = 0;
            int rx = 0;
            if (!File.Exists(FileName)) return rx;
            FileStream F_Stream = File.OpenRead(FileName);
            int ff = F_Stream.ReadByte();
            int type = F_Stream.ReadByte();
            if (ff != 0xff || type != 0xd8)
            {//非JPG文件
                F_Stream.Close();
                return rx;
            }
            long ps = 0;
            do
            {
                do
                {
                    ff = F_Stream.ReadByte();
                    if (ff < 0) //文件结束
                    {
                        F_Stream.Close();
                        return rx;
                    }
                } while (ff != 0xff);

                do
                {
                    type = F_Stream.ReadByte();
                } while (type == 0xff);

                //MessageBox.Show(ff.ToString() + "," + type.ToString(), F_Stream.Position.ToString());
                ps = F_Stream.Position;
                switch (type)
                {
                    case 0x00:
                    case 0x01:
                    case 0xD0:
                    case 0xD1:
                    case 0xD2:
                    case 0xD3:
                    case 0xD4:
                    case 0xD5:
                    case 0xD6:
                    case 0xD7:
                        break;
                    case 0xc0: //SOF0段
                        ps = F_Stream.ReadByte() * 256;
                        ps = F_Stream.Position + ps + F_Stream.ReadByte() - 2; //加段长度

                        F_Stream.ReadByte(); //丢弃精度数据
                        //高度
                        JpgSize.Height = F_Stream.ReadByte() * 256;
                        JpgSize.Height = JpgSize.Height + F_Stream.ReadByte();
                        //宽度
                        JpgSize.Width = F_Stream.ReadByte() * 256;
                        JpgSize.Width = JpgSize.Width + F_Stream.ReadByte();
                        //后面信息忽略
                        if (rx!=1 && rx < 3) rx = rx + 1;
                        break;
                    case 0xe0: //APP0段
                        ps = F_Stream.ReadByte() * 256;
                        ps = F_Stream.Position + ps + F_Stream.ReadByte() - 2; //加段长度

                        F_Stream.Seek(5,SeekOrigin.Current); //丢弃APP0标记(5bytes)
                        F_Stream.Seek(2,SeekOrigin.Current); //丢弃主版本号(1bytes)及次版本号(1bytes)
                        int units=F_Stream.ReadByte(); //X和Y的密度单位,units=0:无单位,units=1:点数/英寸,units=2:点数/厘米

                        //水平方向(像素/英寸)分辨率
                        Wpx=F_Stream.ReadByte()*256;
                        Wpx=Wpx+F_Stream.ReadByte();
                        if (units == 2) Wpx = (float)(Wpx * 2.54); //厘米变为英寸
                        //垂直方向(像素/英寸)分辨率
                        Hpx = F_Stream.ReadByte() * 256;
                        Hpx = Hpx + F_Stream.ReadByte();
                        if (units == 2) Hpx = (float)(Hpx * 2.54); //厘米变为英寸
                        //后面信息忽略
                        if (rx!=2 && rx<3) rx = rx + 2;
                        break;

                    default: //别的段都跳过////////////////
                        ps = F_Stream.ReadByte() * 256;
                        ps = F_Stream.Position + ps + F_Stream.ReadByte() - 2; //加段长度
                        break;
                }
                if (ps + 1 >= F_Stream.Length) //文件结束
                {
                    F_Stream.Close();
                    return rx;
                }
                F_Stream.Position = ps; //移动指针
            } while (type != 0xda); // 扫描行开始
            F_Stream.Close();
            return rx;
        }

 

Imatest SFRplus模块:自动化图像质量分析的全面指南 本文全面解析Imatest SFRplus模块在自动化图像质量分析中的应用,涵盖从测试准备到关键指标解读的全流程。SFRplus模块通过智能识别测试卡区域,大幅提升相机清晰度、色彩和畸变检测效率,特别适合相机研发、质检和摄影爱好者。文章详细介绍了MTF曲线、色差分析和批量测试等核心功能,帮助用户快速掌握这一强大的图像质量评估工具。 阅读详情

相关推荐

C#快速读取图片大小

根据图片格式定义,实现快速读取图的分辨率大小,支持 jpg、png、gif、bmp四种格式图片格式。此类未做全面测试,当遇到不能处理的图片,会用.Net自带的Iamage类进行读取。

C# 如何获得文件(图片)的大小

想了很多方法,最后看到网友使用了字节计算的方法,然后自己试了一下,和Windows上的一样,日常小技巧吧        /// &lt;summary&gt; /// 得到路径下文件的大小 MB /// &lt;/summary&gt; /// &lt;param name="path"&gt;&lt;/param&gt; /// &...

echoerror的博客 1万+

在 Coze 平台工作流开发中,使用图生视频大模型需要时间比较长比如5分钟,如何解决工作流运行超时的问题以及等在视频生成以后再向下走

在 Coze 平台工作流开发中,使用图生视频大模型需要时间比较长比如5分钟,如何解决工作流运行超时的问题以及等在视频生成以后再向下走 同步的比较简单,直接在coze 工作流里面就可以搞定了,也不用写代码之类的

AI懒虫 2362

C# 快速获取图片大小以及分辨率(使用metadata-extractor)

C# 快速获取图片大小以及分辨率(使用metadata-extractor) 官网:metadata-extractor官网 安装:PM> Install-Package MetadataExtractor 注:该控件功能很多,能获取图片的基本所有信息,且速度很快,这里只使用了获取照片的大小以及分辨率 由于软件需要频繁读取JPG文件的像素以及分辨率,早期使用Image类,这个就不说了,速度是惨不忍睹。后来使用SOF0段读取,速度快是快了,但是使用一段时间后发现如果PS保存照片的时候基线不对或者其他一些

zxpei的博客 2551

你一直忽略的神器:离你最近的超强语音输入法(微信语音输入全攻略,支持全局混用)

你一直忽略的语音输入工具🎤 ,其实就在身边!无需额外软件,即可实现全局语音转文字⚡ 支持中英文混输,还能与其他输入法混合使用,聊天、办公都能高效完成,让你的输入效率轻松翻倍🚀

XiaoqiangClub的博客 959

uniapp [安卓苹果App端] - 实现集成微信一键登录及授权获取用户信息全流程源码,uniApp唤起微信客户端app实现微信授权头像昵称手机号(提供移动应用/开放平台/资质认证/签名/权限申请

uni-app,安卓Android,苹果ios,安卓app端,苹果App端,uniapp苹果安卓app,微信一键登录,uniapp项目App端实现微信登录,Uniapp实现微信授权登录,调起微信客户端授权用户信息,uniappapp端微信一键登录打开手机微信app,app端如何唤起用户本机微信应用并授权登陆,如何申请微信一键登录,uniapp实现APP微信登录流程,打开本地微信软件,接入微信登录,UniApp实现微信登录教程,获取头像昵称手机号用户数据,超详细实现微信登录功能,唤起没反应,授权失败,获取

🏆 前端领域优质创作者 1万+

【转】C#快速获取JPG图片大小及英寸分辨率

 //C#快速获取JPG图片大小及英寸分辨率        public static int getJpgSize(string FileName, out Size JpgSize, out float Wpx, out float Hpx)        {//C#快速获取JPG图片大小及英寸分辨率            JpgSize = new Size(0, 0);        

qqqwwwwww的专栏 3481

复现论文《基于Retinex理论和深度学习的低照度图像增强算法研究》

本研究提出两种基于Retinex理论和深度学习的低照度图像增强算法。第一种算法在HSV色彩空间中进行处理,采用Res2Block和CBAM-Res2block模块增强多尺度特征表示;第二种算法使用多尺度残差U型网络结构。复现代码展示了Res2Block、CBAM注意力机制等核心模块的实现,包括多尺度特征提取、通道和空间注意力机制。实验结果表明,所提算法能有效解决低照度图像存在的亮度低、对比度不足、颜色失真和细节丢失等问题,显著提升图像质量。

max500600的博客 393

cefsharp 网页另存为图片_年末台历季,图片转换、压缩一步到位!

2020即将过去岁末年初又是台历印制的高峰期还在为处理大量图片犯难吗?还在为PDF与JPG导出而烦恼吗?……今天小编就为您整理一份图片处理秘籍!话不多说上干货图片压缩最佳办法问题描述将图片上传到网络时,多会显示图片过大,如何压缩且不损害图片的清晰度?以笔者多年经验来看,在PS中进行调整(降低像素),会严重影响图片清晰度。以下图为例:工具:网络地址:https://imagecompres...

weixin_42314448的博客 415

【算法】克里金kriging参数值预测模型

模型中特征值2个,目标值1个,data数据集如图所示。搭建kriging参数值预测模型。

weixin_48618536的博客 5066

关于在线excel插件Univer笔记教程

univer在线excel插件确实是够强大,但也存在不少bug,用户用起来是真的很爽,和本地的wps差不多,但真正的开发起来是真的费劲。由于文档提供的信息不足,我们很多功能只能去看他们插件里的源代码,然后一点点测试,一点点尝试研究。此文章可省去五天的研究成本

guiplan 5833

.net npoi xssfclientanchor设置图片缩放大小_【后期修图】PS的图像大小命令

请转到菜单栏中的“图像”菜单,然后选择“图像大小”。您也可以通过按Ctrl + Alt + I(Win)/Command + Option + I(Mac)从键盘打开它在Photoshop CC中,“图像大小”对话框在左侧显示预览窗口,以及用于查看和更改右侧图像大小的选项新图像预览窗口Adobe在Photoshop CC中重新设计了“图像大小”对话框,最大的变化是新的预览窗口。无论...

weixin_30995429的博客 2543

一篇文章足够你学习Bluez,提供史上最全的Bluez教程,让你告别Bluez从入门到放弃

Bluez是真的难,说“入门到放弃”真的毫不夸张,Bluez的学习曲线陡峭,要求对Linux 系统/驱动概念、D-Bus 通信和蓝牙协议都有要求,加上网络上其实没有一个完整的介绍Bluez系列的文档,所以不管是蓝牙初学者还是蓝牙从业人员,都有不小的难度。

朝气蓬勃 2556

获取图片大小

获取经过页面渲染的图片的大小 //图片加载完之后... $('#preview').on('load',function(){ //获取图片的宽度和高度 picWidth = $('#preview').width();//图片的宽度 picHeight = $('#preview').height();//图片的长度 })需要注意的是这段

Omeletteyang的博客 614

Apache DolphinScheduler 实现了对 OceanBase 的元数据库支持

Apache DolphinScheduler 是一款开源的分布式工作流任务调度系统,它提供了可视化的工作流设计和调度功能,支持大数据任务的自动化调度和监控。最近的更新中,Apache DolphinScheduler 引入了对 OceanBase 数据库的元数据库支持,这为用户在大数据环境中管理和调度任务提供了更多选择。用户可以通过 DolphinScheduler 提供的可视化界面进行工作流的设计和调度,也可以通过 DolphinScheduler 提供的 API 进行任务的编程调度。

VavzNvml的博客 508

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

C# 快速获得 图像大小

简单说来,就是用 Stream,这样不用把整个文件 Load 到 Image 里,自带的 API 接口里,估计会从流头里就得到 文件的大小了。对比了 Image.FromFile(file) 的方法,用流的方法,快了250倍。

voiue的博客 3179

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

C# 获取图片宽与高

获取网络图片宽与高 获取本地图片宽与高

高级项目经理、专注于技术架构、分享项目管理及职场心得 6621

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

c#获取网络图片宽高,c#获取网上图片宽高,c#获取图片宽高,c#获取本地图片宽高

c#获取网络图片宽高,c#获取网上图片宽高,c#获取图片宽高,c#获取本地图片宽高

橙-极纪元-JJYCheng 1590

c# 图像读取几种方法

使用C#进行图像处理的几种方法 本文讨论了C#图像处理中Bitmap类、BitmapData类和unsafe代码的使用以及字节对齐问题。 Bitmap类 命名空间:System.Drawing 封装 GDI+ 位图,此位图由图形图像及其属性的像素数据组成。Bitmap 是用于处理由像素数据定义的图像的对象。  该类的主要方法和属性如下: 1.       GetPixel方法和 S

语帆的专栏 2903

C#快速获取图像尺寸和分辨率(使用MagickImage)

我感觉在CSDN上写文章,我就和这个获取图片尺寸和分辨率杠上了 之前写过两篇文章,分别使用shell32文章链接和metadata-extractor文章链接来获取图像尺寸和分辨率,但是都不如人意。。 开始使用Image类,速度就不多说了。用过的人都知道,特别是大照片 然后使用SOF0段读取,但是会遇到很多图片尺寸读不出来(比如PS保存的时候基线选择连续) 接着使用metadata-extractor,读取尺寸没问题,但是遇到基线为连续的图片,速度惨不忍睹。比系统的Image类还慢 最后又使用shell32

zxpei的博客 8883
上一篇: lua元表详解
下一篇: Unity3D -- 质量设置(Quality Settings)
Le_Sam
博客等级 码龄11年 342粉丝 53原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值