Generate Thumbnail and Display to Browser from a Servlet

I have the following code working locally generating a thumbnail jpeg to the file system.
My question is how would I do the same in a servlet and display the results to the browser?
I don't necessarily want to save the thumbnail to the filesystem on the server, if I can get
away with it. To sum up, using a servlet I would like to reference a full size image (jpeg) on the filesystem and dynamically build a thumbnail in memory and display in via the browser. Can this be done? Help would be greatly appreciated.
import java.awt.* ;
import java.awt.image.* ;
import java.awt.event.*;
import java.awt.geom.*;
import java.io.* ;
import java.net.*;
import javax.swing.*;
import com.sun.image.codec.jpeg.* ;
public class GenerateThumbnail {
public static void main (String args[]) {
try {
// Load normal-sized file
InputStream in = new FileInputStream("test.jpg");
JPEGImageDecoder dec = JPEGCodec.createJPEGDecoder(in);
BufferedImage inImg = dec.decodeAsBufferedImage();
// Scale down to half the size
AffineTransform xform = AffineTransform.getScaleInstance(0.3,0.3);
AffineTransformOp xformOp = new AffineTransformOp(xform,AffineTransformOp.TYPE_BILINEAR);
BufferedImage outImg = new BufferedImage(150,112, BufferedImage.TYPE_INT_RGB);
xformOp.filter(inImg, outImg);
// encode the reduced image
OutputStream out = new FileOutputStream("thumbnail.jpg");
JPEGImageEncoder enc = JPEGCodec.createJPEGEncoder(out);
enc.encode(outImg);
in.close();
out.close();
catch (IOException ie) {}
}

Why don't you just have the servlet send out the following HTML:
<img src="test.jpg" width=150 height=112>
Of course the full-sized test.jpg will be downloaded by the browser, but the display will be limited to the specified width and height!
If this helps, don't forget the Dukes!
V.V.

Similar Messages

  • How to read and display a signal from my a miccrontroller (MCB1700) onto labview connected via a CAN port on a PXI machine

    How do you read and display a signal from my a miccrontroller (MCB1700) onto labview connected via a CAN port on a PXI machine?
    I tried using a DAQ Assistant but the CAN port is not included as one of the supported physical channels even though all its drivers are upto date.
    Please help..
    Thanks.
    Solved!
    Go to Solution.

    Attached herewith is a print screen of what is showing on MAX
    The CAN ports are on NI PXI-8461
    Hopefully that clarrifies something.
    Attachments:
    Untitled.png ‏212 KB
    Untitled.png ‏212 KB

  • How to read and display a signal from my PIC Microcontr​oller onto Labview?

    Hi,
    I am doing a project on a Pulse Oximeter and i am trying to read and display the signal from my PIC Microcontroller on Labview? How do i go about doing it? I am using the PIC16F877 and also making use of the USART?
    How do i implement and initialise the USART in PIC16? What are the steps to be taken, please guide me through the process? The link provides information regarding the USART connection, initialisting and stuff? Is it correct to use these codes in my program?Link: http://ww1.microchip.com/downloads/en/AppNotes/007​74a.pdf
    Also, i am using the RS232 serial interface to connect to the PC? The connector i am using is the DB9 Connector. Which template and VI can i use? Am i supposed to use the NI-DAQmx and VISA? Also, for my USART connection, i am using the MAX232 Driver which is applicable for my application as i am working with +5V. So far, i have been reading and trying out on Labview and the steps i have taken are:
    1) Open a New VI and used the Instrument I/O(Read & Display) template?
    2) How do i configure the Instrument I/O Assistant Express VI to read the info from my device connected to COM1?
    3) I was reading the Labview Manual, 'Getting Started with Labview' and i was following the steps under Page 55, Communicating with an Instrument. Am i on the right track?
    4) How do i check and make sure that the port settings of the I/O Assistant and my PIC Micro Match
    Please help me out and guide me through the process. I am student at a polytechnic and i am very new to Labview and the software is used as a development tool for the project. I have a deadline to meet and i hope i can get a response as fast as possible. Your help will be kindly and greatly appreciated. I hope to hear from you guys soon.You can e-mail me all your answers at [email protected]
    Thank You
    Best regards,
    Ashwin
    Ashwin Kumar Mansukhani
    Attachments:
    Getting Started with Labview.pdf ‏901 KB

    Hi Ashwin,
    It is a good idea to first be able to communicate with the microcontroller using some sort of serial communication software such as "HyperTerminal" or "Procomm", etc. Refer to MicroChip's recommendations on this.
    Once that works, then you are ready to use LabView.
    Here is a link which covers many aspects of serial communication. Link - click here
    You probably received a development kit. They usually have a readily available interface. It's been a long time since I played with the PIC, but I seem to remember that you need to program the serial communication driver (as well as at least a bootloader) to get the serial communication going. The driver contains the necessary protocols so that you PC can have a machine conversation with the target (PIC).
    It sounds like a fun & interesting project. Please avoid to have replies to your personal email. By having the answers posted to this thread, you will get much more support and advice.
    Have fun,
    JLV

  • How to read and display a signal from my PIC Microcontroller onto Labview

    Hi,
    I am doing a project on a Pulse Oximeter and i am trying to read and display the signal from my PIC Microcontroller on Labview? How do i go about doing it? I am using the PIC16F877 and also making use of the USART?
    How do i implement and initialise the USART in PIC16? What are the steps to be taken, please guide me through the process? The link provides information regarding the USART connection, initialisting and stuff? Is it correct to use these codes in my program?Link: http://ww1.microchip.com/downloads/en/AppNotes/00774a.pdf
    Also, i am using the RS232 serial interface to connect to the PC? The connector i am using is the DB9 Connector. Which template and VI can i use? Am i supposed to use the NI-DAQmx and VISA? Also, for my USART connection, i am using the MAX232 Driver which is applicable for my application as i am working with +5V. So far, i have been reading and trying out on Labview and the steps i have taken are:
    1) Open a New VI and used the Instrument I/O(Read & Display) template?
    2) How do i configure the Instrument I/O Assistant Express VI to read the info from my device connected to COM1?
    3) I was reading the Labview Manual, 'Getting Started with Labview' and i was following the steps under Page 55, Communicating with an Instrument. Am i on the right track?
    4) How do i check and make sure that the port settings of the I/O Assistant and my PIC Micro Match
    Please help me out and guide me through the process. I am student at a polytechnic and i am very new to Labview and the software is used as a development tool for the project. I have a deadline to meet and i hope i can get a response as fast as possible. Your help will be kindly and greatly appreciated. I hope to hear from you guys soon.You can e-mail me all your answers at [email protected]
    Thank You
    Best regards,
    Ashwin
    Ashwin Kumar Mansukhani
    Attachments:
    Getting Started with Labview.pdf ‏901 KB

    Hi Ashwin,
    I am not familiar with the PIC Microcontrollers, but I am assuming you mean that you have the microcontroller sending out serial data that you want to read on another computer with LabVIEW. Please let me know if this is incorrect.
    What type of data is coming out of the serial port? Is it ASCII, or binary? The reason I ask this is that the serial communication in LabVIEW is done through a protocol called VISA, which uses ASCII data to send and receive. You can later convert this data into whatever form you need, but this is what it is designed to read and write.
    You can check the settings such as baud rate and data bits in a configuration utility called Measurement and Automation Explorer, or MAX. When you open up the MAX interface, you can expand the Devices and Interfaces entry on the left, and then expand the Ports entry to see your serial port. When you highlight this port, select the Port Settings tab at the bottom of the window, and you can see what the current settings are, and change them if you need to. You can also set these parameters in LabVIEW using the VISA Configure Serial Port VI.
    You can also test communication in MAX by right clicking on the correct port and choosing Open VISA Session. Then choose the Basic I/O light blue tab, and then go to the Read tab. When you click execute, it should read in what is coming from the serial port. This will allow you to verify that the correct information is coming in before even trying to acquire the data in the LabVIEW environment.
    In LabVIEW, the best resource to use the Basic Serial Write and Read example program that ships with LabVIEW. By examining the block diagram of this program, you will be able to see the basic programming flow of serial communication in LabVIEW.
    I hope this information was helpful! Please let us know if there's anything else we can help with.
    john
    Applications Engineer

  • Trying to import video files.  Clock on files and hit import.  Imovie says generating thumbnails and importing.  Then after loading, no movies there.  help?

    My 14 year old son is trying to import videos into iMovie.  He's done this a dozen times before with no problem.  Here is what he's doing "I went to import movies, clicked on the idv files and hit import.  On iMovie it said "generating thumbnails, and importing".  Then it gave the loading sign.  When it was done, none of the movies/videos were in Imovie.  He needs to have this done as a xmas gift for a friend by Thursday .

    After much research and troubleshooting, GoToMeeting replied with the final answer: We do not support the uploading of recordings to editing software. If you are having issues uploading a recording, unfortunately, we do not have tools or steps to resolve this. It is not a supported feature. I am sorry for any inconvenience this may have caused you. 
    The no longer plan to support editing of recordings made with their software.  So, we are planning to find a new meeting provider.

  • How do I Display a string from a servlet into a JSP Page???? NEED HELP!!!!

    Hi guys,
    How do I Display a string from a servlet into a JSP Page...
    Ive tried so many bloody things!.....
    Simply.
    I get text from JSP. The servlet does what ever it does to the string.
    Now. Ive create sessions and bean things,.... how the hell do I display it in a text box... I can display on the screen.. but not in the text box.!!!
    please help!!!

    hmmm, I dont really like using JSP programming, u should be using JAVA..
    the way to do it is:
    Call and cast to the bean like this:
    <%@ page import="beans.*" %>
    <% //cast to bean get request create object
    userNameBean u= (userNameBean) request.getSession().getAttribute("userNameBean");
    then... all you do is call it like this:
    <input type="text" name="firstName" value="<%= u != null? u.getFirstName(): "" %>">
    this is the real programmers way,,,
    chet.~

  • Create or open a new browser from a servlet

    Hi everybody(sorry my english is so terrible), i have one problem .It`s possible to create ,instance or open a new browser from a servlet without javascript?.

    Hi everybody(sorry my english is so terrible), i have
    one problem .It`s possible to create ,instance or
    open a new browser from a servlet without javascript?.Well, sorta. You have to create a link with a target to "_blank" that the user clicks on. For example:
    Some Page
    will open somePage.jsp in a new browser window. There would be no way, other then js to do it automatically (and often those are blocked, now-a-days with pop-up blockers), flash (can be blocked as well, requires a plugin to use, costs money to get the developement kit), or an applet (java program embeded in web page, requires a plugin, can be blocked). Or some other client-side script/application. (ie servlets run on the server so they can't interact with the client's computer. You need something on the client's computer to do the job).

  • How to retrieve xml file from BLOB and display on browser with css/xslt

    Hi All,
    I am new to xml. I am storing my xml file into BLOB in database. Now in my jsp page I want to retrieve this xml file from BLOB and display in HTML/CSS/XSLT form...
    Pl. guide me.. any docs..?? Logic...??
    Thanks in Advance.
    Sandeep Oza

    Hello Sandeep!
    I'm not familiar with jsp but logic should be as follows:
    -in jsp page instantiate XML parser
    -load specified BLOB into parser
    Now you may traverse the XML tree or you might load XSL file and use transform method to transform XML according to XSL file.
    I have an example where I'm selecting XML straight from relational database and then transform it using XSL into appropriate HTML output, but it's written in PSP.
    You can try http://www.w3schools.com/default.asp for basics on XML, CSS, XSL. It's easy to follow with good examples.
    Regards!
    miki

  • How to import and display an applet from JSP

    i m using netbeans 5.0
    i have class named myapplet.class
    and jsp named myjsp.jsp
    now i want to access(import) this myapplet.class from jsp
    also i want to display this applet from this jsp
    i am able to do either thing but not both
    so please help me it is so urgent and important for me bcoz
    i have to complete my project as early as possible
    Thanks in advance

    my jsp source file page path is D:\Reliance
    project\WebApplication3\web\
    and classes path is D:\Reliance
    project\WebApplication3\build\web\WEB-INF\classes\
    so problem is that if i want to use myapplet.class
    then i have to put my class in D:\Reliance
    project\WebApplication3\build\web\WEB-INF\classes\
    location
    but at that time i am not able to display this applet
    on my jsp
    if i put my myapplet.class in
    D:\Reliance project\WebApplication3\web\ then i m
    able to display
    applet but not able to access(import) this class
    hope you will got the problem!!!
    thanks for your reply !!!try to set the path of your applet on jsp something like this
    "WEB-INF/classes/myclass.class"

  • How to retreive and display output list from BAPI

    Hello
    I am making an applcation using SUP 2.0, and this application make an user to get leave history using a Mobile System from SUP.
    I've created the MBO as Attributes using the BAPI: BAPI_LEAVE_HISTORY.
    This BAPI has some parameters IN and OUT.
    Input parameters are Employee Id and date.
    The parameter OUT is a List that retreives the employee leave history.
    Anyone has an Idea or example how to retreive the output from BAPI and displaying the output on a screen.
    Any tips or blogs that can help me?
    Thanks all!
    Satish

    Hi David Brandow,
    I have tried your solution where I just created a MBO for my 'operation' and I'm using sync parameters to execute the RFC.
    The problem I'm facing is, for example, if I create a record it gets saved in the MBO table and the record successfully gets created in SAP as well after a sync. But when I create another record and sync, the previously saved record in MBO table also gets executed so I'm getting duplicate entries in SAP.
    Have you or anyone faced this problem?
    Any response is appreciated. Please let me know if I'm not clear, I realized its a complicated scenario.
    Thanks,
    Sandeep

  • Having a problem calling and displaying a page,from outside the class?? :-(

    Hi,
    I seem to be having a problem displaying a class from a different page, it is called but all i get is a blank page, even though when i compile and run it by itself it works fine?? I call it like:
    if(source == animateVMS)
                   {ImageSequence i = new ImageSequence();
                    i.setSize(Toolkit.getDefaultToolkit().getScreenSize());
                    i.show();
                    this.dispose();
                   }but it only displays a blank screen?? I think it is sumthing to do with the contructor of the following class?
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class ImageSequence extends JFrame implements ActionListener
       {    static ImageSequence controller = new ImageSequence();
                 ImageSQPanel imageSQPanel;   
            static int frameNumber = -1;   
            int delay;   
            Thread animatorThread;   
            static boolean frozen = false;   
            Timer timer;    
            //Invoked only when this is run as an application.   
        public static void main(String[] args) {
              Image[] waving = new Image[10];        
              for (int i = 1; i <= 10; i++) {
                    waving[i-1] = Toolkit.getDefaultToolkit().getImage("images/T" + i + ".gif");
              JFrame f = new JFrame("ImageSequenceTimer");
              f.addWindowListener(new WindowAdapter() {
                 public void windowClosing(WindowEvent e) {               
                                System.exit(0);           
             //ImageSequence controller = new ImageSequence();
             controller.buildUI(f.getContentPane(), waving);
             controller.startAnimation();
             f.setSize(Toolkit.getDefaultToolkit().getScreenSize());       
             f.setVisible(true);    }    
             //Note: Container must use BorderLayout, which is the    
             //default layout manager for content panes.   
             void buildUI(Container container, Image[] dukes) {
                          int fps = 10;        
             //How many milliseconds between frames?       
             delay = (fps > 0) ? (1000 / fps) : 100;        
             //Set up a timer that calls this object's action handler       
             timer = new Timer(delay, new TimerListener());       
             timer.setInitialDelay(0);       
             timer.setCoalesce(true);        
             JPanel buttonPanel = new JPanel();        
             JButton play = new JButton("PLAY");       
             play.addActionListener(this);
             JButton stop = new JButton("STOP");       
             stop.addActionListener(this);
             JButton back = new JButton("Back");        
             back.addActionListener(this);
             imageSQPanel = new ImageSQPanel(dukes);       
             container.add(imageSQPanel, BorderLayout.CENTER);        
             container.add(buttonPanel, BorderLayout.SOUTH);       
             buttonPanel.add(play);       
             buttonPanel.add(stop);               
             buttonPanel.add(back);   
          public void start() {       
             startAnimation();   
          public void stop() {       
             stopAnimation();   
          public synchronized void startAnimation() {
                       if (frozen) {            
          //Do nothing. The user has requested that we            
          //stop changing the image.       
                         else {           
          //Start animating!           
          if (!timer.isRunning()) {               
          timer.start();           
          public synchronized void stopAnimation() {       
          //Stop the animating thread.       
          if (timer.isRunning()) {           
          timer.stop();       
       /**     * Listener for the play, stop, restart, and back buttons.     */   
       public void actionPerformed(ActionEvent e) {       
       JButton button = (JButton)e.getSource();       
       String label = button.getActionCommand();       
       if("PLAY".equals(label))           
       start();       
       if("STOP".equals(label))           
       stop();
       if("BACK".equals(label))
       {varsity v = new varsity();
        v.setSize(Toolkit.getDefaultToolkit().getScreenSize());
        v.show();
        this.dispose();
       /**     *  Listener for the animation timer.     */   
       private class TimerListener implements ActionListener {       
         public void actionPerformed(ActionEvent e)        {            
       //Advance the animation frame.           
       frameNumber++;             
       //Display it.           
       imageSQPanel.repaint();       
        class ImageSQPanel extends JPanel {       
        Image dukesWave[];        
        public ImageSQPanel(Image[] dukesWave) {           
        this.dukesWave = dukesWave;         }        
        //Draw the current frame of animation.       
        public void paintComponent(Graphics g) {           
        super.paintComponent(g);
        //paint background            
        //Paint the frame into the image.           
        try {               
        g.drawImage(dukesWave[ImageSequenceTimer.frameNumber%10],0, 0, this);            
        catch (ArrayIndexOutOfBoundsException e) {               
        //On rare occasions, this method can be called                
        //when frameNumber is still -1. Do nothing.               
        return;           
    }Could someone please try to help me fix my problem!
    Kind Regards
    RSH

    cheers that did the trick!! : - )
    I was wondeing if you could help me with one more thing, its about getting rid of an old page after you press a button to go to a new page! this.dispose doesnt wrk below:
            JButton back = new JButton("BACK");
            back.addActionListener(new ActionListener()       
                  public void actionPerformed(ActionEvent e)           
                       VowelmSound s = new VowelmSound();
                        s.setSize(Toolkit.getDefaultToolkit().getScreenSize());
                        s.show();
                        //this.dispose();           
             });        and this is main
    public static void main(String[] args)
    JFrame draw = new punjabidraw();   
    draw.setVisible(true);   
    }I was wondering what I could use to get rid of the old page??
    Kind Regards
    Raj

  • How to retreive and display return value from BAPI

    Hello,
    I am using SUP to create a sales order application. In my MBO I have a create operation which calls a BAPI to create a sales order. How can I retrieve the return value (saled doc number) and display it on a screen and display it as an Alert of BB application.
    Regards
    Nidhideep Bhandari

    Hi David Brandow,
    I have tried your solution where I just created a MBO for my 'operation' and I'm using sync parameters to execute the RFC.
    The problem I'm facing is, for example, if I create a record it gets saved in the MBO table and the record successfully gets created in SAP as well after a sync. But when I create another record and sync, the previously saved record in MBO table also gets executed so I'm getting duplicate entries in SAP.
    Have you or anyone faced this problem?
    Any response is appreciated. Please let me know if I'm not clear, I realized its a complicated scenario.
    Thanks,
    Sandeep

  • How to hide "View in Browser" and "Edit in Browser" from ECB injected by Office Web Apps Feature

    Hi,
    i am currently using custom_AddDocLibMenuItems to implement a custom ECB menu for my document library. I need to activate Office Web Apps. My custom_AddDocLibMenuItems has two items
    -> custom dialog
    -> open in office web apps
    After activating the Office Web Apps Feature at the SiteCollection Level, this Feature "injects" in my custom menu the following
    additional menu items:
    -> View in Browser
    -> Edit in Browser
    Its curious to see that, cause implementing the js function custom_AddDocLibMenuItems with
    return true should be the way to impolement a custom ECB menu without having other features/solutions injecting things in this menu!? Or did i misunderstood something here?
    My question is: How can i prevent this ...
    a) without deactivating the Office Web Apps Feature
    b) without modifying the core.js
    I hope someone can help!
    Best Regards
    Bog
    Developers Field Notes | www.bog1.de

    May be this can help
    http://extreme-sharepoint.com/2011/10/29/hide-menu-ecb/http://pholpar.wordpress.com/2011/07/24/hiding-ecb-custom-actions-based-on-specific-list-properties-using-the-client-object-model/Or tryhttp://stackoverflow.com/questions/13795858/how-to-hide-view-in-browser-in-document-library-in-sharepoint-2010-using-javascr $(document).ready(function(){
    $('.ms-MenuUIPopupBody').live('blur', function() {
    var elm = $("div.ms-MenuUIULItem a:contains('View in Browser')");
    elm.remove();
    $("div.ms-MenuUIULItem a:contains('Edit in Browser')").remove();
    It is hiding menu only on focus or blur or mouseover
    I wants it to be hide on load AS soon as i Click on "V" option on right side of document it should hide View in Browser and Edit in browser
    When I click on V option ![I wants As soon as i Click on v option right side of test it should hide view in Browser and edit in browser][1]
    If this helped you resolve your issue, please mark it Answered

  • HT1338 my i movie does not finish generating thumbnails and stays locked on that screen

    I movies asks to generate thumbnails but never finishes loading?  Help!

    - See:
    iPod touch: Hardware troubleshooting
    - Try another cable
    - Try another charging source
    - Look at the dock connector on the iPod. Look for abnormalities like bent or corroded contacts, cracked or broken plastic.
    - Make an appointment at the Genus Bar of an Apple store.
    Apple Retail Store - Genius Bar

  • Problems while reading and displaying .pdf-Documents from Bfile

    Hi
    I want to read and display .pdf-Documents in Adobe-Reader that are stored as BFile. While displaying the Document Adobe Reader is showing several Errors like " ..less Picture-Data read than expected.. ". Is this a Buffer-Problem? or whatelse ??
    Thanks for help
    null

    PrintStream wr = new PrintStream(socket.getOutputStream());
    wr.close();I suspect this is the problem. You could try socket.shutdownOutput() - or you could just leave the streams alone and let socket.close() shut things down.
    Grant

Maybe you are looking for

  • Streaming audio restarts after stopallsounds

    Hello, the site in question is thirdcache.com - i've got streaming audio playing as background music, however after someone clicks the stop all sounds button it stops, however when the background music reaches the end of it's timeline, it starts back

  • IMac 2012 Electric specifications

    Hi, I'm looking for the right UPS to supply to 5 iMac 21", 1 time capsule, 1T external HD. Neighter I could find the VA electrical specifications for the new iMac 21". Can u help me? thanx

  • Document Approval Report

    Hi, Does anyone know if there is a report that will show the details of a document approval process? That is, I would like the report to show the date and time of the document when it went for approval (along with the last person that edited the docu

  • Lightroom not exporting jpegs from a nikon d750?

    I know lightroom doesn't support the RAW files from the d750 but I understood it supports the jpeg files. However, when I go to export them it acts as if its doing it but it doesn't. I am doing everything as usual, but the picture does not come up wh

  • Display report in Lotus Notes

    We are bursting our report and emailing it to our users. The report is embedded in the email so when you open the email you can see the table directly. The problem is for our Lotus Notes users in Germany and Spain. When they open the email the report