ABCpdf.NET中Rect,Bottom,Height的關係

來源:互聯網
上載者:User

標籤: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隨之變化

沒有查看源碼,根據結果總結以上結論,對我當前的需求是使用的。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.