技术标签: 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…
也可能是我没有弄好压缩方式。。。。
那我就不晓得了。
如果喜欢,点个赞呗
文章浏览阅读1.5w次,点赞10次,收藏129次。文章目录目录模型评估评价指标1.分类评价指标acc、recall、F1、混淆矩阵、分类综合报告1.准确率方式一:accuracy_score方式二:metrics2.召回率3.F1分数4.混淆矩阵5.分类报告6.kappa scoreROC1.ROC计算2.ROC曲线3.具体实例2.回归评价指标3.聚类评价指标1.Adjusted Rand index 调整兰德系数2.Mutual Informa..._model.score
文章浏览阅读344次。因工作需要,在Apache上使用,重新学习配置mod_jk1. 分别安装Apache和Tomcat:2. 编辑httpd-vhosts.conf: LoadModule jk_module modules/mod_jk.so #加载mod_jk模块 JkWorkersFile conf/workers.properties #添加worker信息 JkLogFil_apache mod_jk 虚拟
文章浏览阅读335次。待老夫kotlin大成,扩展:MotionLayout 与 CoordinatorLayout,DrawerLayout,ViewPager 的 交互众所周知,MotionLayout 的 动画是有完成度的 即Progress ,他在0-1之间变化,一.CoordinatorLayout 与AppBarLayout 交互时,其实就是监听 offsetliner 这个 偏移量的变化 同样..._android onoffsetchanged
文章浏览阅读8.3k次,点赞3次,收藏19次。【转】多核处理器的工作原理及优缺点《处理器关于多核概念与区别 多核处理器工作原理及优缺点》原文传送门 摘要:目前关于处理器的单核、双核和多核已经得到了普遍的运用,今天我们主要说说关于多核处理器的一些相关概念,它的工作与那里以及优缺点而展开的分析。1、多核处理器 多核处理器是指在一枚处理器中集成两个或多个完整的计算引擎(内核),此时处理器能支持系统总线上的多个处理器,由总..._多核处理器怎么工作
文章浏览阅读306次。1. eclipse配置lombok 拷贝lombok.jar到eclipse.ini同级文件夹下,编辑eclipse.ini文件,添加: -javaagent:lombok.jar2. myeclipse配置lombok myeclipse像eclipse配置后,定义对象后,直接访问方法,可能会出现飘红的报错。 如果出现报错,可按照以下方式解决。 ..._eclispe每次运行个新项目都需要重新配置lombok吗
文章浏览阅读1.2w次,点赞31次,收藏126次。#注意:笔者在2021/11/11当天调试过这个代码是可用的,由于pdfminer版本的更新,网络上大多数的语法没有更新,我也是找了好久的文章才修正了我的代码,仅供学习参考。1、把pdf文件移动到本代码文件的同一个目录下,笔者是在pycharm里面运行的项目,下图中的x1文件夹存储了我需要转换成文本文件的所有pdf文件。然后要在此目录下创建一个存放转换后的txt文件的文件夹,如图中的txt文件夹。2、编写代码 (1)导入所需库# coding:utf-8import ..._python批量读取文字并批量保存
文章浏览阅读1.4k次。http://blog.csdn.net/pipisorry/article/details/52902234Scala 访问修饰符Scala 访问修饰符基本和Java的一样,分别有:private,protected,public。如果没有指定访问修饰符符,默认情况下,Scala对象的访问级别都是 public。Scala 中的 private 限定符,比 Java 更严格,在嵌套类情况下,外层_scala ===运算符
文章浏览阅读2.6k次,点赞7次,收藏19次。ER图导出为PDF或图片格式_数据库怎么导出er图
文章浏览阅读655次。CREATE OR REPLACE TRIGGER Trg_ReimFactBEFORE UPDATEON BP_OrderFOR EACH ROWDECLAREPRAGMA AUTONOMOUS_TRANSACTION;--自制事务fc varchar2(255);BEGINIF ( :NEW.orderstate = 2AND :NEW.TransState = 1 ) THENBEG..._oracle触发器更新同一张表
文章浏览阅读513次。目录概念debouncethrottle实现debouncethrottle应用场景debouncethrottle场景举例debouncethrottle概念debounce字面理解是“防抖”,何谓“防抖”,就是连续操作结束后再执行,以网页滚动为例,debounce要等到用户停止滚动后才执行,将连续多次执行合并为一次执行。throttle字面理解是“节流”,何谓“节流”,就是确保一段时..._throttle和debounce应用在哪些场景
文章浏览阅读526次。regex() $regex 正则表达式用于模式匹配,基本上是用于文档中的发现字符串 (下面有例子)注意:若未加 @Field("名称") ,则识别mongdb集合中的key名为实体类属性名。也可以对数组进行索引,如果被索引的列是数组时,MongoDB会索引这个数组中的每一个元素。也可以对整个Document进行索引,排序是预定义的按插入BSON数据的先后升序排列。save: 若新增数据的主键已经存在,则会对当前已经存在的数据进行修改操作。_java 操作mongodb
文章浏览阅读1k次。今天push代码到github仓库时出现这个报错TACKCHEN-MB0:tc-image tackchen$ git pushremote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.remote: Please see https://github.blog/2020-12-15-token-authentication_git push remote: support for password authentication was removed on august 1