Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » I found a resizeImage() function online.(But I get some errors I don't know how to fix)
I found a resizeImage() function online. [message #902197] Thu, 16 August 2012 10:07 Go to next message
Calvin Cutts is currently offline Calvin CuttsFriend
Messages: 12
Registered: July 2012
Junior Member
I found the resizeImage() method online and just copied and pasted it, that's the only place where the errors occur.

import java.awt.Component;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.net.URL;

public class ImageLoader extends Component {

	public Image loadImageFromFile(String filename) {
		Image image = null;
		Toolkit tk = Toolkit.getDefaultToolkit();
		image = tk.getImage(filename);
		waitForImage(image);
                image = resizeImage(image, 200, 200);
		return(image);
	}

	private void waitForImage(Image image) {
		MediaTracker mt = new MediaTracker(this);
		mt.addImage(image, 1);
		try {
			mt.waitForAll();
		} catch(Exception e) {
			e.printStackTrace();
			System.exit(0);
		}
	}
	
	public Image loadImageFromInternet(String urlString) {
		Image image = null;
		URL url = null;
		try {
			url = new URL(urlString);
		} catch(Exception e) {
			e.printStackTrace();
			System.exit(0);
		}
		Toolkit tk = Toolkit.getDefaultToolkit();
		image = tk.getImage(url);
		waitForImage(image);
                image = resizeImage(image, 200, 200);
		return(image);
	}
	
	public static Image resizeImage(Image src, int screenWidth, int screenHeight) {
		int srcWidth = src.getWidth(); *******************************************************
                int srcHeight = src.getHeight(); ********************************************************
		Image tmp = Image.createImage(screenWidth, srcHeight); ***********************************************
		Graphics g = tmp.getGraphics();
		int ratio = (srcWidth << 16) / screenWidth;
		int pos = ratio / 2;
		 
	    // Horizontal Resize
	    for (int x = 0; x < screenWidth; x++)
	    {
	        g.setClip(x, 0, 1, srcHeight);
	        g.drawImage(src, x - (pos >> 16), 0, Graphics.LEFT | Graphics.TOP);**************************************
	        pos += ratio;
	    }
		 
	    Image resizedImage = Image.createImage(screenWidth, screenHeight);*************************************
	    g = resizedImage.getGraphics();
	    ratio = (srcHeight << 16) / screenHeight;
	    pos = ratio / 2;
	 
	    //Vertical resize
	    for (int y = 0; y < screenHeight; y++) {
	        g.setClip(0, y, screenWidth, 1);
		        g.drawImage(tmp, 0, y - (pos >> 16), Graphics.LEFT | Graphics.TOP);********************************************
		        pos += ratio;
		    }
	 
		    return resizedImage;
		}
}


These errors make no sense to me, not all of them refer to the above function though, and that's the only problem.

Quote:
Description Resource Path Location Type
The serializable class DrawSquares does not declare a static final serialVersionUID field of type long DrawSquares.java /DrawSquares/src line 7 Java Problem
The method show() from the type Window is deprecated DrawSquares.java /DrawSquares/src line 18 Java Problem
The serializable class FSquares does not declare a static final serialVersionUID field of type long FillSquares.java /FillSquares/src line 28 Java Problem
The method show() from the type Window is deprecated FillSquares.java /FillSquares/src line 19 Java Problem
The serializable class DisplayCanvas does not declare a static final serialVersionUID field of type long DisplayCanvas.java /ImageLoader/src line 6 Java Problem
The serializable class FillSquares does not declare a static final serialVersionUID field of type long FillSquares.java /FillSquares/src line 8 Java Problem
The method show() from the type Window is deprecated QWin.java /QWin/src line 19 Java Problem
The serializable class Squares does not declare a static final serialVersionUID field of type long DrawSquares.java /DrawSquares/src line 28 Java Problem
The serializable class QWin does not declare a static final serialVersionUID field of type long QWin.java /QWin/src line 4 Java Problem
The value of the local variable qw is not used QWin.java /QWin/src line 9 Java Problem
The value of the local variable fred is not used ArrayDemo.java /ArrayDemo/src line 7 Java Problem
The serializable class ImageLoader does not declare a static final serialVersionUID field of type long ImageLoader.java /DrawMemory/src line 7 Java Problem
The value of the local variable lance is not used ArrayDemo.java /ArrayDemo/src line 23 Java Problem
The serializable class Display does not declare a static final serialVersionUID field of type long Display.java /ImageLoader/src line 5 Java Problem
The serializable class DrawBevel2 does not declare a static final serialVersionUID field of type long DrawBevel2.java /DrawBevel2/src line 8 Java Problem
The serializable class Bevel2 does not declare a static final serialVersionUID field of type long DrawBevel2.java /DrawBevel2/src line 27 Java Problem
The method show() from the type Window is deprecated DrawBevel2.java /DrawBevel2/src line 18 Java Problem
The serializable class DrawMemoryCanvas does not declare a static final serialVersionUID field of type long DrawMemoryCanvas.java /DrawMemory/src line 8 Java Problem
The method show() from the type Window is deprecated Display.java /ImageLoader/src line 19 Java Problem
The serializable class RemoteDisplayCanvas does not declare a static final serialVersionUID field of type long RemoteDisplayCanvas.java /ImageLoader/src line 6 Java Problem
The serializable class CheckerBoard does not declare a static final serialVersionUID field of type long CheckerBoard.java /CheckerBoard/src line 8 Java Problem
The serializable class Checker does not declare a static final serialVersionUID field of type long CheckerBoard.java /CheckerBoard/src line 29 Java Problem
The method show() from the type Window is deprecated CheckerBoard.java /CheckerBoard/src line 19 Java Problem
The serializable class ImageLoader does not declare a static final serialVersionUID field of type long ImageLoader.java /ImageLoader/src line 7 Java Problem
The serializable class ColourFadeCanvas does not declare a static final serialVersionUID field of type long ColourFade.java /ColourFade/src line 30 Java Problem
The serializable class ColourFade does not declare a static final serialVersionUID field of type long ColourFade.java /ColourFade/src line 9 Java Problem
The serializable class DrawMemory does not declare a static final serialVersionUID field of type long DrawMemory.java /DrawMemory/src line 5 Java Problem
The method show() from the type Window is deprecated DrawMemory.java /DrawMemory/src line 16 Java Problem
The method show() from the type Window is deprecated ColourFade.java /ColourFade/src line 20 Java Problem
The serializable class ImageLoader does not declare a static final serialVersionUID field of type long ImageLoader.java /CheckerBoard/src line 7 Java Problem


I have no idea why or how I'm getting these errors. Could someone help me?

Thanks
Astralogic

Edit: I only need help with erros on the lines I marked with stars.

Edit 2: If you would like a screenshot showing exactly what is highlighted red let me know and I'll pm you the image.

[Updated on: Thu, 16 August 2012 10:15]

Report message to a moderator

Re: I found a resizeImage() function online. [message #902312 is a reply to message #902197] Fri, 17 August 2012 00:30 Go to previous messageGo to next message
David Wegener is currently offline David WegenerFriend
Messages: 1445
Registered: July 2009
Senior Member
On 08/16/2012 05:07 AM, Calvin Cutts wrote:
> I found the resizeImage() method online and just copied and pasted it,
> that's the only place where the errors occur.
>
> import java.awt.Component;
> import java.awt.Graphics;
> import java.awt.Image;
> import java.awt.MediaTracker;
> import java.awt.Toolkit;
> import java.net.URL;
>
> public class ImageLoader extends Component {
>
> public Image loadImageFromFile(String filename) {
> Image image = null;
> Toolkit tk = Toolkit.getDefaultToolkit();
> image = tk.getImage(filename);
> waitForImage(image);
> image = resizeImage(image, 200, 200);
> return(image);
> }
>
> private void waitForImage(Image image) {
> MediaTracker mt = new MediaTracker(this);
> mt.addImage(image, 1);
> try {
> mt.waitForAll();
> } catch(Exception e) {
> e.printStackTrace();
> System.exit(0);
> }
> }
>
> public Image loadImageFromInternet(String urlString) {
> Image image = null;
> URL url = null;
> try {
> url = new URL(urlString);
> } catch(Exception e) {
> e.printStackTrace();
> System.exit(0);
> }
> Toolkit tk = Toolkit.getDefaultToolkit();
> image = tk.getImage(url);
> waitForImage(image);
> image = resizeImage(image, 200, 200);
> return(image);
> }
>
> public static Image resizeImage(Image src, int screenWidth, int
> screenHeight) {
> int srcWidth = src.getWidth();
> *******************************************************
> int srcHeight = src.getHeight();
> ********************************************************
> Image tmp = Image.createImage(screenWidth, srcHeight);
> ***********************************************
> Graphics g = tmp.getGraphics();
> int ratio = (srcWidth << 16) / screenWidth;
> int pos = ratio / 2;
> // Horizontal Resize
> for (int x = 0; x < screenWidth; x++)
> {
> g.setClip(x, 0, 1, srcHeight);
> g.drawImage(src, x - (pos >> 16), 0, Graphics.LEFT |
> Graphics.TOP);**************************************
> pos += ratio;
> }
> Image resizedImage = Image.createImage(screenWidth,
> screenHeight);*************************************
> g = resizedImage.getGraphics();
> ratio = (srcHeight << 16) / screenHeight;
> pos = ratio / 2;
> //Vertical resize
> for (int y = 0; y < screenHeight; y++) {
> g.setClip(0, y, screenWidth, 1);
> g.drawImage(tmp, 0, y - (pos >> 16), Graphics.LEFT |
> Graphics.TOP);********************************************
> pos += ratio;
> }
> return resizedImage;
> }
> }
>
> These errors make no sense to me, not all of them refer to the above
> function though, and that's the only problem.
>
> Quote:
>> Description Resource Path Location Type
>> The serializable class DrawSquares does not declare a static final
>> serialVersionUID field of type long DrawSquares.java
>> /DrawSquares/src line 7 Java Problem
>> The method show() from the type Window is deprecated
>> DrawSquares.java /DrawSquares/src line 18 Java Problem
>> The serializable class FSquares does not declare a static final
>> serialVersionUID field of type long FillSquares.java
>> /FillSquares/src line 28 Java Problem
>> The method show() from the type Window is deprecated
>> FillSquares.java /FillSquares/src line 19 Java Problem
>> The serializable class DisplayCanvas does not declare a static final
>> serialVersionUID field of type long DisplayCanvas.java
>> /ImageLoader/src line 6 Java Problem
>> The serializable class FillSquares does not declare a static final
>> serialVersionUID field of type long FillSquares.java
>> /FillSquares/src line 8 Java Problem
>> The method show() from the type Window is deprecated QWin.java
>> /QWin/src line 19 Java Problem
>> The serializable class Squares does not declare a static final
>> serialVersionUID field of type long DrawSquares.java
>> /DrawSquares/src line 28 Java Problem
>> The serializable class QWin does not declare a static final
>> serialVersionUID field of type long QWin.java /QWin/src line
>> 4 Java Problem
>> The value of the local variable qw is not used QWin.java
>> /QWin/src line 9 Java Problem
>> The value of the local variable fred is not used ArrayDemo.java
>> /ArrayDemo/src line 7 Java Problem
>> The serializable class ImageLoader does not declare a static final
>> serialVersionUID field of type long ImageLoader.java
>> /DrawMemory/src line 7 Java Problem
>> The value of the local variable lance is not used ArrayDemo.java
>> /ArrayDemo/src line 23 Java Problem
>> The serializable class Display does not declare a static final
>> serialVersionUID field of type long Display.java
>> /ImageLoader/src line 5 Java Problem
>> The serializable class DrawBevel2 does not declare a static final
>> serialVersionUID field of type long DrawBevel2.java
>> /DrawBevel2/src line 8 Java Problem
>> The serializable class Bevel2 does not declare a static final
>> serialVersionUID field of type long DrawBevel2.java
>> /DrawBevel2/src line 27 Java Problem
>> The method show() from the type Window is deprecated
>> DrawBevel2.java /DrawBevel2/src line 18 Java Problem
>> The serializable class DrawMemoryCanvas does not declare a static
>> final serialVersionUID field of type long DrawMemoryCanvas.java
>> /DrawMemory/src line 8 Java Problem
>> The method show() from the type Window is deprecated
>> Display.java /ImageLoader/src line 19 Java Problem
>> The serializable class RemoteDisplayCanvas does not declare a static
>> final serialVersionUID field of type long
>> RemoteDisplayCanvas.java /ImageLoader/src line 6 Java Problem
>> The serializable class CheckerBoard does not declare a static final
>> serialVersionUID field of type long CheckerBoard.java
>> /CheckerBoard/src line 8 Java Problem
>> The serializable class Checker does not declare a static final
>> serialVersionUID field of type long CheckerBoard.java
>> /CheckerBoard/src line 29 Java Problem
>> The method show() from the type Window is deprecated
>> CheckerBoard.java /CheckerBoard/src line 19 Java Problem
>> The serializable class ImageLoader does not declare a static final
>> serialVersionUID field of type long ImageLoader.java
>> /ImageLoader/src line 7 Java Problem
>> The serializable class ColourFadeCanvas does not declare a static
>> final serialVersionUID field of type long ColourFade.java
>> /ColourFade/src line 30 Java Problem
>> The serializable class ColourFade does not declare a static final
>> serialVersionUID field of type long ColourFade.java
>> /ColourFade/src line 9 Java Problem
>> The serializable class DrawMemory does not declare a static final
>> serialVersionUID field of type long DrawMemory.java
>> /DrawMemory/src line 5 Java Problem
>> The method show() from the type Window is deprecated
>> DrawMemory.java /DrawMemory/src line 16 Java Problem
>> The method show() from the type Window is deprecated
>> ColourFade.java /ColourFade/src line 20 Java Problem
>> The serializable class ImageLoader does not declare a static final
>> serialVersionUID field of type long ImageLoader.java
>> /CheckerBoard/src line 7 Java Problem
>
>
> I have no idea why or how I'm getting these errors. Could someone help me?
>
> Thanks
> Astralogic
>
> Edit: I added code tags, and stars *** to highlight the lines on which
> the errors occured.
Serializable classes either use a static final field to provide a
reference value or generate one based on the compiled class file. The
reference value is used during serialization or de-serilization to
confirm that the version of the class is compatible. You should study
serilizable classes to find out more. The message should be a warning
only unless you've set it to be treated as an error.

The deprecated messages indicate that you are using methods that are no
longer recommended for use and can be removed from future versions of
the JDK. These messages should also be warnings.

Your question really belongs in a general programming forum such as
stackoverflow etc. The Eclipse forums are for questions about using the
Eclipse tools not general Java programming questions.
Re: I found a resizeImage() function online. [message #902363 is a reply to message #902312] Fri, 17 August 2012 10:28 Go to previous message
Calvin Cutts is currently offline Calvin CuttsFriend
Messages: 12
Registered: July 2012
Junior Member
Sorry about that, mods feel free to move this.
Previous Topic:Missing PROG gawk
Next Topic:How to make Eclipse to save settings
Goto Forum:
  


Current Time: Thu Apr 25 17:39:43 GMT 2024

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

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

Back to the top