Is this a legal way to create an image? [message #249140] |
Wed, 03 June 2009 15:04  |
Eclipse User |
|
|
|
Originally posted by: thomas.cranksoftware.com
I have an application that displays layers similarly to Photoshop, but there are
some circumstances where the layer that I want to display is not part of the
active model, and so it doesn't have an EditPart (or an IFigure) associated
with it.
I want to create thumbnails of these items, so I've crafted a bit of code that
looks something like:
protected void displayThumbnail(Object modelObject) {
IFigure modelFigure = getModelObjectFigure(modelObject);
if(modelFigure != null) {
... Use the standard Thumbnail in an SWT widget
} else {
Image image = createLayerImage(modelObject);
... Use the image in an SWT widget
}
}
The createLayerImage() routine is where I'm wondering how completely out to
lunch I am and what issues I should be aware of (or if there is a better
way to achieve what I want ... drawing a not-yet-existing model object to
an SWT Image):
protected Image createLayerImage(Object layer) {
ScrollingGraphicalViewer viewer = new ScrollingGraphicalViewer();
viewer.setEditPartFactory(new MyEditPartFactory());
viewer.setContents(layer);
Map map = viewer.getEditPartRegistry();
GraphicalEditPart ep = (GraphicalEditPart)map.get(layer);
IFigure rootFigure = ep.getFigure();
ep.refresh();
rootFigure.setSize(getWidth(), getHeight());
rootFigure.getLayoutManager().layout(rootFigure);
ep.refresh();
Image image = new Image(null, app.getWidth(), app.getHeight());
GC gc = new GC(image);
SWTGraphics graphics = new SWTGraphics(gc);
rootFigure.paint(graphics);
graphics.dispose();
gc.dispose();
return image;
}
Any and all comments appreciated.
Thanks,
Thomas
---
http://www.cranksoftware.com
|
|
|
|
Re: Is this a legal way to create an image? [message #510416 is a reply to message #249151] |
Wed, 27 January 2010 08:46  |
Eclipse User |
|
|
|
I want to make a picture of the full [/SIZE]gef(scrollingGraphicalViewer). I get the picture in the right size, but i became not the whole components. But if I run the Method a second time, I get the whole image of all components.
Code:
ScalableFreeformRootEditPart rootEditPart = (ScalableFreeformRootEditPart)graphicalViewer.getRootEditPar t();
IFigure rootFigure = rootEditPart.getLayer(ScalableFreeformRootEditPart.PRINTABLE _LAYERS);
Rectangle rootFigureBounds = rootFigure.getBounds();
Image img = new Image(null, rootFigureBounds.width, rootFigureBounds.height);
GC imageGC = new GC(img);
Graphics graphics = new SWTGraphics(imageGC);
rootFigure.paint(graphics);
ImageLoader imgLoader = new ImageLoader();
imgLoader.data = new ImageData[] { img.getImageData() };
imgLoader.save(m_IreportDir + "test.jpeg", SWT.IMAGE_JPEG);
|
|
|
Powered by
FUDForum. Page generated in 0.07834 seconds