技术标签: navicat git svg nagios less
最近需要用到TIF格式的文件,研究了一段时间,终于有点结果了,
发现两种方式,第一种是使用BitMiracle.LibTiff.NET,直接在Nuget上安装即可
,第二种是使用RasterEdge.DocImageSDK,要从官网下载dll包
第一种免费,但是生成的tiff文件大小比原始图片大的多
第二种收费,但是有试用期一个月,效果很好,生成的tiff文件比原图小的多而且不失真。过期之后,只需要到官网下载最新dll,重新引用即可再来一个月试用。。。
先说第二种RasterEdge.DocImageSDK的使用方法:
官网地址:http://www.rasteredge.com/how-to/csharp-imaging/tiff-convert-bmp/
//过期后打开上面 这个网址,重新下载 dll包,重新引用即可 bin x64 4.0
新建一个cmd项目,测试代码如下:
class Program
{
private static byte[] CompressionImage(Stream fileStream, long quality)
{
using (System.Drawing.Image img = System.Drawing.Image.FromStream(fileStream))
{
using (Bitmap bitmap = new Bitmap(img))
{
ImageCodecInfo CodecInfo = GetEncoder(img.RawFormat);
System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;
EncoderParameters myEncoderParameters = new EncoderParameters(1);
EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, quality);
myEncoderParameters.Param[0] = myEncoderParameter;
using (MemoryStream ms = new MemoryStream())
{
bitmap.Save(ms, CodecInfo, myEncoderParameters);
myEncoderParameters.Dispose();
myEncoderParameter.Dispose();
return ms.ToArray();
}
}
}
}
private static ImageCodecInfo GetEncoder(ImageFormat format)
{
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();
foreach (ImageCodecInfo codec in codecs)
{
if (codec.FormatID == format.Guid)
{ return codec; }
}
return null;
}
static void Main(string[] args)
{
string[] imagePaths = System.IO.Directory.GetFiles(@"D:\images\","*.jpg");
Bitmap[] bmps = new Bitmap[imagePaths.Count()];
for (int i = 0; i < imagePaths.Length; i++)
{
var stream = new FileStream(imagePaths[i], FileMode.Open);
var by = CompressionImage(stream, 100);
stream.Close();
Bitmap tmpBmp = new Bitmap(new MemoryStream(by));
if (tmpBmp != null)
bmps[i] = tmpBmp;
}
ImageOutputOption option = new ImageOutputOption() { Color = ColorType.Color, Compression = ImageCompress.CCITT };
TIFFDocument tifDoc = new TIFFDocument(bmps, option);
if (tifDoc == null)
throw new Exception("Fail to construct TIFF Document");
tifDoc.Save(@"D:\images\test.tif");
}
}
下面说说第二种免费的方式:
新建一个TiffHelper帮助类:
using BitMiracle.LibTiff.Classic;
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
namespace JpgToTiff
{
public class UserErrorHandler : TiffErrorHandler
{
public override void WarningHandler(Tiff tif, string method, string format, params object[] args)
{
//base.WarningHandler(tif, method, format, args);
}
public override void WarningHandlerExt(Tiff tif, object clientData, string method, string format, params object[] args)
{
//base.WarningHandlerExt(tif, clientData, method, format, args);
}
}
public class TiffHelper
{
public static UserErrorHandler m_errorHandler = new UserErrorHandler();
static TiffHelper()
{
Tiff.SetErrorHandler(m_errorHandler);
}
/// <summary>
/// 合并jpg
/// </summary>
/// <param name="bmps">bitmap数组</param>
/// <param name="tiffSavePath">保存路径</param>
/// <param name="quality">图片质量,1-100</param>
/// <returns></returns>
public static bool Jpegs2Tiff(Bitmap[] bmps, string tiffSavePath, int quality = 15)
{
try
{
MemoryStream ms = new MemoryStream();
using (Tiff tif = Tiff.ClientOpen(@"in-memory", "w", ms, new TiffStream()))
{
foreach (var bmp in bmps)//
{
byte[] raster = GetImageRasterBytes(bmp, PixelFormat.Format24bppRgb);
tif.SetField(TiffTag.IMAGEWIDTH, bmp.Width);
tif.SetField(TiffTag.IMAGELENGTH, bmp.Height);
tif.SetField(TiffTag.COMPRESSION, Compression.JPEG);
tif.SetField(TiffTag.PHOTOMETRIC, Photometric.RGB);
tif.SetField(TiffTag.JPEGQUALITY, quality);
tif.SetField(TiffTag.ROWSPERSTRIP, bmp.Height);
tif.SetField(TiffTag.XRESOLUTION, 90);
tif.SetField(TiffTag.YRESOLUTION, 90);
tif.SetField(TiffTag.BITSPERSAMPLE, 8);
tif.SetField(TiffTag.SAMPLESPERPIXEL, 3);
tif.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG);
int stride = raster.Length / bmp.Height;
ConvertSamples(raster, bmp.Width, bmp.Height);
for (int i = 0, offset = 0; i < bmp.Height; i++)
{
tif.WriteScanline(raster, offset, i, 0);
offset += stride;
}
tif.WriteDirectory();
}
System.IO.FileStream fs = new FileStream(tiffSavePath, FileMode.Create);
ms.Seek(0, SeekOrigin.Begin);
fs.Write(ms.ToArray(), 0, (int)ms.Length);
fs.Close();
return true;
}
}
catch (Exception ex)
{
return false;
}
}
private static byte[] GetImageRasterBytes(Bitmap bmp, PixelFormat format)
{
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
byte[] bits = null;
try
{
BitmapData bmpdata = bmp.LockBits(rect, ImageLockMode.ReadWrite, format);
bits = new byte[bmpdata.Stride * bmpdata.Height];
System.Runtime.InteropServices.Marshal.Copy(bmpdata.Scan0, bits, 0, bits.Length);
bmp.UnlockBits(bmpdata);
}
catch
{
return null;
}
return bits;
}
private static void ConvertSamples(byte[] data, int width, int height)
{
int stride = data.Length / height;
const int samplesPerPixel = 3;
for (int y = 0; y < height; y++)
{
int offset = stride * y;
int strideEnd = offset + width * samplesPerPixel;
for (int i = offset; i < strideEnd; i += samplesPerPixel)
{
byte temp = data[i + 2];
data[i + 2] = data[i];
data[i] = temp;
}
}
}
}
}
下面是测试代码:
class Program
{
private static byte[] CompressionImage(Stream fileStream, long quality)
{
using (System.Drawing.Image img = System.Drawing.Image.FromStream(fileStream))
{
using (Bitmap bitmap = new Bitmap(img))
{
ImageCodecInfo CodecInfo = GetEncoder(img.RawFormat);
System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;
EncoderParameters myEncoderParameters = new EncoderParameters(1);
EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, quality);
myEncoderParameters.Param[0] = myEncoderParameter;
using (MemoryStream ms = new MemoryStream())
{
bitmap.Save(ms, CodecInfo, myEncoderParameters);
myEncoderParameters.Dispose();
myEncoderParameter.Dispose();
return ms.ToArray();
}
}
}
}
private static ImageCodecInfo GetEncoder(ImageFormat format)
{
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();
foreach (ImageCodecInfo codec in codecs)
{
if (codec.FormatID == format.Guid)
{ return codec; }
}
return null;
}
static void Main(string[] args)
{
string[] imagePaths = System.IO.Directory.GetFiles(@"D:\images\","*.jpg");
Bitmap[] bmps = new Bitmap[imagePaths.Count()];
for (int i = 0; i < imagePaths.Length; i++)
{
var stream = new FileStream(imagePaths[i], FileMode.Open);
var by = CompressionImage(stream, 100);
stream.Close();
Bitmap tmpBmp = new Bitmap(new MemoryStream(by));
if (tmpBmp != null)
bmps[i] = tmpBmp;
}
TiffHelper.Jpegs2Tiff(bmps, @"D:\images\test.tif", 100);
}
}
可以看到,两个方式生成的tif文件大小简直天壤之别。。。
7个原图大小4.8M,第一种1.36M,
第二种直接23.5M…
也可能是我没有弄好压缩方式。。。。
那我就不晓得了。
如果喜欢,点个赞呗
文章浏览阅读3.1k次。1. 打开配置文件Mac 如下图2. 在文件内部添加这段文字,就可以了:"update_check":false _mac sublime text 取消更新提示
文章浏览阅读548次,点赞10次,收藏6次。Linux系统下DNS配置指南_linux 服务器修改网络dns
文章浏览阅读779次,点赞19次,收藏24次。springboot微信小程序的小疾病问诊服务系统的设计与实现。springboot基于spring的物业管理系统的设计与实现。springboot基于Java的高校学生请假系统。ssm基于Android的购物商场APP设计与实现。springboot基于微信小程序的智慧校园系统。ssm基于Android的英语词典的设计与开发。ssm基于SSM+Vue的学生实践管理平台开发。ssm基于android的企业员工考勤系统。ssm基于web的暗香小店系统的设计与实现。ssm基于Web的高等学校公费医疗管理系统。
文章浏览阅读2.3w次,点赞15次,收藏63次。hover属性用不同的书写方式,来改变不同关系的元素样式。元素:hover 表示聚焦后改变自己元素:hover 元素 表示聚焦后改变其子元素元素:hover + 元素 表示聚焦后改变其指定的“亲兄弟”(条件是该兄弟元素与其相邻)元素元素:hover ~ 元素 表示聚焦后改变其指定的兄弟元素,两个元素相不相邻都行。示例:.first:hover {color: white;}/* 聚焦我改变自己 */.three:hover .three-son {font-size: 20px._css hover的用法
文章浏览阅读6k次,点赞3次,收藏15次。coursera-斯坦福-机器学习-吴恩达-第8周笔记-无监督学习coursera-斯坦福-机器学习-吴恩达-第8周笔记-无监督学习1聚类算法clutering1聚类算法简介2K-means21kmeans的目标函数22随机初始化23选择类别数3考试quiz维数约减 dimensionality reduction1数据压缩2数据可视化3维度约简-主成分分析法PCA1 PCA_pca反向压缩
文章浏览阅读5.2k次。一、插件安装Vundle是vim的一个插件管理器, 同时它本身也是vim的一个插件。插件管理器用于方便、快速的安装、删除、Vim更新插件。mkdir -p ~/.vim/bundlegit clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim管理器安装完成后,vim ~/.vimrc命令创建.vimrc文件syntax on" tab宽度和缩进同样设置为4set tabstop=4set softta_bxbx.vim
文章浏览阅读226次,点赞2次,收藏3次。本项目设计了一款可以触摸控制的天气显示器。主要由Wemos D1 Mini Pro和TFT显示屏组成,利用Wemos D1 Mini Pro作为设备的主控芯片,发出Wi-Fi信号并接收相应指令,通过调用API将接收到的信息传输到TFT显示屏,TFT显示屏将接收到的信息显示出来。该天气显示器实现对所在地区当前的时间与日期;当日的天气信息,如温度、压力、湿度、降雨量;七天的未来预测等功能的显示。设计采用Wemos D1 Mini Pro,利用API将实时获取的天气信息,通过TFT显示屏显示出来。_arduino wemos d1 mini
文章浏览阅读653次。public void initDiffDisplay() { try { DisplayManager displayManager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE); Display[] presentationDisplays = displayManager.getDisplays(); if (presentationDi._android service 检测是否双屏
文章浏览阅读530次,点赞23次,收藏10次。springboot+mybatisplus+mysql 用户端 uniapp(vue语法)管理后台 vue+elementUi。后台服务 springboot+mybatisplus+mysql。一、我们技术使用JAVA后台服务 前后端分离。管理后台 vue+elementUi。用户端 uniapp(vue语法)适配小程序+H5+公众号。私信客服获取演示地址。私信客服获取演示地址。
文章浏览阅读3.3k次,点赞3次,收藏5次。# -*- coding: UTF-8 -*-year = int(input("输入一个年份:"))if year % 100 == 0: if year % 400 == 0: print('%d年是闰年' % year) else: print('%d年不是闰年' % year)else: if year % 4 == 0: print('%d年是闰年' % year) else: print('%d_判断闰年的python程序直接输入一个代表年份的正整数
文章浏览阅读987次,点赞20次,收藏19次。偏微分方程PDE图像去噪(含SNR)完整的代码,方可运行;可提供运行操作视频!适合小白!_pdnet 深度学习 偏微分方程 去噪
文章浏览阅读6.6w次,点赞128次,收藏962次。Ubuntu18.0详尽版安装教程下载Ubuntu18.04下载VMware Workstation安装虚拟机下载Ubuntu18.04官方网站:http://old-releases.ubuntu.com/releases/18.04.4/?_ga=2.44113060.1243545826.1617173008-2055924693.1608557140下载VMware Workstation这个在网上有很多教程下载,这里我就不写了,我用的版本是14 pro。如下图:安装虚拟机1、打开_ubuntu18安装