2016-12-23 2 views
0

私はGraphics2DFrameライブラリで非常に新しいです。私はオブジェクトにpdfを描画するためにPDFRendererPDFBoxライブラリから)を試していました。コードは次のとおりです。グラフィックスオブジェクトでフレームに描画されたすべてのストローク/四角形を取得する方法は?

import java.awt.*; 
import java.awt.event.*; 
import java.io.File; 
import java.io.IOException; 

import org.apache.pdfbox.pdmodel.PDDocument; 
import org.apache.pdfbox.rendering.PDFRenderer; 
public class Example01 extends Frame { 
    /** 
    * Instantiates an Example01 object. 
    **/ 
    public static void main(String args[]) { 
    new Example01(); 
    } 
    /** 
    * Our Example01 constructor sets the frame's size, adds the 
    * visual components, and then makes them visible to the user. 
    * It uses an adapter class to deal with the user closing 
    * the frame. 
    **/ 
    public Example01() { 
    //Title our frame. 
    super("Java 2D Example01"); 
    //Set the size for the frame. 
    setSize(1000,1000); 
    //We need to turn on the visibility of our frame 
    //by setting the Visible parameter to true. 
    setVisible(true); 
    //Now, we want to be sure we properly dispose of resources 
    //this frame is using when the window is closed. We use 
    //an anonymous inner class adapter for this. 
    addWindowListener(new WindowAdapter() 
     {public void windowClosing(WindowEvent e) 
     {dispose(); System.exit(0);} 
     } 
    ); 
    } 
    /** 
    * The paint method provides the real magic. Here we 
    * cast the Graphics object to Graphics2D to illustrate 
    * that we may use the same old graphics capabilities with 
    * Graphics2D that we are used to using with Graphics. 
    **/ 
    public void paint(Graphics g) { 
    Graphics2D g2d = (Graphics2D)g; 
    try (PDDocument document = PDDocument.load(new File("C:\\Users\\prabhjot.rai\\Desktop\\xceligent\\9542899.pdf"))) 
    { 
     PDFRenderer pdfRenderer = new PDFRenderer(document); 
     pdfRenderer.renderPageToGraphics(1, g2d); 
     System.out.println(g2d.getStroke()); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 


    } 
} 

これは、pdf全体を見ることができるフレームを作成します。グラフィックスオブジェクトを使用して、フレーム内に描かれたストロークを取得しようとしています。どうすれば入手できますか?私のメソッドpdfRenderer.renderPageToGraphics(1, g2d)にはGraphics2Dオブジェクトだけが必要なので、私はフレーム以外のライブラリを使用しています。

答えて

0

これはできません。

Graphics2Dはイメージベースのグラフィックツールです。つまり、すべてのアクションがイメージに描画され、忘れられた場合、結果のピクセルのみが保存されます。

機能getStroke()は、描画方法のいずれかを使用するときに使用される現在のストロークのみを返します。

多くのgrahpicsフレームワークでは、ノードのベースで図形や図形を描画することができ、画像の一部を分解したり変更したりすることができます(JavaFXなど)。

関連する問題