曾經有人給我了一張jpg,是1024*1024大小,檔案大小為99kb,做了個金字塔,各層影像大小如下:單位kb
我產生的jpg金字塔 為經過任何加工
height256 46.2kb
height512 162kb
height1024 557kb
Photoshop產生的jpg金字塔 為經過任何加工
height256 48kb
height512 90kb
height1024 163kb
可以看出這個映像大小差異太大了,我可是百思不得其解,最終看了上面那篇博文後,通過擷取中繼資料的方式來看看原因:
擷取中繼資料函數
複製代碼 代碼如下:public void GetProperty()
{
Bitmap myImage1024 = new Bitmap(@"E:\myjpg\height.jpg");
foreach (PropertyItem property in myImage1024.PropertyItems)
{
StringBuilder sb=new StringBuilder();
Byte[] sbbyte = (Byte[])property.Value;
sb.AppendFormat("ID:{0},Length:{1},Type:{2};\n",
property.Id.ToString(), property.Len.ToString(), property.Type.ToString(),);
Console.Write(sb);
}
}
發現我產生的jpg和原始圖片的中繼資料是不同的
height1024:
ID:771,Length:1,Type:1; 頭資訊Tag解釋:303 PropertyTagSRGBRenderingIntent
ID:769,Length:8,Type:5; 頭資訊Tag解釋:301 PropertyTagGamma
ID:20752,Length:1,Type:1; 頭資訊Tag解釋:5110 PropertyTagPixelUnit 解析度
ID:20753,Length:4,Type:4; 頭資訊Tag解釋:5111 PropertyTagPixelPerUnitX
ID:20754,Length:4,Type:4; 頭資訊Tag解釋:5112 PropertyTagPixelPerUnitY
height:
ID:20625,Length:128,Type:3;頭資訊Tag解釋:5091 PropertyTagChrominanceTable
ID:20624,Length:128,Type:3; 頭資訊Tag解釋:5090 PropertyTagLuminanceTable
原來如此,這樣我們就知道為什麼jpg竟然不一樣大小了,那好吧,我就修改了產生了影像金字塔的方法:在儲存金字塔之前,把他們的頭資訊去掉。之後驚奇的發現:我產生的影像金字塔的最精細層和原始映像一樣大小了!。
去除影像中繼資料的方法:
複製代碼 代碼如下:public void RemoveProperty()
{
Bitmap myImage1024 = new Bitmap(@"E:\myjpg\height.jpg");
foreach (PropertyItem property in myImage1024.PropertyItems)
{
myImage1024.RemovePropertyItem(property.Id);
}
myImage1024.Save(@"E:\myjpg\nopro.jpg");
}