Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Nebula » load image to Gallery very slow
load image to Gallery very slow [message #65474] Sat, 11 July 2009 19:42 Go to next message
gaston  is currently offline gaston Friend
Messages: 8
Registered: July 2009
Junior Member
Hi:
I use swt.image for assign images of the a folder with many images of high
sized but is very slow. Next I use the image with xxx.setImage();
I would like you to help me.
This is the code:

Image itemImage;
alleryItem item ;

// files.lenght = 700;

for (int i = 0, n = files.length; i < n; i++) {
itemImage = new Image(display, files[i].toString());
// resize the image
item.setImage(resize(itemImage, 640, 480));
itemImage.dispose();
}


Regards.
Gaston
Re: load image to Gallery very slow [message #65853 is a reply to message #65474] Sat, 18 July 2009 10:22 Go to previous messageGo to next message
Nicolas Richeton is currently offline Nicolas RichetonFriend
Messages: 179
Registered: July 2009
Senior Member
Hi Gaston,

Loading and resizing images with SWT is not that fast and with this
code, your application is frozen while it processes all images.

You should do the loading and resizing in a separate thread and use
setImage after each image processed. Most applications work this way.

Additionnaly, you can post the code you use for resize, there may be
possible speed improvements.

--
Nicolas


gaston a écrit :
> Hi:
> I use swt.image for assign images of the a folder with many images of
> high sized but is very slow. Next I use the image with xxx.setImage();
> I would like you to help me.
> This is the code:
>
> Image itemImage;
> alleryItem item ;
>
> // files.lenght = 700;
>
> for (int i = 0, n = files.length; i < n; i++) {
> itemImage = new Image(display, files[i].toString());
> // resize the image
> item.setImage(resize(itemImage, 640, 480));
> itemImage.dispose();
> }
>
>
> Regards.
> Gaston
>
Re: load image to Gallery very slow [message #65872 is a reply to message #65853] Mon, 20 July 2009 02:16 Go to previous messageGo to next message
gaston  is currently offline gaston Friend
Messages: 8
Registered: July 2009
Junior Member
Hi, I change mi code, is better, but is a bit slow.
It is better to do with AWT and then convert to SWT for use in the
gallery?
The code for Resize is yours and is in your blog.

gallery.addListener(SWT.SetData, new Listener() {

public void handleEvent(Event event) {
GalleryItem item = (GalleryItem) event.item;
int index;
if (item.getParentItem() != null) {
index = item.getParentItem().indexOf(item);
item.setItemCount(0);
} else {
index = gallery.indexOf(item);
item.setItemCount(100);
}

System.out.println( "setData index " + index); //$NON-NLS-1$

// map is a map with file path
Image img = resize(map.get(index), 640,480);
item.setImage(img);
item.setText("Item " + index); //$NON-NLS-1$
}
});
Regards.
And Thank you.
Re: load image to Gallery very slow [message #66025 is a reply to message #65872] Sat, 25 July 2009 10:56 Go to previous message
Nicolas Richeton is currently offline Nicolas RichetonFriend
Messages: 179
Registered: July 2009
Senior Member
Hi Gaston,

AWT will add additionnal work to convert images to SWT so this won't
give you any speed improvements.

The code you provided uses the virtual mode but does not use threads.
Try to do the image loading and resize work in a Thread or a Job.

Note that the code on my blog uses the maximum processing quality, which
is the slowest :

gc.setAntialias(SWT.ON);
gc.setInterpolation(SWT.HIGH);

try to replace the previous code by

gc.setAntialias(SWT.OFF);
gc.setInterpolation(SWT.LOW);

This is often enough for thumbnails.

And don't forget to keep track of Image objects. You have to dispose
them after use (the gallery won't do this automatically).

--
Nicolas

gaston a écrit :
> Hi, I change mi code, is better, but is a bit slow.
> It is better to do with AWT and then convert to SWT for use in the
> gallery? The code for Resize is yours and is in your blog.
>
> gallery.addListener(SWT.SetData, new Listener() {
>
> public void handleEvent(Event event) {
> GalleryItem item = (GalleryItem) event.item;
> int index;
> if (item.getParentItem() != null) {
> index = item.getParentItem().indexOf(item);
> item.setItemCount(0);
> } else {
> index = gallery.indexOf(item);
> item.setItemCount(100);
> }
>
> System.out.println( "setData index " + index); //$NON-NLS-1$
>
> // map is a map with file path
> Image img = resize(map.get(index), 640,480); item.setImage(img);
> item.setText("Item " + index); //$NON-NLS-1$
> }
> }); Regards.
> And Thank you.
>
Re: load image to Gallery very slow [message #595738 is a reply to message #65474] Sat, 18 July 2009 10:22 Go to previous message
Nicolas Richeton is currently offline Nicolas RichetonFriend
Messages: 179
Registered: July 2009
Senior Member
Hi Gaston,

Loading and resizing images with SWT is not that fast and with this
code, your application is frozen while it processes all images.

You should do the loading and resizing in a separate thread and use
setImage after each image processed. Most applications work this way.

Additionnaly, you can post the code you use for resize, there may be
possible speed improvements.

--
Nicolas


gaston a écrit :
> Hi:
> I use swt.image for assign images of the a folder with many images of
> high sized but is very slow. Next I use the image with xxx.setImage();
> I would like you to help me.
> This is the code:
>
> Image itemImage;
> alleryItem item ;
>
> // files.lenght = 700;
>
> for (int i = 0, n = files.length; i < n; i++) {
> itemImage = new Image(display, files[i].toString());
> // resize the image
> item.setImage(resize(itemImage, 640, 480));
> itemImage.dispose();
> }
>
>
> Regards.
> Gaston
>
Re: load image to Gallery very slow [message #595745 is a reply to message #65853] Mon, 20 July 2009 02:16 Go to previous message
gaston  is currently offline gaston Friend
Messages: 8
Registered: July 2009
Junior Member
Hi, I change mi code, is better, but is a bit slow.
It is better to do with AWT and then convert to SWT for use in the
gallery?
The code for Resize is yours and is in your blog.

gallery.addListener(SWT.SetData, new Listener() {

public void handleEvent(Event event) {
GalleryItem item = (GalleryItem) event.item;
int index;
if (item.getParentItem() != null) {
index = item.getParentItem().indexOf(item);
item.setItemCount(0);
} else {
index = gallery.indexOf(item);
item.setItemCount(100);
}

System.out.println( "setData index " + index); //$NON-NLS-1$

// map is a map with file path
Image img = resize(map.get(index), 640,480);
item.setImage(img);
item.setText("Item " + index); //$NON-NLS-1$
}
});
Regards.
And Thank you.
Re: load image to Gallery very slow [message #595804 is a reply to message #65872] Sat, 25 July 2009 10:56 Go to previous message
Nicolas Richeton is currently offline Nicolas RichetonFriend
Messages: 179
Registered: July 2009
Senior Member
Hi Gaston,

AWT will add additionnal work to convert images to SWT so this won't
give you any speed improvements.

The code you provided uses the virtual mode but does not use threads.
Try to do the image loading and resize work in a Thread or a Job.

Note that the code on my blog uses the maximum processing quality, which
is the slowest :

gc.setAntialias(SWT.ON);
gc.setInterpolation(SWT.HIGH);

try to replace the previous code by

gc.setAntialias(SWT.OFF);
gc.setInterpolation(SWT.LOW);

This is often enough for thumbnails.

And don't forget to keep track of Image objects. You have to dispose
them after use (the gallery won't do this automatically).

--
Nicolas

gaston a écrit :
> Hi, I change mi code, is better, but is a bit slow.
> It is better to do with AWT and then convert to SWT for use in the
> gallery? The code for Resize is yours and is in your blog.
>
> gallery.addListener(SWT.SetData, new Listener() {
>
> public void handleEvent(Event event) {
> GalleryItem item = (GalleryItem) event.item;
> int index;
> if (item.getParentItem() != null) {
> index = item.getParentItem().indexOf(item);
> item.setItemCount(0);
> } else {
> index = gallery.indexOf(item);
> item.setItemCount(100);
> }
>
> System.out.println( "setData index " + index); //$NON-NLS-1$
>
> // map is a map with file path
> Image img = resize(map.get(index), 640,480); item.setImage(img);
> item.setText("Item " + index); //$NON-NLS-1$
> }
> }); Regards.
> And Thank you.
>
Previous Topic:Custom Font for Row Headers
Next Topic:[CDateTime] No Selection Events?
Goto Forum:
  


Current Time: Thu Apr 18 10:19:07 GMT 2024

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

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

Back to the top