• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Problems Getting Image Width and Height on Linux
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problems Getting Image Width and Height on Linux


  • Subject: Problems Getting Image Width and Height on Linux
  • From: MadBrowser <email@hidden>
  • Date: Wed, 1 Oct 2003 15:46:32 -0700

Hey folks. I have some code in one of my WO apps that resizes JPGs and gets their width and height.

This code seems to be doing different things depending on which JVM it is running on. On my OS X dev system (10.2.8 w/ 1.4 update), things work great. On my Linux deployment server, I am getting different results.

I have a method that gets the height and width of an image file. It uses the Image, Graphics and Frame classes from J2SE to do this. I've included the code below. On OS X, I get the correct values (640,480). On my Linux system (Sun JVM 1.4.2) I get (-1, -1). According to Sun docs, -1 means that "the width of this image, or -1 if the width is not yet known".

** Now what is strange is that this same piece of code is working just fine in a J2EE app on the same server. I know this code can work on Linux, but it doesn't seem to work in my WO apps. **

I am running Xvfb on the server to provide AWT with access to X11. For my J2EE apps I had to export a variable (DISPLAY=:0.0) for the JVM to find the X server. Do I need to do something like that for WO running on Linux? What is strange is that I'm not getting an error that WO can't connect to an X11 server, just the output from the AWT classes is totally wrong. I may be off base with this idea, but something is not working properly on Linux...

I tried running with 1.4's headless option and just got an exception... But, this way SHOULD work since the J2EE apps can run this way.

I must be doing something wrong.

I'm sure others have seen something similar but the archives didn't turn up much.

Any help is much appreciated.

Thanks,
Hunter

Code:

private Integer[] getImageSize(String fullsizePathToFile) throws InterruptedException {
Graphics g = null;
Frame frame = null;


        Integer[] theSizes = new Integer[2];

        try {
            frame = new Frame();
            frame.addNotify();

            if (fullsizePathToFile == null) {
                NSLog.out.appendln("AddPhoto->No File Path");
            }

            String pathToFile = fullsizePathToFile;

            MediaTracker mt = new MediaTracker(frame);
            Image image = new ImageIcon(pathToFile).getImage();
            mt.addImage(image, 0);

try {
mt.waitForAll();
}
catch (InterruptedException e) {
NSLog.out.appendln("Interrupted while loading image: " + pathToFile);
throw new InterruptedException(e.getMessage()); //should I really be doing this?
}


theSizes[0] = new Integer(image.getWidth(frame)); //this is returning -1 instead of 480
theSizes[1] = new Integer(image.getHeight(frame));
}


        finally {
            if (g != null) g.dispose();
            if (frame != null) frame.removeNotify();
        }

        return theSizes;
    }

Exception:

[2003-10-01 17:44:02 CDT] <WorkerThread6> <com.webobjects.appserver._private.WOComponentRequestHandler>: Exception occurred while handling request:
java.lang.IllegalArgumentException: Width (-1) and height (-1) cannot be <= 0
[2003-10-01 17:44:02 CDT] <WorkerThread6> java.lang.IllegalArgumentException: Width (-1) and height (-1) cannot be <= 0
at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectCol orModel.java:999)
at java.awt.image.BufferedImage.<init>(BufferedImage.java:250)
at Resize.doResize(Resize.java:37)
at AddPhoto.uploadFile(AddPhoto.java:72)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav a:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor Impl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at KeyValueCodingProtectedAccessor.methodValue(KeyValueCodingProtectedAcces sor.java:54)
at com.webobjects.foundation.NSKeyValueCoding$_MethodBinding.valueInObject( NSKeyValueCoding.java:1160)
at com.webobjects.foundation.NSKeyValueCoding$DefaultImplementation.valueFo rKey(NSKeyValueCoding.java:1268)
at com.webobjects.appserver.WOComponent.valueForKey(WOComponent.java:1544)
at com.webobjects.foundation.NSKeyValueCoding$Utility.valueForKey(NSKeyValu eCoding.java:498)
at com.webobjects.foundation.NSKeyValueCodingAdditions$DefaultImplementatio n.valueForKeyPath(NSKeyValueCodingAdditions.java:212)
at com.webobjects.appserver.WOComponent.valueForKeyPath(WOComponent.java:16 05)
at com.webobjects.appserver._private.WOKeyValueAssociation.valueInComponent (WOKeyValueAssociation.java:46)
at com.webobjects.appserver._private.WOImageButton.invokeAction(WOImageButt on.java:239)
at com.webobjects.appserver._private.WODynamicGroup.invokeChildrenAction(WO DynamicGroup.java:101)
at com.webobjects.appserver._private.WODynamicGroup.invokeAction(WODynamicG roup.java:110)
at com.webobjects.appserver._private.WOForm.invokeAction(WOForm.java:82)
at com.webobjects.appserver._private.WODynamicGroup.invokeChildrenAction(WO DynamicGroup.java:101)
at com.webobjects.appserver._private.WODynamicGroup.invokeAction(WODynamicG roup.java:110)
at com.webobjects.appserver.WOComponent.invokeAction(WOComponent.java:950)
at com.webobjects.appserver.WOSession.invokeAction(WOSession.java:1136)
at com.webobjects.appserver.WOApplication.invokeAction(WOApplication.java:1 316)
at com.webobjects.appserver._private.WOComponentRequestHandler._dispatchWit hPreparedPage(WOComponentRequestHandler.java:196)
at com.webobjects.appserver._private.WOComponentRequestHandler._dispatchWit hPreparedSession(WOComponentRequestHandler.java:287)
at com.webobjects.appserver._private.WOComponentRequestHandler._dispatchWit hPreparedApplication(WOComponentRequestHandler.java:322)
at com.webobjects.appserver._private.WOComponentRequestHandler._handleReque st(WOComponentRequestHandler.java:358)
at com.webobjects.appserver._private.WOComponentRequestHandler.handleReques t(WOComponentRequestHandler.java:435)
at com.webobjects.appserver.WOApplication.dispatchRequest(WOApplication.jav a:1247)
at com.webobjects.appserver._private.WOWorkerThread.runOnce(WOWorkerThread. java:167)
at com.webobjects.appserver._private.WOWorkerThread.run(WOWorkerThread.java :248)
at java.lang.Thread.run(Thread.java:534)
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.

  • Next by Date: D2W Newbie
  • Next by thread: D2W Newbie
  • Index(es):
    • Date
    • Thread