I can't scale my images. [message #488107] |
Fri, 25 September 2009 15:04 |
chris snow Messages: 16 Registered: July 2009 |
Junior Member |
|
|
I am trying to draw a series of images. The images put on the buttons are scaling ok, but the images put on the GC aren't??
Any pointers would be appreciated!
Many thanks in advance,
Chris
@Override
public void createPartControl(Composite parent) {
Composite composite = new Composite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
GridLayout gridLayout = new GridLayout();
gridLayout.verticalSpacing = 5;
gridLayout.horizontalSpacing = 5;
gridLayout.numColumns = 1;
composite.setLayout(gridLayout);
FileStoreEditorInput input = (FileStoreEditorInput) getEditorInput();
AllocateImagesRequest req = getAllocateImagesRequest(input);
File xmlPath = new File(input.getURI());
File imageFolder = new File(xmlPath.getParent());
ImageType[] images = req.getImagesType().getImageType();
for (int i = 0; i < images.length; i++) {
ImageType img = images[i];
File imageFile = new File(imageFolder, img.getFileName());
String fileName = imageFile.getAbsolutePath();
Image origImage = new Image(composite.getDisplay(), fileName);
double zoom = 1d/4; //scale to half of the size maintaining aspect ratio
final int width = origImage.getBounds().width;
final int height = origImage.getBounds().height;
final Image scaledImage = new Image(
Display.getDefault(), origImage.getImageData().scaledTo((int)(width * zoom),(int)(height * zoom))
);
Canvas canvas = new Canvas( composite, SWT.NONE);
canvas.addPaintListener( new PaintListener() {
public void paintControl(PaintEvent e) {
GC gc = e.gc;
gc.drawImage(scaledImage,0,0);
}
});
Button button = new Button(composite, SWT.NONE);
button.setImage(scaledImage);
button.setText(img.getFileName());
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.03500 seconds