Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » I can't scale my images.
I can't scale my images. [message #488107] Fri, 25 September 2009 11:04 Go to next message
chris snow is currently offline 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());
}
Re: I can't scale my images. [message #488172 is a reply to message #488107] Fri, 25 September 2009 14:48 Go to previous message
chris snow is currently offline chris snow
Messages: 16
Registered: July 2009
Junior Member
This did the job:

GridData layoutData = new GridData(GridData.FILL_BOTH);
canvas.setLayoutData(layoutData);
Previous Topic:How to substitute an SWT class
Next Topic:Register preferences action on cocoa
Goto Forum:
  


Current Time: Wed Aug 20 00:55:35 EDT 2014

Powered by FUDForum. Page generated in 0.04061 seconds