標籤:style blog http color 使用 2014 ar 代碼
因為項目需要新功能,要在一個圖片的上下加上固定高度的白邊如。項目中一直使用ABCpdf.NET處理圖片,但我一直沒有做這方面的功能,所以找來API參考做。
這個簡單需求做的過程中出現了一些曲折,主要是ABCpdf.NET的座標體系和想象中的不一樣。
它座標系不同於Windows所用的左上為原點的座標系, 它是採用左下為座標原點的(可以通過設定Doc的TopDown為true來改變原點的位置)。Doc.Rect屬性很重要, 如果要輸出什麼對象的話, 都是輸出到Rect所指定的矩形範圍內,Rect的值在操作過程中不斷被覆蓋更新,但是之前加入的對象的位置不受影響。
對於我需要加入對象的位置主要受以下屬性影響Rect,Bottom,Height
Doc theDoc = new Doc(); //theDoc.Rect= "0 0 612 792" theDoc.Rect.Height = 792.0 XImage theImg = new XImage(); theImg.SetFile("MBC140448XX-HF02-0101bl.tif"); theDoc.Rect.Left = 0; theDoc.Rect.Bottom = 27; // theDoc.Rect = "0 27 612 792" theDoc.Rect.Height=765 theDoc.Rect.Width = theImg.Width; //theImg.Width = 1200 theDoc.Rect = "0 27 1200 792" theDoc.Rect.Height=765 theDoc.Rect.Height = theImg.Height;//theImg.Height = 1200 theDoc.Rect = "0 27 1200 777" theDoc.Rect.Height=750 theDoc.AddImageObject(theImg, false); theDoc.Rect.Height = theImg.Height + 27; //theDoc.Rect= "0 27 1200 804" theDoc.Rect.Height = 777.0 theDoc.Rect.Left = 0; theDoc.Rect.Bottom = 0; //theDoc.Rect= "0 0 1200 804" theDoc.Rect.Height = 804.0 theDoc.Rendering.Save("out.tif"); theDoc.Clear();
以上代碼後面注釋的值都是本行語句執行後的結果。通過以上結果分析,總結得到下面規律。本段代碼主要是對Y方向的操作,所以主要考慮Rect = {X, Y, W, H}的Rect.H,Bottom,Height.
Rect.H = Bottom+Height
- theDoc.Rect.Bottom = 27 Bottom變化,Rect.Y隨之變化,Rect.H沒有變化,但是Height變了(Height=792-27=765,原始預設值792).所以,Bottom變,Rect.H不變,Height變
- theDoc.Rect.Height = theImg.Height; Height變化,Rect.H隨之變化,Rect.H = Bottom + Height=27+750=777. 所以,Bottom不變,Height變,Rect.H隨之變化
沒有查看源碼,根據結果總結以上結論,對我當前的需求是使用的。