Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Conversion: from "Image" to "File"
Conversion: from "Image" to "File" [message #456298] Mon, 30 May 2005 12:59 Go to next message
Eclipse UserFriend
Originally posted by: bhbh.iyy.com

Hello,
I'm using swt libraries to handle images, and I need to convert an Image
into a File, and viceversa.
I could convert a file into an image :
Image img = new Image(null,file.getAbsolutePath());
but I sometimes get java.lang.OutofMemory exception, when the image is
really big.

I also need to do the viceversa, and I have NO clue how to convert an image
into a file. I mean I know you can do it using an ImageLoader and saving it,
but if possible, I'd like not to save it on hard disk.
Any hints?
Thanks a lot,


Larissa
Re: Conversion: from "Image" to "File" [message #456304 is a reply to message #456298] Mon, 30 May 2005 15:01 Go to previous messageGo to next message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
Try using -Xmx to increase the memory available to Java.

"Barli" <bhbh@iyy.com> wrote in message
news:d7f305$8ui$1@news.eclipse.org...
> Hello,
> I'm using swt libraries to handle images, and I need to convert an Image
> into a File, and viceversa.
> I could convert a file into an image :
> Image img = new Image(null,file.getAbsolutePath());
> but I sometimes get java.lang.OutofMemory exception, when the image is
> really big.
>
> I also need to do the viceversa, and I have NO clue how to convert an
image
> into a file. I mean I know you can do it using an ImageLoader and saving
it,
> but if possible, I'd like not to save it on hard disk.
> Any hints?
> Thanks a lot,
>
>
> Larissa
>
>
Re: Conversion: from "Image" to "File" [message #456380 is a reply to message #456298] Wed, 01 June 2005 22:27 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bhbh.iyy.com

Thanks for the tip, if anybody knows how to do this conversion please let me
know.
Cheers,


Larissa
Re: Conversion: from "Image" to "File" [message #456385 is a reply to message #456380] Thu, 02 June 2005 01:06 Go to previous messageGo to next message
Philippe Ombredanne is currently offline Philippe OmbredanneFriend
Messages: 386
Registered: July 2009
Senior Member
"Barli" <bhbh@iyy.com> wrote in message
news:d7lcoe$mak$1@news.eclipse.org...
> Thanks for the tip, if anybody knows how to do this conversion please let
me know.
> Larissa
You are doing it just fine.
Just use Steve's tip to increase the memory available to Java when loading
large images :-)

To save, use an ImageLoader, set its data with the ImageData of your Image
Then call ImageLoader.save("yourfilename", SWT.IMAGE_"Format"):

Something like that for Jpeg:
ImageLoader imageSaver = new ImageLoader();
ImageData idata = image.getImageData();
imageSaver.data = new ImageData[]{idata};
imageSaver.save("yourfilename.jpg", SWT.IMAGE_JPEG);
Re: Conversion: from "Image" to "File" [message #456610 is a reply to message #456385] Sun, 05 June 2005 18:47 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bhbh.iyy.com

"Philippe Ombredanne" <pombredanne@nexb.com> ha scritto nel messaggio
news:d7lm5i$vm7$1@news.eclipse.org...
> "Barli" <bhbh@iyy.com> wrote in message
> news:d7lcoe$mak$1@news.eclipse.org...
> To save, use an ImageLoader, set its data with the ImageData of your Image
> Then call ImageLoader.save("yourfilename", SWT.IMAGE_"Format"):
>
> Something like that for Jpeg:
> ImageLoader imageSaver = new ImageLoader();
> ImageData idata = image.getImageData();
> imageSaver.data = new ImageData[]{idata};
> imageSaver.save("yourfilename.jpg", SWT.IMAGE_JPEG);
>

Thanks for the tip, but I don't want to save the image on hard disk!
I want to save it on a "file" in the sense of a file type java variable!
Any idea how to do it?
Many thanks,

Lari
Re: Conversion: from "Image" to "File" [message #456611 is a reply to message #456610] Sun, 05 June 2005 20:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bob.objfac.com

Barli wrote:
> Thanks for the tip, but I don't want to save the image on hard disk!
> I want to save it on a "file" in the sense of a file type java variable!
> Any idea how to do it?
> Many thanks,

Do you mean java.io.File? That's nothing but a path.

Bob
Re: Conversion: from "Image" to "File" [message #456907 is a reply to message #456611] Mon, 13 June 2005 08:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bhbh.iyy.com

"Bob Foster" <bob@objfac.com> ha scritto nel messaggio
news:d7vnk8$n2l$1@news.eclipse.org...
> Barli wrote:
>> Thanks for the tip, but I don't want to save the image on hard disk!
>> I want to save it on a "file" in the sense of a file type java variable!
>> Any idea how to do it?
>> Many thanks,
>
> Do you mean java.io.File? That's nothing but a path.


Yes, I mean java.io.File.
So when I want to save something on a "file" type, it has to be stored on
hard disk first? Because I have to give the path to the file object?
Re: Conversion: from "Image" to "File" [message #456908 is a reply to message #456385] Mon, 13 June 2005 08:58 Go to previous message
Eclipse UserFriend
Originally posted by: bhbh.iyy.com

"Philippe Ombredanne" <pombredanne@nexb.com> ha scritto nel messaggio
news:d7lm5i$vm7$1@news.eclipse.org...
> You are doing it just fine.
> Just use Steve's tip to increase the memory available to Java when loading
> large images :-)


ok, I don't understand: how can I insert this xmx command in the code? My
plugin has to run in strartup, I cannot insert commands to launch it.
Thanks!
Previous Topic:ComboBoxCellEditor and dynamic values
Next Topic:Difference between addListener() and addSelectionListener()?
Goto Forum:
  


Current Time: Thu Apr 25 10:30:56 GMT 2024

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

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

Back to the top