How to resize image in JSP using JAI ??!!

Please help me how to resize an JPEG image from my JSP, could I use JAI lib ? how ?

Hello,
I had the same problem few months ago ( in that case i used Jimi instead of JAI).
The answer to your question is: use the java class called "Image".
Infact you can use JAI just for load or save to disk your image that you have to resize and then use the following code to resize the image :
Image imgResized = img.getScaledInstance(100,1,Image.SCALE_AREA_AVERAGING);
The object "img" is the image to resize and the object "imgResized" is the image resized with width equals to 100 and with a right height.
I used Jimi just to save my image and i think that with JAI there is a method to do this.
You can use JAI to load in memory your image too so you can avoid problem with MediaTraker class.
I hope that this can help you.
Cheers.
Stefano

Similar Messages

  • How to resize image using java imageio

    Hello ,
    I want to know how to resize image using java imageio.
    I dont want to use java awt because i am writing a web application.
    help is very much needed
    thank you.

    Just use an AffineTransform !
    Its much easier

  • How to improve image resolution with using filters

    how to improve image resolution with using filters?

    image resolution, Please check the below links. They should give you a clear idea about Resizing and resampling images.
    http://helpx.adobe.com/photoshop/kb/advanced-cropping-resizing-resampling-photoshop.html#m ain_Resizing_and_resampling_images
    Understanding Resize vs. Resample | Learn Photoshop CS6 | Adobe TV
    Cheers!
    ~ Arpit

  • How to send images through PI using SOAP adapter

    hi,
    Can anybody tell me how to send images through PI using SOAP adapter.
    Regards ,
    Loveena

    Hi Loveena,
    only as attachments of a SOAP message.
    Regards,
    Udo

  • How to store images in database using java

    hii
    how to store images in database using java..........
    Message was edited by:
    naveennaga

    I asked a similar question once and the answer I got was - Don't.
    Instead, store the images on a drive somewhere and store the path in the database.
    But I'm no expert - that's just what I was told by someone who does this kind of stuff a lot.
    Hope that helps.

  • How to resize image on my mac?

    How to resize image on my mac?

    What version of Mac OS X do you have? In Preview under 10.9 Mavericks (I believe 10.8 too), this is what I see:
    The padlock is next to the unit (pixels, etc) selection box.
    Matt

  • How to do  validation in jsp using javascript

    how to do validation in jsp using javascript

    The same way you do with any HTML page.
    Catch the onclick/onsubmit event, do your validation in javascript and then allow/cancel the action as required.
    However this is javascript validation only - javascript can never call JSP code.

  • How to embed image in jsp(j2ee application)

    Hi ,
    I have created a simple jsp application and deployed on portal.
    in the first jsp i need to show a jpeg image
    I am referencing the image wth a simple HTML SRC="image.jpg" tag
    image is placed in same folder as jsp.
    However this does not work. when i deploy on portal and access the jsp using following url
    http://hostname:port/applicationname/index.jsp
    the image is not shown..?
    What is the reason..?
    Please help.
    Thanks
    rocky

    Hi Rocky,
    Are you using the DC?
    if yes then you need to put the image inside the component folder. after that close the application
    & reopen. You will get the image.
    In case this does not work then try refreshing the portal through server side. Once the cache is cleared, it will be up to view.
    Also check the Activity list you have created. It should be added to the dtr properly or else it wont be reflected once reimported the configurations.
    Regards
    Chander Kararia

  • How to display PDF in JSP using Iframe

    Hi All,
    I am using Struts 2. I am building my file in ActionClass with seperate Method like getGeneratedPDF() in which, I am setting header of response and writing into PDF.
    This method will be called from JSP by this way
    s:property value="getGeneratedPDF()" />
    But It displayed Junk Characters , and this PDF is not static (already Generated). It is generated and build on Fly.
    I have 2 questions 1 -- How to display PDF in JSP in proper way without Junk Character in it?
    questions 2 -- How to display it in Iframe?
    Please help me , If you know the solution.
    Thanks in Advance,
    Jimmy

    jamy_26 wrote:
    But It displayed Junk Characters , and this PDF is not static (already Generated). It is generated and build on Fly.A PDF file is a binary file, not a text file, and you're trying to display it as String. Of course you would get "junk characters". Have you ever tried opening a binary file (pdf, doc, jpg, xls, etc) using a text editor like Notepad?
    I have 2 questions 1 -- How to display PDF in JSP in proper way without Junk Character in it?Display it as binary stream, not as text stream. You can display it standalone, just let the link/form/addressbar URL point to some Servlet which writes the InputStream of the PDF file to the OutputStream of the response, along with a correct set of response headers (at least content-type, content-disposition and content-length), so that the browser can open it in the correct application (which is usually Acrobat Reader). If you want to embed the PDF file in a JSP, then one of the ways is indeed using the HTML <iframe> tag.
    questions 2 -- How to display it in Iframe? Just let the iframe URL point to the aforementioned Servlet.
    You can find here an example of a generic file servlet, you may find it useful to get the idea how to do it: [http://balusc.blogspot.com/2007/07/fileservlet.html].

  • How to resize Image Jpeg ?

    I have a problem when I scale file image Jjpeg.
    My code :
    public void resize(Image img){
    BufferredImage bimg = toBufferedImage(img);
    AffineTransform tx = new AffineTransform();
    tx.scale(125,125);
    AffineTransformOp op = new AffineTransformOp (tx,AffineTransformOp.TYPE_BILINEAR)
    bimg = op.filter(bimg, null);
    public static BufferedImage toBufferedImage(Image image) {
    if (image instanceof BufferedImage) {
    return (BufferedImage)image;
    // Determine if the image has transparent pixels; for this method's
    // implementation, see e661 Determining If an Image Has Transparent Pixels
    boolean hasAlpha = hasAlpha(image);
    // Create a buffered image with a format that's compatible with the screen
    BufferedImage bimage = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    try {
    // Determine the type of transparency of the new buffered image
    int transparency = Transparency.OPAQUE;
    if (hasAlpha) {
    transparency = Transparency.BITMASK;
    // Create the buffered image
    GraphicsDevice gs = ge.getDefaultScreenDevice();
    GraphicsConfiguration gc = gs.getDefaultConfiguration();
    bimage = gc.createCompatibleImage(
    image.getWidth(null), image.getHeight(null), transparency);
    } catch (HeadlessException e) {
    // The system does not have a screen
    if (bimage == null) {
    // Create a buffered image using the default color model
    int type = BufferedImage.TYPE_INT_RGB;
    if (hasAlpha) {
    type = BufferedImage.TYPE_INT_ARGB;
    bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
    // Copy image to buffered image
    Graphics g = bimage.createGraphics();
    // Paint the image onto the buffered image
    g.drawImage(image, 0, 0, null);
    g.dispose();
    return bimage;
    }

    This is my code :
    private ImageIcon getImageIcon(String path){
    ImageIcon iIcon = new ImageIcon(path);
    if(iIcon.getIconHeight() > 125 || iIcon.getIconWidth() > 125){
    Image img = iIcon.getImage();
    int iw = img.getHeight(null);
    int ih = img.getWidth(null);
    BufferedImage bImage1 = toBufferedImage(img);
    BufferedImage bImage2 = new BufferedImage(400,400,1);
    AffineTransform tx = new AffineTransform();
    tx.scale(400,400);
    AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
    BufferedImage bImage3 = op.filter(bImage1, bImage2);
    img = Toolkit.getDefaultToolkit().createImage(bImage2.getSource());
    return (new ImageIcon(img));
    if(iIcon == null)
    return null;
    return iIcon;
    public static BufferedImage toBufferedImage(Image image) {
    if (image instanceof BufferedImage) {
    return (BufferedImage)image;
    // Determine if the image has transparent pixels; for this method's
    // implementation, see e661 Determining If an Image Has Transparent Pixels
    boolean hasAlpha = hasAlpha(image);
    // Create a buffered image with a format that's compatible with the screen
    BufferedImage bimage = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    try {
    // Determine the type of transparency of the new buffered image
    int transparency = Transparency.OPAQUE;
    if (hasAlpha) {
    transparency = Transparency.BITMASK;
    // Create the buffered image
    GraphicsDevice gs = ge.getDefaultScreenDevice();
    GraphicsConfiguration gc = gs.getDefaultConfiguration();
    bimage = gc.createCompatibleImage(
    image.getWidth(null), image.getHeight(null), transparency);
    } catch (HeadlessException e) {
    // The system does not have a screen
    if (bimage == null) {
    // Create a buffered image using the default color model
    int type = BufferedImage.TYPE_INT_RGB;
    if (hasAlpha) {
    type = BufferedImage.TYPE_INT_ARGB;
    bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
    // Copy image to buffered image
    Graphics g = bimage.createGraphics();
    // Paint the image onto the buffered image
    g.drawImage(image, 0, 0, null);
    g.dispose();
    return bimage;
    When I recieve Img3 which is not same original Image (img1)
    Please help me ?

  • How to resize image in flash

    Hi guys any tips or advise on how to resize an image i know
    there are various tools but is there a tool in Adobe flash
    professional and how can I do it
    cheers

    In what way do you want to resize the image? Are you
    importing graphics that you want to resize when you import them at
    runtime? Do you want to resize the images to a specific size or
    relative to one imported image? Or do you want to resize one or
    more images for a specific purpose at runtime based on some user
    input? Or is it something else?

  • How to display image in database using php

    i've try search all hope that you all can give me some guidance how to display data that is in image or BLOB using PHP. just a query and php code that will make display of the image. hope that you all show me the example or give me reference that i need to solve my problem.

    Hi,
    Have a check on these Google results, you might find something there...
    http://www.google.com/search?sourceid=navclient-ff&ie=UTF-8&q=%22display%20image%22%2Boracle%20%2Bphp

  • How to resize image with high quality

    I refer lot of examples in image resizing. But quality of resized image not good. pls can give me solution for that with code?

    I refer lot of examples in image resizing.Have you read [_this article_|http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html]?
    db

  • How to include servlet in JSP using Include Directive?

    Hi experts,
    am a beginner to JSP.. I want to know,
    is it possible to include a servlet in jsp using include directive? could any one explain me...

    No it is not possible.
    Include directive is like copying and pasting some text into a JSP file, and then translating/compiling it.
    So the only thing you can include with the <%@ include %> directive is a jsp fragment
    It is a static translation/compile time include and thus will always be the same
    By contrast <jsp:include> is a runtime include, and includes the result of running the imported url.
    That URL has to be a complete/standalone jsp/servlet/whatever. However as it is runtime, it can take parameters where the include directive can not.
    Does that answer your homework question?
    Cheers,
    evnafets

  • How to show images in jsp dynamic

    Hi all,
    I am beginner in web technology and am faced with some prob. I have a form in which user enters his unique id....n submits...then web server call ejb which fetches data for that unique id from DB and does some operation and also fetch photograph which i need to display in my response jsp along with data....this photograph is different for each ID and i want to know how to display this image , i dont want to use applet.....i need good response time..and i have lot of hits per second on my site....i was planning to have separate frame wherein image will be loaded and use AJAX for the same but i do believe their mite be some other simple method for the same please suggest.....
    Regards,
    beginner83.

    I am not great at UI, but see if this thread is of any help:
    http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=20&t=007725

Maybe you are looking for

  • Error while deleting UIElements from existing view of webdynpro project

    hiiii everybody, I have an existing project which i need to modify.so when i am trying to delete some UIElements from existing view and saving the metadata, itz showing error as for example: 1)Group Group2 header is missing 2)wdThis cannot be resolve

  • My Mac Pro keeps crashing

    Every once in a while my Mac Pro crashes and the screen just turns into a bunch of vertical cream colored bars. Any help would be very much apriciated. Thank you Error message: Interval Since Last Panic Report:  215528 sec Panics Since Last Report:  

  • IPhone 5 won't set up

    I am trying to set up my new iPhone 5 and I just synced all of my data to iTunes. It won't advance to the next step. It still says 'connect to iTunes' even though I already synced it.

  • Unable to import IPhoto 6 slideshows to IDVD 6

    When I try to send a SLIDESHOW with captions and music prepared in iPhoto 6 to IDVD to burn to a DVD by choosing Share>Send to IDVD i get the following message "An error occured while exporting the slideshow, the export movie file could not be create

  • Blotted method parameter list

    As part of a class, I have a method of this form: static void superVisor( double ZC, double thetaX, double thetaY) The program runs fine but now I need to pass multiple values of ZC, thetaX and thetaY. The only way I can think of is to declare them a