Save view as jpg image [message #511215] |
Sun, 31 January 2010 11:27 |
|
hi..
i want to save my view as JPG image iam useing folling code
ScalableFreeformRootEditPart rootEditPart =
(ScalableFreeformRootEditPart)gViewer.getEditPartRegistry().
get(LayerManager.ID);
IFigure rootFigure = ((LayerManager)
rootEditPart).getLayer(LayerConstants.PRINTABLE_LAYERS);
Rectangle rootFigureBounds = rootFigure.getBounds();
Control figureCanvas = gViewer.getControl();
GC figureCanvasGC = new GC(figureCanvas);
Image img = new Image(null, rootFigureBounds.width,
rootFigureBounds.height);
GC imageGC = new GC(img);
imageGC.setBackground(figureCanvasGC.getBackground());
imageGC.setForeground(figureCanvasGC.getForeground());
imageGC.setFont(figureCanvasGC.getFont());
imageGC.setLineStyle(figureCanvasGC.getLineStyle());
imageGC.setLineWidth(figureCanvasGC.getLineWidth());
imageGC.setXORMode(figureCanvasGC.getXORMode());
Graphics imgGraphics = new SWTGraphics(imageGC);
rootFigure.paint(imgGraphics);
ImageData[] imgData = new ImageData[1];
imgData[0] = img.getImageData();
ImageLoader imgLoader = new ImageLoader();
imgLoader.data = imgData;
imgLoader.save("c:/View.jpg", SWT.IMAGE_JPEG);
figureCanvasGC.dispose();
imageGC.dispose();
img.dispose();
my view gViewer contains - x and - y values...
i am able to save the image from (0,0) cordinates can any one tell me the
how to get - ve x and y coordinate data
Thanks
Raj
|
|
|
Re: Save view as jpg image [message #511748 is a reply to message #511215] |
Tue, 02 February 2010 16:54 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
Hi,
It looks like you're essentially asking how to save your IFigure's image,
right? If so then someone on the GEF newsgroup should be able to help you.
I know that this question has already been redirected once already from
another newsgroup, but I think the title implied a different question than
what I infer from your snippet.
FWIW, I'm guessing that invoking IFigure.setBounds(0,0,width,height) would
give what you want. Are you able to do this, do the paint, and then re-set
the bounds to the previous value? Or if not, is it possible to make a copy
of the IFigure and change its bounds and paint it to the GC instead?
HTH,
Grant
"raj" <graj.83@gmail.com> wrote in message
news:hk3pek$h3b$1@build.eclipse.org...
> hi..
>
> i want to save my view as JPG image iam useing folling code
>
> ScalableFreeformRootEditPart rootEditPart =
> (ScalableFreeformRootEditPart)gViewer.getEditPartRegistry().
> get(LayerManager.ID);
> IFigure rootFigure = ((LayerManager)
> rootEditPart).getLayer(LayerConstants.PRINTABLE_LAYERS);
> Rectangle rootFigureBounds = rootFigure.getBounds();
> Control figureCanvas = gViewer.getControl();
> GC figureCanvasGC = new GC(figureCanvas);
>
> Image img = new Image(null, rootFigureBounds.width,
> rootFigureBounds.height);
> GC imageGC = new GC(img);
>
> imageGC.setBackground(figureCanvasGC.getBackground());
> imageGC.setForeground(figureCanvasGC.getForeground());
> imageGC.setFont(figureCanvasGC.getFont());
> imageGC.setLineStyle(figureCanvasGC.getLineStyle());
> imageGC.setLineWidth(figureCanvasGC.getLineWidth());
> imageGC.setXORMode(figureCanvasGC.getXORMode());
>
>
> Graphics imgGraphics = new SWTGraphics(imageGC);
> rootFigure.paint(imgGraphics);
> ImageData[] imgData = new ImageData[1];
> imgData[0] = img.getImageData();
> ImageLoader imgLoader = new ImageLoader();
> imgLoader.data = imgData;
> imgLoader.save("c:/View.jpg", SWT.IMAGE_JPEG);
>
> figureCanvasGC.dispose();
> imageGC.dispose();
> img.dispose();
>
> my view gViewer contains - x and - y values...
> i am able to save the image from (0,0) cordinates can any one tell me the
> how to get - ve x and y coordinate data
>
> Thanks
> Raj
>
|
|
|
Re: Save view as jpg image [message #511750 is a reply to message #511748] |
Tue, 02 February 2010 17:47 |
|
hi Grant,
thanks for the replay i got the solution from web..
ScalableFreeformRootEditPart rootEditPart = (ScalableFreeformRootEditPart) graphicalViewer
.getEditPartRegistry().get(LayerManager.ID);
IFigure rootFigure = ((LayerManager) rootEditPart)
.getLayer(LayerConstants.PRINTABLE_LAYERS);
Rectangle rootFigureBounds = rootFigure.getBounds();
Control figureCanvas = graphicalViewer.getControl();
Image img = new Image(Display.getDefault(), rootFigureBounds.width,
rootFigureBounds.height);
GC imageGC = new GC(img);
Graphics graphics=new SWTGraphics(imageGC);
rootFigure.paint(graphics);
int x = rootFigureBounds.x, y = rootFigureBounds.y;
Rectangle clipRect = new Rectangle();
while (y < rootFigureBounds.y + rootFigureBounds.height) {
while (x < rootFigureBounds.x + rootFigureBounds.width) {
graphics.pushState();
// getPrinter().startPage();
graphics.translate(-x, -y);
graphics.getClip(clipRect);
clipRect.setLocation(x, y);
graphics.clipRect(clipRect);
rootFigure.paint(graphics);
// getPrinter().endPage();
graphics.popState();
x += clipRect.width;
}
x = rootFigureBounds.x;
y += clipRect.height;
}
// figureCanvas.print(imageGC); // This is Eclipse 3.4 only API
ImageLoader imgLoader = new ImageLoader();
imgLoader.data = new ImageData[] { img.getImageData() };
imgLoader.save(saveLocation, SWT.IMAGE_PNG);
imageGC.dispose();
img.dispose();
|
|
|
Powered by
FUDForum. Page generated in 0.04021 seconds