Image seems not loading in servlet running in tomcat 4 ... (win xp)

This servlet basically takes a images file do some scaling then send out as outputstream.
BUT the image dun since to load ... i keep getting a -1 for the width n height of the image .... seems that image cant load in tomcat....
Is it something wrong wif my code or is there a bug in tomcat....
Can someone help thanks
This is the servlet code:
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.net.*;
import java.awt.*;
import java.awt.image.*;
public class ImageOperater extends HttpServlet
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException
{ System.out.println("Start of post");
OutputStream out = null;
try{
out = res.getOutputStream();
catch(Exception e)
e.printStackTrace();
System.out.println("Start of imageprocessing");
//image processing
Image img = Toolkit.getDefaultToolkit().getImage("images/peppers.png");
ImageFilter imf = new CropImageFilter(0,0,200,200);
ImageProducer ip = new FilteredImageSource(img.getSource(),imf);
img = Toolkit.getDefaultToolkit().createImage(ip);
img =img.getScaledInstance(500,-1,Image.SCALE_AREA_AVERAGING);
//image processing finish
//check if the image is fully loaded
System.out.println("Start of image loading");
MediaTracker mediaTracker = new MediaTracker(new Container());
mediaTracker.addImage(img, 0);
try{
mediaTracker.waitForID(0);
System.out.println(mediaTracker.checkAll());
System.out.println("thread sleep");
Thread.sleep(1000);
catch(Exception e)
e.printStackTrace();
try{
mediaTracker.waitForID(0);
System.out.println(mediaTracker.checkAll());
System.out.println("thread sleep");
Thread.sleep(1000);
catch(Exception e)
e.printStackTrace();
//image fully loaded
System.out.println("Start of buffered image ");
System.out.println("width"+img.getWidth(null)+" Height "+img.getHeight(null));
//preparing the buffered image to be send
BufferedImage bimg = new BufferedImage(img.getWidth(null),img.getHeight(null),BufferedImage.TYPE_INT_RGB);
Graphics gr = bimg.getGraphics();
gr.drawImage(img, 0, 0, null);
gr.dispose();
//finished preparing
//ig = Toolkit.getDefaultToolkit().createImage(bimg.getSource());
System.out.println("Start of sending");
//send out to client
try{
ImageIO.write((RenderedImage)bimg,"png",new File("c:\\test.png"));
ImageIO.write((RenderedImage)bimg,"png",out);
catch(Exception e)
e.printStackTrace();
try{
out.flush();
out.close();
catch(Exception e)
e.printStackTrace();
System.out.println("post ended");
but if the same code is put into an applet it works ... thw getWidth() and getHeight() returns the correct value:
Image img = Toolkit.getDefaultToolkit().getImage("images/peppers.png");
ImageFilter imf = new CropImageFilter(0,0,200,200);
ImageProducer ip = new FilteredImageSource(img.getSource(),imf);
img = Toolkit.getDefaultToolkit().createImage(ip);
img =img.getScaledInstance(500,-1,Image.SCALE_AREA_AVERAGING);
//image processing finish
//check if the image is fully loaded
System.out.println("Start of image loading");
MediaTracker mediaTracker = new MediaTracker(new Container());
mediaTracker.addImage(img, 0);
try{
mediaTracker.waitForID(0);
System.out.println(mediaTracker.checkAll());
System.out.println("thread sleep");
Thread.sleep(1000);
catch(Exception e)
e.printStackTrace();
try{
mediaTracker.waitForID(0);
System.out.println(mediaTracker.checkAll());
System.out.println("thread sleep");
Thread.sleep(1000);
catch(Exception e)
e.printStackTrace();
//image fully loaded
System.out.println("Start of buffered image ");
System.out.println("width"+img.getWidth(null)+" Height "+img.getHeight(null));
//preparing the buffered image to be send
BufferedImage bimg = new BufferedImage(img.getWidth(null),img.getHeight(null),BufferedImage.TYPE_INT_RGB);
Graphics gr = bimg.getGraphics();
gr.drawImage(img, 0, 0, null);
gr.dispose();
//finished preparing
//ig = Toolkit.getDefaultToolkit().createImage(bimg.getSource());
System.out.println("Start of sending");
//send out to client
try{
ImageIO.write((RenderedImage)bimg,"png",new File("c:\\test.png"));

hi ganttan
first you have to make sure your server is running xwindow. in most cases a linux/apache server does not run it by default. then there is a much simpler approach of scaling images with a servlet:
Iterator readers = ImageIO.getImageReadersByFormatName("gif");
ImageReader reader = (ImageReader)readers.next();
ImageInputStream iis = ImageIO.createImageInputStream(new File(path));
reader.setInput(iis, true);
ImageReadParam param = reader.getDefaultReadParam();
param.setSourceRenderSize(new Dimension(width, height));
BufferedImage thumbnail = reader.read(0, param);
ImageIO.write(thumbnail, "gif", response.getOutputStream());
however this does not work for jpeg images. use setSourceSampling() instead of setSourceRenderSize() in this case but unfortunately it's limited and you can not scale to any size.

Similar Messages

  • Images do not load after XP SP3 install. IE works fine :-(

    I installed XP SP3 last night and now images do not load in web pages. Not all images do not load but Players photos on PGATOUR.com and item images on Ebay and item images on Amazon.com. You can click the images in Ebay you get a popup window with grey type saying 'Image is not available. I just updated Firefox, Updated Adobe per Firefox recomendation, updated Java per firefox recomendation but still no images.
    Hate to go back to IE as I have been very happy with FireFox.

    Here is the error i get when i run Debug (ctrl+Shift+Enter)
    It works fine inside of flash but outside of flash or the published swf calls an error.
    Attempting to launch and connect to Player using URL C:\Users\oussiden\Documents\flash tutorial\imgmove\test3.swf
    [SWF] C:\Users\oussiden\Documents\flash tutorial\imgmove\test3.swf - 83667 bytes after decompression
    Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.
    when i troubleshoot i found that when i comment the second line out the error disapears.
    myLoader.load(new URLRequest("img/pictures.xml"));
    myLoader.addEventListener(Event.COMPLETE, image.processXML); // when i comment this out the error disapears

  • Images are not loaded in KM Navigational iViews

    Hi All
    I have uploaded documents & folders in Content Management.
    Created KM navigational iViews, assigned to pages, worksets & role.
    Role has been granted to other users, and when they click on the role, images of documents types are not loaded. When I run the properties(Image) path its gives a portal exception.
    But when I login I see all the images loading perfectly.
    Please advise on this. Its an emergancy.
    Thanks to all.

    sk wrote:
    Hi,
    I'm facing problem while deploying apex listener in glassfish 3.0.1. So far I have done
    - Installed 10g XE
    - Installed APEX 4.0
    - Unlocked APEX_PUBLIC_USER account and reset the password
    - Installed Glassfish 3.0
    - Created admin and manager users
    - Deployed apex.war
    - Created "i" folder in C:\glassfishv3\glassfish\domains\domain1\docroot and copied images from APEX directory
    - Completed listener configuration http://127.0.0.1:9090/apex/listenerConfigure
    When I try to open the Apex page http://127.0.0.1:9090/apex images and css are not loaded. Already I have spent a day, went thro documentations and I couldn't figure out what I'm doing wrong. Can someone help on this please?
    SKHi,
    I have the same problem. But , under user "root" everything works fine, under user "oracle" images are not loaded. User oracle are owner folder where glassfish installed.
    And one more problem. Apex Listener doesn't understand role Admin and user adminlistener. Every time I have recieved message : access denied.
    Please, help me ((
    Sorry for my bad english,
    Egor Karmanov
    Edited by: 843328 on 10.03.2011 2:41

  • Images sporadically not loading

    All of a suddent, I have started experiencing a problem where images are not loading in my application.
    I have four applications in my workspace and they all share images that are defined for any application in the workspace to use.
    This issue seems to affect all four applications in my workspace.
    What happens is that if I clean my browser cache, and then go to my application, the first time I load the application page, all images on it show up. But then as I navigate through my application and eventually get back to the page, the page loads but the images sometimes don't. When they don't, all I see is the default "X" (image missing icon).
    3 strange things:
    1. It started to happen all of a sudden. I have been introducing new images and, generally, been making changes to my application, though.
    2. As I said, it is happening intermittently. That is, if I get get to the previously loaded page, sometimes the images do load fine.
    3. When the image does not load and I see the red "X" in a bordered frame, the shape of the bordered frame seems to resemble the size of the image that should have been loaded. For example, for the image of my logo that is wide like a banner spanning across my page, the missing image "X" icon is in a bordered frame that is wide like a banner - exactly the same shape as my image should have been.
    Any help would be highly appreciated.
    Thank You
    Boris

    My solution to this issue is that I had to turn OFF remote images. Turn off my iPhone completely, turn my iPhone back on then turn remote images back ON again. And all seems to be well now

  • Css and images are not loading in SharePoint website

    Scenario:-
    System Configuration- Windows server 2008 R2, SharePoint Designer 2010, SP server 2010 all are in Local Machine.
    1. I had reset the Windows server 2008 R2 password and opened SharePoint Designer 2010.
    2. Opened previous working site and found error- services unavailable- HTTP Error 503. The service is unavailable
    3. For this issue, I reset  (as I reset for windows server) the Identity password in App pool for "SharePoint Central Administration v4" application.
    4. The error "Service Unavailable" got vanished.
    But encountered new problem - .css and images are not loading. 
    5. I re run "Product Configuration wizard" with below steps:-
    A) Do not disconnect from this server.
    B) No, this machine will continue to host the website
     Still Problem persisting.
    What tried:-
    1. Resetting IIS Server.
    2. Restarted SharePoint Admin Services from "Service window".
    3. Recycled App pool.
    Just do let me know for further information.
    I have Checked so may forum and sites but no solution :(
    Looking for excellent resolution :)

    Check if Style Resource Readers SharePoint group has permissions on the site, permissions to the style library and make sure that this library provides Style Resource Readers with restricted read.
    If you don't see Style resource readers on the site, go to that library and set that permission.  you could also just load your installation media to a folder, and execute on setup.exe, select repair option.  This second option of the installation
    media is the cannon vs. flyswatter approach though, but it will work
    Stacy Anothersharepointblog.blogspot.com

  • Image does not load in a new Form window

    Hi everyone,
    In Oracle Forms I have a Form with multiple windows. On startup only the main window is loaded. For some conditions during user input another window should be shown (I am using the SHOW_WINDOW functionality). In the new window is an Image which is set with the following code:
    READ_IMAGE_FILE('image.gif', 'URL', 'IMAGE_PICTURE');
    SHOW_WINDOW('DIALOG');
    The image is stored in the JAR file and works for other form modules. But when I open the new window (Style = Dialog, Modal = Yes), the image is not loaded/displayed. But, if I close the dialog window and reopen it directly again the image is displayed.
    Does someone know how to solve this issue? I would like to have the image displayed also the first time when the dialog window is opened.
    Thanks!
    Marco

    I tried it right now, but without success.
    In the new Window I only have the Image, a dynamically generated message for the user as an text item and a button (this sounds like I could use an alert box, but an alert box has some limitations which does not fit the user requirements). When I now try to set the "Synchronize with Item" property of the Image to one of the other items of the window, the Form cannot compile:
    FRM-32084: Data Type of item is not compatible with mirror item MSG.

  • Image does not load in application

    Hi:
    I read about the following in a loading image tutorial:
    "The getImage methods return immediately, without checking whether the image data exists. The actual loading of image data normally doesn't start until the first time the program tries to paint the image. "
    Basically, I am using the
    Image img = Toolkit.getDefaultToolkit().getImage(path);I've also overwritten the paintComponent()method
    public void paintComponent(Graphics g)
       super.paintComponent(g);
       g.drawImage(image, 0,0, myWidth, myHeight, this);
    }Then, I included the above code in a JPanel, which is further included in a JInternalFrame. But somehow, the image just doesn't load, the tutorial says, the image does not load until the FIRST TIME PROGRAM PAINTS THE IMAGE. How do I make the program paint the image??
    Thanx a lot

    Check out ImageObserver, Component.prepareImage() and MediaTracker.

  • In fire fox and google chrome CSS and images are not loading

    I am facing problem with jrun, In IE-8 application is working fine, but in FireFox and Google chrome CSS and Images are not loading.
    in fire fox and google chrome requests are Aborted.
    thanks
    Ashok Gadiparthi.

    Check if Style Resource Readers SharePoint group has permissions on the site, permissions to the style library and make sure that this library provides Style Resource Readers with restricted read.
    If you don't see Style resource readers on the site, go to that library and set that permission.  you could also just load your installation media to a folder, and execute on setup.exe, select repair option.  This second option of the installation
    media is the cannon vs. flyswatter approach though, but it will work
    Stacy Anothersharepointblog.blogspot.com

  • Linked images do not load in my website

    Hi all,
    I built my website in Photoshop and Flash Catalyst. My site takes forever to load and my linked images do not load when they should. Can someone please help me with getting the load time down and loading the liked images. I linked them because I though that would cut down on the load time,  but when I click the thumbnail the images doesn't appear right away it takes a while. What am I doing wrong? I really need to get my portfolio up. Also how small should my swf file be right now it's at 8.79MB. I am a designer and new to Flash Catalyst so any suggestions will help. Thanks!

    Here's a super post from FlashCats:
    http://flashcats.net/2010/07/17/optimizing-for-smaller-swf-output-size-in-flash-catalyst/
    Hope this helps.
    Tanya

  • Images do not load in foxfire, but load ok in IE. such as the zoom bar in google maps

    I'm using Firefox 9. when I goto sites such as amazon, the images do not load. I can right click on the image box and select view image and the image will be displayed in a new page. An other example is google maps. The zoom bar on the left does not display. If I move the cursor over where the zoom bar is suppose to be the cursor will change to the hand and I can left click to work the zoom. If I bring up Internet Explorer all images, etc work ok.

    You can use these steps to check if images are blocked:
    *Open the web page that has the images missing in a browser tab.
    *Click the website favicon ([[Site Identity Button]]) on the left end of the location bar.
    *Click the "More Information" button to open the "Page Info" window with the Security tab selected (also accessible via "Tools > Page Info").
    *Go to the <i>Media</i> tab of the "Tools > Page Info" window.
    *Select the first image link and scroll down through the list with the Down arrow key.
    *If an image in the list is grayed and there is a check-mark in the box "<i>Block Images from...</i>" then remove that mark to unblock the images from that domain.

  • Image will not load from lightroom to CS5

    I am having an issue with external editing from lightroom to CS5!  From develope>edit in CS5>images does not load!  CS5 loads but the MAC finder app comes up asking me to choose a file!  Never have I seen this.  I looked into the preferences and the external editing, but its in the external editing already.  Help!

    Make sure your external editor settings link to the application in support files (hidden on Lion) rather than a shortcut.
    http://kb2.adobe.com/cps/909/cpsid_90947.html

  • Images are not loaded in glassfish

    Hi,
    I'm facing problem while deploying apex listener in glassfish 3.0.1. So far I have done
    - Installed 10g XE
    - Installed APEX 4.0
    - Unlocked APEX_PUBLIC_USER account and reset the password
    - Installed Glassfish 3.0
    - Created admin and manager users
    - Deployed apex.war
    - Created "i" folder in C:\glassfishv3\glassfish\domains\domain1\docroot and copied images from APEX directory
    - Completed listener configuration http://127.0.0.1:9090/apex/listenerConfigure
    When I try to open the Apex page http://127.0.0.1:9090/apex images and css are not loaded. Already I have spent a day, went thro documentations and I couldn't figure out what I'm doing wrong. Can someone help on this please?
    SK

    sk wrote:
    Hi,
    I'm facing problem while deploying apex listener in glassfish 3.0.1. So far I have done
    - Installed 10g XE
    - Installed APEX 4.0
    - Unlocked APEX_PUBLIC_USER account and reset the password
    - Installed Glassfish 3.0
    - Created admin and manager users
    - Deployed apex.war
    - Created "i" folder in C:\glassfishv3\glassfish\domains\domain1\docroot and copied images from APEX directory
    - Completed listener configuration http://127.0.0.1:9090/apex/listenerConfigure
    When I try to open the Apex page http://127.0.0.1:9090/apex images and css are not loaded. Already I have spent a day, went thro documentations and I couldn't figure out what I'm doing wrong. Can someone help on this please?
    SKHi,
    I have the same problem. But , under user "root" everything works fine, under user "oracle" images are not loaded. User oracle are owner folder where glassfish installed.
    And one more problem. Apex Listener doesn't understand role Admin and user adminlistener. Every time I have recieved message : access denied.
    Please, help me ((
    Sorry for my bad english,
    Egor Karmanov
    Edited by: 843328 on 10.03.2011 2:41

  • "I do not get any message or option to add exception" - Using Self signed cert -Images does not load

    Wr are have two web servers one for app and another for loading images. Both are behind Kemp Load balancer and are using self signed certs from the load balancer. The images does not load when using Firefox 3.x. I load with IE and Firefox 2.x. With firefox 3.x it does not give a message to "add exception". I only get one certificate message to add exception for the app server. I do not get the certificate message or pop up for the imaging server with Firefox 3.x.
    == This happened ==
    Every time Firefox opened
    == Always ==
    == User Agent ==
    Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)

    You have a lot of information in packed in the "More system details..." (in the right-hand column), where it looks like you found a solution. If not take a look at "Problematic Extensions" the AVG Free installation of their "'''AVG Free Search'''" can cause such problems. Directions to fix that are specific and involve reinstalling AVG Free without the Link Scanner component.
    * http://kb.mozillazine.org/Problematic_extensions

  • Background images are not loading in Firefox nor IE, running Win 7 Home Premium

    Win 7 laptop does not load background type images in either Firefox or IE.
    XP laptop shows background images while using page info/media tab.

    Please check out [[Troubleshooting extensions and themes]].

  • Images not loading when I run my JAR

    I created a Yahtzee game that contains five die images. When I created the JAR file, I explicitly added the source and images to it. But when I go to run the app, no die images show up. I referenced Java's Creating a JAR File tutorial (http://java.sun.com/docs/books/tutorial/deployment/jar/build.html) but I didn't find anything useful regarding my issue.
    My Images folder is under my classes folder: Yahtzee\build\classes\Images
    I create the JAR from within classes and I add the die images that are in Images by using change directory option -C.
    jar cvfm Yahtzee.jar Manifest.txt *.class -C Images/ .
    I'm using the verbose option v, which allows me to see every file that gets added to the JAR, so I know there's no problem with missing files.
    Any thoughts?
    Message was edited by:
    d_mart

    By the way I'm adding the images into the JAR, they should be in its root.
    This is what I'm doing with my code. I have five die buttons that get a random die face, which are represented with my die images. I have an up-state (unselected) and a down-state (selected) image for each die face (1, 2, 3, 4, 5, 6). I have two different states because just like poker, you keep the cards that you want and disgard the ones that you don't want and in return, you get some random card for every card that you disgarded. So the selected and unselected images should be self-explanitory now. In Yahtzee, you have up to three rolls per hand, which I have a button that handles the rolls (<=3). I have stored my die images in a 2D array.
    My image file names are as follows:
    d1up.png, d1down.png, d2up.png, d2down.png,...d6up.png, d6down.png
    private Icon [][] dieImages;
    private Icon defaultDieImage;
    private Die [] dieButtons;
    // INITIALIZE DIE IMAGES
    defaultDieImage = new ImageIcon("../Yahtzee/src/Images/blank.png");
    dieImages = new ImageIcon[2][6];
    for(int i = 0; i <= 5; i++) {
         // up state images
         dieImages[0] = new ImageIcon("../Yahtzee/src/Images/d"
    + (i + 1) + "up.png");
    // down state images
    dieImages[1][i] = new ImageIcon("../Yahtzee/src/Images/d"
    + (i + 1) + "down.png");
    Those images are then loaded into the die buttons (depending on the roll).
    FYI, I just finished my 2nd semester of Java, so I'm still pretty new to the language and it's the only language that I know so far. With that said, please forgive for any dumb mistakes. It's all good though, I learn something new everyday. So you say that I should be using something like getClass().getClassLoader().getResource("an_image.jpg"); in my code instead of what I have?
    I hope the information that I provided helps.
    Dan

Maybe you are looking for

  • Creation of forms in Custom list for different departments in share point online .

    Hello , We are using office 365 E3 plan in our organization.Recently we got a requirement from the management to create forms for different departments.I will explain a bit more on requirement. We have three departments A, B & C .We want to create a

  • DVD Plays on computer drives, but not on dvd players

    iDVD 06 - This is a new problem, just happened two days ago. Previous dvd's burned with idvd 06 work just fine on old and new dvd players. I always test them after burning. However this new project will only play on computer dvd drives (mac or pc) bu

  • Getting java.io.NotSerializableException: sun.management.MemoryPoolImpl

    Hi, While trying to get JVM Memory pool information of a remote computer ,am getting java.io.NotSerializableException. I used following method ManagementFactory.getMemoryPollMXBean(). Please help me to solve these exception. java.io.NotSerializableEx

  • Startup Error - Worried About Recovering Data - Need Help!

    Hi All... This is my first time posting to the forum, and I'm hoping someone can help me. Last night, I used my MacBook Pro (specifics are pasted below) with no issues at the airport. I then boarded my flight, stowed my laptop under my seat, and land

  • No AUTOMATION in InDesign CS5!?

    hi, I'd like to use the data merge tool which has served very well in the past. Now, I can't find the menu window/automation. any idea what's happened? InDesign CS5 Design Premium / Windows 7 / 32 bit thanks folks...