Skip to main content

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 15:04 Go to next message
chris snow is currently offline chris snowFriend
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,


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;
	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;  
	Button button = new Button(composite, SWT.NONE);
Re: I can't scale my images. [message #488172 is a reply to message #488107] Fri, 25 September 2009 18:48 Go to previous message
chris snow is currently offline chris snowFriend
Messages: 16
Registered: July 2009
Junior Member
This did the job:

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

Current Time: Sat Dec 07 11:39:10 GMT 2019

Powered by FUDForum. Page generated in 0.01673 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top