Image Resizing Using Java

Hi.
I am new to Java and have a question.
I have an image at this path: "c:\images\pic1.gif".
I want to take this image, resize it, and save it to a different path.
I don't have any outside Toolkits.
How do I do this?
Or, more simply, how do I use the Image and BufferedImage classes?
I cannot figure out how to create a BufferedImage object using the path for the image I have.
Thanks in anticipation.

the article referred by previous answer is pretty good, but you can do it simpler. Just:
1. create buffered image
2. get graphics
3. draw your source image in the graphics with desired size
Check for an implementation
http://mediachest.sourceforge.net/download/MediaChest11-80.zip

Similar Messages

  • How to import the image by using java application

    1.how to import the image by using java APPLICATION and display it on the textarea that you have been created.
    2.how to store the image into the file.
    3. what class should i used?
    4. how to create an object to keep track the image in java application.
    * important : not java applet.
    plzzzzzzz.
    regards fenny

    follow the link:
    http://java.sun.com/docs/books/tutorial/2d/images/index.html

  • How to make image resizable using mouse ?

    Hi,
    I want to know about that how to resize image by using mouse in Java Canvas. I created some tools like line, free hand, eraser. And want to know how to make an image resizable in canvas by using mouse. An image is jpeg, png, or gif format. I want to make image stretch and shrink by using mouse.
    Please help me..
    Thnax in advance.
    Manveer

    You make a listener to handle the mouse event that you want to capture, then program the affect you want using the event as the trigger.

  • Ways to implement image resizing using plug-ins?

    Hi Photoshop developers,
    I'm a developer with a few Photoshop filter and selection plug-ins under my belt, and I have a good understanding of the SDK and tools and suites it provides. My next project is an algorithm for enlarging/resampling images to different pixel dimensions. I'm wondering if anyone has any suggestions for or experience with the best combination of plug-in types to implement this.
    Clearly, I can't just write it as a filter plug-in, since there is no way to change the image dimensions from within a filter.
    I'd like the resized image to remain within Photoshop (as a new window or in the original one), so an export plug-in on its own is not sufficient.
    Import plug-ins seem promising, since they allow the creation of a new document of the required size. However, as best I can tell from the Photoshop 6.0 SDK documentation, import plug-ins cannot access the image data from other open documents (or even the clipboard), nor do they provide any support for channel ports and the Channel Port suite.
    My best idea at this stage is to create an export plug-in to provide the user interface and calculate the resized image, and then an import plug-in to import the resized image back into a new window. (I'm supposing a further automation plug-in would then be written to perform this export/import sequence.) The difficulty I see with this approach is how to communicate the resized image data between the two plug-ins. Since the resized image will potentially be very large, the ideal solution would be to store it in channels managed by the Channel Ports suite. However, I cannot see how the channel ports created in the export plug-in could be communicated to and used by an import plug-in. The alternative would be for the export plug-in to save the resized image to a temporary file on disk, however this seems unnecessary.
    So, my questions, specifically, are:
    a) Is it possible to create new channels using the Channel Ports suite (sPSChannelPorts->New()) in one plug-in, and have those channels persist to be used in another plug-in?
    b) If so, how would the channel ports be communicated between the plug-ins?
    c) Alternately, are there any alternative architectures available for implementing an image-resizing algorithm using the plug-in types that are available for Photoshop developers.
    Any responses would be greatly appreciated; I know this is a low-traffic forum...
    Thanks,
    Matthew.

    I would make an automation plug-in and a filter plug-in.<br /><br />1) Run the automation which runs your filter to gather current image <br />information<br />2) Create a temp file of the new document<br />3) Make a new document<br />4) Call the filter again to reload the temp data on disk<br /><br /><[email protected]> wrote in message <br />news:[email protected]...<br />> Hi Photoshop developers,<br />><br />> I'm a developer with a few Photoshop filter and selection plug-ins under <br />> my belt, and I have a good understanding of the SDK and tools and suites <br />> it provides. My next project is an algorithm for enlarging/resampling <br />> images to different pixel dimensions. I'm wondering if anyone has any <br />> suggestions for or experience with the best combination of plug-in types <br />> to implement this.<br />><br />> Clearly, I can't just write it as a filter plug-in, since there is no way <br />> to change the image dimensions from within a filter.<br />><br />> I'd like the resized image to remain within Photoshop (as a new window or <br />> in the original one), so an export plug-in on its own is not sufficient.<br />><br />> Import plug-ins seem promising, since they allow the creation of a new <br />> document of the required size. However, as best I can tell from the <br />> Photoshop 6.0 SDK documentation, import plug-ins cannot access the image <br />> data from other open documents (or even the clipboard), nor do they <br />> provide any support for channel ports and the Channel Port suite.<br />><br />> My best idea at this stage is to create an export plug-in to provide the <br />> user interface and calculate the resized image, and then an import plug-in <br />> to import the resized image back into a new window. (I'm supposing a <br />> further automation plug-in would then be written to perform this <br />> export/import sequence.) The difficulty I see with this approach is how to <br />> communicate the resized image data between the two plug-ins. Since the <br />> resized image will potentially be very large, the ideal solution would be <br />> to store it in channels managed by the Channel Ports suite. However, I <br />> cannot see how the channel ports created in the export plug-in could be <br />> communicated to and used by an import plug-in. The alternative would be <br />> for the export plug-in to save the resized image to a temporary file on <br />> disk, however this seems unnecessary.<br />><br />> So, my questions, specifically, are:<br />><br />> a) Is it possible to create new channels using the Channel Ports suite <br />> (sPSChannelPorts->New()) in one plug-in, and have those channels persist <br />> to be used in another plug-in?<br />><br />> b) If so, how would the channel ports be communicated between the <br />> plug-ins?<br />><br />> c) Alternately, are there any alternative architectures available for <br />> implementing an image-resizing algorithm using the plug-in types that are <br />> available for Photoshop developers.<br />><br />> Any responses would be greatly appreciated; I know this is a low-traffic <br />> forum...<br />><br />> Thanks,<br />> Matthew.

  • Setting source property of Trinidad image component using java script

    Hi,
    Can anyone tell me how to set the source property of Trinidad Image component using javascript.
    i tried document.getElementById("f1:img").source="/images/neha.gif".
    But its not working
    Thanks
    Neha

    Hi,
    Bases on the solution you suggested, i tried the img component to change the image on OnMouseOver and OnMouseOut. Its working fine in a normal browser but doesnt work in Mobile browser. May be because mobile browser supports only trinidad components. I then tried the option of backing bean
    " Or you can expose the component to a backing bean by setting its "binding" attribute. JDeveloper can create a backing bean from the wizard if you don't already have one. This will get you a CoreImage object in the bean, and you can change the source with its setSource method."
    . So i bound the omMouseOver event of the trinidad image component to a backing bean. Inside that i am changing the source and refreshing the component.
    <tr:commandLink id="cl1" action="goAlerts" styleClass="listingLink2">
    <tr:image source="/images/alert.gif" id="i4"
    binding="#{Images.alertOnMouseOver}"
    onmouseover="#{Images.alertOnMouseOver}"/>
    </tr:commandLink>
    Images.java
    public void setAlertOnMouseOver(CoreImage alertOnMouseOver) {
    this.alertOnMouseOver = alertOnMouseOver;
    alertOnMouseOver.setSource("/images/alertSelect.gif");
    RequestContext context = RequestContext.getCurrentInstance();
    context.addPartialTarget(alertOnMouseOver);
    System.out.print("Test");
    So what i found is setAlertOnMouseOver is getting called but not MouseOver event but when the page is loaded. Can you please tell me where i am going wrong?

  • Image upload using Java API

    Hi all,
    I am trying to upload an image into MDM repository using the Java MDM4J API. I have referred to the earlier posting in this forum for the same problem I am not able to add images into Catalog thru java API. However I am working on SP3 version of MDM software and looks like the Images table structure changed a bit and the code in the earlier posting isn't working.
    I am getting an error code <b>-5586944</b> and the message that gets printed on the console is
    <i>a2i.core.StringException: AddRecord error
         at a2i.common.CatalogData.AddRecord(Unknown Source)
         at a2i.common.CatalogData.AddRecord(Unknown Source)</i>
    Here is the code that I am using to upload the image
    String filePath = "C:\temp\Sunset.jpg";
    File file = new File(filePath);
    byte[] bytes = new byte[(int) file.length()];
    try{
         //read byte from file, and set the large data
         FileInputStream inputStream = new FileInputStream(file);
         inputStream.read(bytes);
         mdmFields.Add(new A2iField("Data ID", new Value(bytes)));
    }catch(IOException ioex){
         ioex.printStackTrace();
    int dataGroupId = 0;//Hardcoded it to 0. There is one group already in the repository
    mdmFields.Add(new A2iField("Data Group ID", new Value(dataGroupId)));
    //adding the name
    mdmFields.Add(new A2iField("Name", new Value(file.getName())));
    mdmFields.Add(new A2iField("Original Name", new Value(file.getName())));
    //adding OrigLocationId
    int origLocationId =0;
    try{
         origLocationId = catalog.AddDataLocation(filePath, 0, DataLocationType.ComputerLocation);
         System.out.println("Location id generated is " +origLocationId);
    }catch(StringException ex){
         System.out.println("Error while generating the location id");
         ex.printStackTrace();
    mdmFields.Add(new A2iField("Original Location ID", new Value(origLocationId)));
    try {
         //adding the image to the "Images" table
         int newImageId = catalog.AddRecord("Images", mdmFields, 0, 0);
    } catch (StringException e) {
         // TODO Auto-generated catch block
         System.out.println("Error while adding the image record " + e.GetErrorCode() + "  " + e.GetRCMessage(e.GetErrorCode()));
         e.printStackTrace();
    I am not able to figure out what is causing the problem. Any ideas would be greatly helpful. Thanks in advance.
    Suman.

    Hi Mausam,
    Thanks for your help. However, the problem doesn't seem to be going.
    I printed the records in the <b>Data Groups</b> table using a program to find the record ids that are already existing. My Data Groups table has 3 records. Here are the values.
    ID :1 Value :MyGroup
    ID :2 Value :Group2
    ID :3 Value :Group3
    I tried passing all the above 3 values (1,2,3) as input to the <b>Data Group ID</b> field. However, this time, I am getting a different error code this time
    Error while adding the image record -2147483647  No message for RC (0x80000001)
    a2i.core.StringException: AddRecord error
         at a2i.common.CatalogData.AddRecord(Unknown Source)
         at a2i.common.CatalogData.AddRecord(Unknown Source)
         at images.MyImageUpload.uploadImage(MyImageUpload.java:82)
    The error code <b>2147483647</b>  from the javadocs says <b>RC_BADPARAM</b>. Not able to figure out what exactly is causing the problem with Data Group ID.
    Any ideas or pointers to solve this would be greatly helpful. Thanks in advance.
    Regards
    Suman
    > Hi Suman,
    >
    > If you look at the description for the error code,
    > you get RC_CM_DATAGROUPNOTFOUND.
    >
    > Try giving some other value ( 1 worked for me ) in
    > the Data Group or try following the code given for
    > the Data Group in other forum post that you have
    > mentioned.
    >
    > Regards,
    > Mausam

  • General discussion - image handling using Java

    Hi,
    I am working on an image-processingtool over 4 month and i am a little annoyed by
    the handling of images in java/JAI.
    The differentiation between the color model, the sample model and the databuffer looks
    very nice and oop. In practice it is very complicated ...
    Try to load an image ... convert this to an gray-image and then do some operations onto
    this image under the restriction, that the values of each pixel should be minimal 16bits long.
    I found each class i should use to create such an buffered image. I do so ... but the result is
    not the one I suggest.
    The support of 16/32bit per pixel images is in general not the best at the core jdk.
    The JAI-library provide better support on the first look but there you got to know much knowledge
    how to use the library(the api is not very self documentating).
    One one side I though .. hey why you don't let the images be images and only work with Raster's?
    But you can't do any JAI-operation on a Raster nor can't you create a image only with the raster itself.
    There you end up in difficult merge conflicts with rasters, buffered images or planar images and the
    precission of 16/32 bits per pixel or only 8 bits.
    For me as a practical user of java.awt.image and jai the complicated usage of those classes in the cases
    I described was not the best sign. I don't got the time to read books about color models, sample models etc.
    to write an app which should do "only simple edge detecting ops".
    So maybe in future releases of the jdk this point of view can be noticed.
    Greetings,
    Olek

    As I remember Studio4 place resource files under
    project folder in the .jar file. If you working on
    "sampleproject", and place a pic/splash.png into .jar
    you can reach it like
    Image image =
    Image.createImage("sampleprojec/pic/splash.png");
    I'm not sure, but you could simple check it if you
    look into .jar file.How do I look into the .jar file? Open it in notepad and try and decipher the text, in there it says "res/player.png", but I've tried that, I've tried "/res/player.png", "player.png", "/player.png", "/bin/game/player.png","/bin/game/res/player.png" nothing works, actually I can't compile anything now either - the world has all gone wrong.....

  • Image transfer using java

    hi,
    i would like to know how to transfer an image from one computer to another in java using sockets.
    please reply if you are willing to help me .
    thank you.
    r.hari haran.

    hi,
    AFAIK thee is no serializable class implementing Image.
    But every image is a 2 dimensional integer array decribing the image pixels. You can write the array to the socket and recreate the image using BufferedImage.
    Gernot

  • Image resize : loss of quality by using Java API. What's wrong ?

    We actually have a problem with the resizing of pictures.
    We use jdk 1.4.2.
    We are trying to transform some picture from approx. 2000*1600 to 500*400.
    The result is poor (loss of colors, blur ...)
    We use an affineTransform and some renderingHints.
    There is actually no effect when we change the renderingHints parameters. Why ?
    Here's the code we use:
    import java.awt.geom.AffineTransform;
    import java.awt.image.*;
    import java.io.*;
    import javax.imageio.ImageIO;
    import java.awt.*;
    import javax.swing.*;
    public class Jpeg
        public Jpeg()
        // i  = la largeur de l'image redimensionner
        // s  = le chemin d'acces � l'image original
        // s1 = le chemin d'acces � l'image retaill�e
        public boolean resize(int i, String s, String s1)
           try
                File file  = new File(s);
                File file1 = new File(s1);
                //Parametrage de la lecture
                ImageIO.setUseCache (true);
                BufferedImage src = ImageIO.read(file);
                double d  = src.getWidth();
                double d1 = src.getHeight();
                double d2 = i;
                double d3 = d2 / d;
                if(d1 * d3 > d2)
                    d3 = d2 / d1;
                if(d3 > 0.8D)
                    d3 = 1.0D;
                int j = (int)(d * d3);
                int k = (int)(d1 * d3);
             AffineTransform  tx = new AffineTransform ();
                tx.scale (d3, d3);
                RenderingHints  rh = new RenderingHints (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                rh.put (RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
                rh.put (RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
                rh.put (RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
                rh.put (RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
                rh.put (RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
                rh.put (RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
                AffineTransformOp  op    = new AffineTransformOp (tx, rh);
                BufferedImage      biNew = new BufferedImage (j, k, src.getType ());
                op.filter(src, biNew);
                ImageIO.write (biNew, "jpg", new File (s1));
            catch (Exception  e)
                e.printStackTrace ();
                return  false;
            return  true;
        public static void main(String args[])
            Jpeg jpeg = new Jpeg();
            jpeg.resize (Integer.parseInt (args [0]), args[1], args[2]);
    }Here's the original picture http://193.252.12.20/bugimage/14457.jpg
    Here's the resized picture http://193.252.12.20/bugimage/bur.jpg
    Here's the paintshop pro resized picture http://193.252.12.20/bugimage/psp.jpg
    Is there another way to resize pictures ?
    Can we have a better result by using jdk 1.5.0 ?
    Thanks for your help.

    Nothing wrong - it's a feature :).
    "Loss of colours" is connected with Java embedded JPEG decoder. If you transcode to for example PNG format using any image processing program and then resize using Java then colors will be OK.
    "Blur..." is connected with bad implementation of interpolation algorithms in JDK/JRE and can't be fixed :)
    I'm close to finish developing own resizing library which produced the next results from your image (it's a very good image to test). "from_png" means that the source image is PNG.
    <b>Box interpolation</b> (also known as nearest neighbour, but it's the honest implementation, not JDK fake):
    http://www.chainline.com/Box.jpg
    http://www.chainline.com/Box_from_png.jpg
    Well-known <b>Lanczos 3</b>:
    http://www.chainline.com/Lanczos_3.jpg
    http://www.chainline.com/Lanczos_3_from_png.jpg
    Not-well-known <b>Ideal 5S</b> but one of the most qualified:
    http://www.chainline.com/Ideal_5S.jpg
    http://www.chainline.com/Ideal_5S_from_png.jpg
    And 2 interesting s.c. "sharp" filters which make the result sharpen:
    <b>Sharp Light 5</b>:
    http://www.chainline.com/Sharp_Light_5.jpg
    http://www.chainline.com/Sharp_Light_5_from_png.jpg
    <b>Sharp 5</b>:
    http://www.chainline.com/Sharp_5.jpg
    http://www.chainline.com/Sharp_5_from_png.jpg

  • 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

  • Need to convert an image to .jpeg using Java !

    Hello,
    i am working in images now. i need to convert any image in the form of .jpeg using Java. in other words, i need to store an image in the form of .jpeg format. can any of u help me ! thanks in advance.
    - Krishna

    There's also jimi, at http://java.sun.com/products/jimi/
    You can do something like:
    image = new BufferedImage (width, height, BufferedImage.TYPE_INT_RGB);
    // create your image
    String path = "/path/image.jpg";
    Jimi.putImage(image, path);
    [\code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to extract the number from image using java

    Hello every one
    i want to develope a project which can extract the number from image
    that i can use as inter or String or char.
    Is there any API in java which provide this type of facility.
    right now i m using java 5
    thanks in Advance
    Jignesh

    In my project i have a image in that i have a
    co-ordinate (x,y) I am still puzzled as to what you seek. It sounds to me like you have a point (x, y) represented by p. in java it's just p.getX() p.getY()
    i want to convert that cordinate to numeric form,
    i mena i want to use that cordinate in somewhere else
    in project.point.getX() point.getY()
    So need to convert it into numeric form u can called
    it OCR also.OCR is optical character recognition. If I want out and took a picture of the US Declaration of Independence and then wanted the words on the parchement in the picture in text form, then I would run the picture through a software program and it would try to optically recognise what lettering and number were present in the picture. In the end, I would have a text of what is written on the US Declaration of Independence.
    Is that what you want?

  • Image not displayed in pdf generated using Java API for Forms service

    Hi,
    I am creating a pdf document using Java API for Forms Service.
    I am able to generate the pdf but the images are not visible in the generated pdf.
    The image relative path is coming in the xml as defined below. The images are stored dynamically in the Livecycle repository each time a request is fired with unique name before the xml is generated.
    <imageURI xfa:contentType="image/png" href="../Images/logo.png"></imageURI>
    Not sure if I need to specify specify specific URI values that are required to render a form with image.
    The same thing is working when I generate pdf document using Java API for Output Service.
    As, I need to generate interactive form, I have to use Forms service to generate pdfs.
    Any help will be highly appreciated.
    Thanks.

    Below is the code snippet:
                //Create a FormsServiceClient object
                FormsServiceClient formsClient = new FormsServiceClient(myFactory);
                //Specify URI values that are required to render a form
                URLSpec uriValues = new URLSpec();
                                  // Template location contains the whole rpository path for the form
                uriValues.setContentRootURI(templateLocation);
               // The base URL where form resources such as images and scripts are located.  Whole Image path is passed in BaseUrl in the http format.
                      String baseLocation = repositoryPath.concat(serviceName).concat(imagesPath);   
                                  uriValues.setBaseURL(baseLocation);                                        
                // Set run-time options using a PDFFormRenderSpec instance
                PDFFormRenderSpec pdfFormRenderSpec = new PDFFormRenderSpec();
                pdfFormRenderSpec.setCacheEnabled(new Boolean(true));           
                pdfFormRenderSpec.setAcrobatVersion(com.adobe.livecycle.formsservice.client.AcrobatVersio n.Acrobat_8);
                                  //Invoke the renderPDFForm method and write the
                //results to a client web browser
                String tempTemplateName =templateName;
                FormsResult formOut = formsClient.renderPDFForm(tempTemplateName,
                                              inXMDataTransformed,pdfFormRenderSpec,uriValues,null);
                //Create a Document object that stores form data
                Document outputDocument = formOut.getOutputContent();
                InputStream inputStream = outputDocument.getInputStream();

  • How to upload Image to MDM 5.5 SP3 using Java APIs

    Hi,
    I am trying to upload Image to Images table in MDM 5.5 using JAVA API for MDM. But. I'm not able to find particular field in Images table where I need to set the Blob object ( Image data ).
    I'm not aware of the method to set the Blob, there is one for getting the Image data.
    I have gone through I am not able to add images into Catalog thru java API forums posts and tried the code. But with no luck....
    I think this code is for some other MDM version as the fields mentioned are not present in the Images table e.g. DataObject - this field is used in the above posts to set the Blob data but this field does not exist in Images table in MDM 5.5
    Can anyone suggest the solution?
    Thanks and Regards,
    Mausam

    Hi Mausam,
    Please try the following:
    // adding to a image table
    // get the bytes for the image
    byte[] imageBuf = readFile("C:\pic.bmp");
    // setup A2iFields
    fields = new A2iFields();
    fields.Add(new A2iField("DataObject", new
    Value(imageBuf))); // the image binary (required)
    fields.Add(new A2iField("Name", new Value("pic.bmp")));
    // a name for the image
    fields.Add(new A2iField("OrigName", new
    Value("pic.bmp"))); // the original image file name
    (required)
    fields.Add(new A2iField("DataGroupId", new Value(888)));
    // the data group to add to (required)
    fields.Add(new A2iField("OrigLocationId", new
    Value(999))); // the data location of the image
    (required)
    fields.Add(new A2iField("Description", new Value("a
    short description"))); // a short description here
    // add the image
    String imageTable = "Images";
    catalog.AddRecord(imageTable, fields, -1, -1);
    It's taken out of the API guide for SP3 (the example for method AddRecord.
    Best regards,
    Amit

  • 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.

Maybe you are looking for