Creating Thumbnails with ImageIO or JAI?

Hello,
Could anyone advise between the clases available in ImageIO and the JAI.
Which use the least amount of memory, and is quickist in creating thumbnails from an jpeg, or gif image?
My thought was the JAI would be quicker, and perhaps uses less memory or better at release memory.
I would much appreciate the members guidance.
Thanks

Further to this, I first thought the problem was probably something to do with the Xserver requirement for java.awt.Toolkit, but as you can see from the code, an image is loaded and scaled (as far as I can tell) with no problems - its just encoding it and writing it back out that causes problems.

Similar Messages

  • Can't create Thumbnails with ADDT

    Hi i have a site that seems its not finding the GD or imagemagic module.
    when i click on Required server libraries i get an error = No match found for parameter "multiNames". when i choose gd the thumbs are not created and the page errors out. I've done this many times before on diferent sites and had no problems.
    im running php version 4.3.9
    and created an phpinfo file and can see gd is enabled
    i have anoter site on the same server and i don't get this error.
    Can someone help trouble shoot this with me as i contacted my hosting company and they said gd is installed properly. And now im stuck.
    server: Apache/lunux

    Thanks thats strange everything else works just when i try to use the "show thumbnail" behavior. i tried to use the show picture works just not the thumbnail. i will request my host updates this asap then try from their.
    thanks

  • How do i create gallery with text under thumbnails?

    Hi. Im new in Muse and im trying to learn. My next challenge is to make thumbnails with text under like this:
    And when visitors click a thumbnail it should pop up the original size picture in a lightbox. A mouseover big pic
    should also work.
    Like this site. Affinity Surfaces | Color Gallery Here they have text on thumbnails and when you click on it it shows the full aize pic
    Any tips?
    My goal is to create my own art-page where i can show and sell my artwork

    That worked pnoypie
    I had to manually put pic in thumbnail and in lightbox. (or is it an other way?)
    I also had to put the text under thumbnail manually... but thats ok. To bad i cant group it with the thumbnail.
    Is it a way around that?

  • When I try to open I Movie the screen appears with the message creating thumbnails and all my projects have disappeared. Then everything freezes and I have to force close my Macbook Pro

    When I try to open I Movie thes screen appears with the message "creating thumbnails" and then freezes. None of my events or projects appear in the libraries. I cannot close I Movie or my computer and have to force shut down my Macbook. This is a sudden occurence.

    You can never, never transfer an installed copy of PSE. It's just too complex and it strews stuff all over your hard drive in places the migration assistant is not programmed to look. Now you will need to download and run this:
    Use the CC Cleaner Tool to solve installation problems | CC, CS3-CS6
    after which you can go around and manually remove all the bits from Applications, the library at the top level of your hard drive>application support>adobe, and your username>library>preferences. Spotlight will not help with this; it's programmed to skip these kinds of files.
    Then you can reinstall from scratch. Let us know if you need help finding the library folders.

  • Photoshop 10 Orginizer with Win7 takes 20 hrs to create thumbnails, why?

    Why does it take 20 hours for my thumbnails to create when I startup my program?

    Creating thumbnails is a background task with low priority, but that should not prevent you to work immediately, as the thumbnails for the current display grid are created in priority.
    The first time thumbnails are created (after import or restore), that means all your media files should be read and the thumbnail saved. That depends on the size of your library : number of items, library size in Gbytes.
    If you meet the problem each time you open the organizer, then it helps generally to delete the thumbnail cache and let it be created when you open the organizer.
    Find the catalog folder : Menu Help / system info. That folder may be hidden by default, set Windows to show hidden folders. Delete the file 'thumbs.5.cache' and restart the organizer and let it rebuild the cache. That may take a long time, but only the first time you open the organizer.

  • Create Thumbnail Image in JSP

    I have JSP a page, were I want to show Thumbnail Image from specified path. The specified path contain one or more file. If anybody have the code or reference for doing this please replay. (For one image will also the helpfule for me)
    Thank You

    The following is what I use to create thumbnail images. It uses struts, is a bit of a haste work but never failed in creating thousands of thumbnails. I'd be glad if you suggest improvement.
    import java.io.*;
    import java.text.*;
    import java.util.*;
    import org.apache.struts.upload.FormFile;
    import javax.imageio.ImageIO;
    import java.awt.*;
    import java.awt.image.BufferedImage;
    import org.apache.log4j.Logger;
    * @author Niklas
    public class ClassifiedImage {
        Logger log = Logger.getLogger(this.getClass());
        /** Creates a new instance of ClassifiedImage */
        public ClassifiedImage() {
        public void generateImage(FormFile file, String outputFilename, String outputthumbFilename) {
            try {
                String type = file.getContentType();
                String name = file.getFileName();
                int size = file.getFileSize();
                byte[] data = file.getFileData();
                if (data != null && name.length() > 0) {
                    ByteArrayInputStream bis = new ByteArrayInputStream(data);
                    BufferedImage bi = ImageIO.read(bis);
                    int width = bi.getWidth();
                    int height = bi.getHeight();
                    Image thumb = null;
                    if (width > 600 || height > 600) {
                        Image scaledimage = null;
                        if (width > 600) {
                            scaledimage = bi.getScaledInstance(600, -1, Image.SCALE_SMOOTH);
                            thumb = bi.getScaledInstance(80, -1, Image.SCALE_SMOOTH);
                            BufferedImage scaledBuffImage = StrutsUploadAction.toBufferedImage(scaledimage);
                            BufferedImage thumbBuffImage = StrutsUploadAction.toBufferedImage(thumb);
                            int newWidth = scaledBuffImage.getWidth();
                            int newHeight = scaledBuffImage.getHeight();
                            int thumbBuffImagenewWidth = thumbBuffImage.getWidth();
                            int thumbBuffImagenewHeight = thumbBuffImage.getHeight();
                            if (thumbBuffImagenewHeight > 60) {
                                thumb = thumbBuffImage.getScaledInstance(-1, 60, Image.SCALE_SMOOTH);
                            if (newHeight > 600) {
                                scaledimage = scaledBuffImage.getScaledInstance(-1, 600, Image.SCALE_SMOOTH);
                            BufferedImage scaledthumbBuffImage = StrutsUploadAction.toBufferedImage(thumb);
                            BufferedImage scaledBuffImage2 = StrutsUploadAction.toBufferedImage(scaledimage);
                            int newWidth2 = scaledBuffImage2.getWidth();
                            int scaledNewHeight = scaledBuffImage2.getHeight();
                            String formatName = "jpg"; // desired format
                            File outputFile = new File(outputFilename);
                            File outputthumbfile = new File(outputthumbFilename);
                            if (width > 600 || newHeight > 600) {
                                boolean writerExists = ImageIO.write(scaledBuffImage2, formatName, outputFile);
                                boolean writerthumbExists = ImageIO.write(scaledthumbBuffImage, formatName, outputthumbfile);
                        } else if (height > 600) {
                            Image scaledimage2 = bi.getScaledInstance(-1, 600, Image.SCALE_SMOOTH);
                            thumb = bi.getScaledInstance(-1, 60, Image.SCALE_SMOOTH);
                            BufferedImage scaledBuffImage2 = StrutsUploadAction.toBufferedImage(scaledimage2);
                            int newWidth2 = scaledBuffImage2.getWidth();
                            int newHeight2 = scaledBuffImage2.getHeight();
                            BufferedImage scaledthumbBuffImage2 = StrutsUploadAction.toBufferedImage(thumb);
                            int newthumbWidth2 = scaledthumbBuffImage2.getWidth();
                            int newthumbHeight2 = scaledthumbBuffImage2.getHeight();
                            if (newWidth2 > 600) {
                                scaledimage2 = scaledBuffImage2.getScaledInstance(600, -1, Image.SCALE_SMOOTH);
                            if (newthumbWidth2 > 80) {
                                thumb = scaledthumbBuffImage2.getScaledInstance(80, -1, Image.SCALE_SMOOTH);
                            BufferedImage ndscaledBuffImage2 = StrutsUploadAction.toBufferedImage(scaledimage2);
                            BufferedImage ndscaledthumbBuffImage2 = StrutsUploadAction.toBufferedImage(thumb);
                            int n_newWidth2 = ndscaledBuffImage2.getWidth();
                            int n_newHeight2 = ndscaledBuffImage2.getHeight();
                            String formatName2 = "jpg"; // desired format
                            File outputFile2 = new File(outputFilename);
                            File outputfile3 = new File(outputthumbFilename);
                            if (height > 600 || newHeight2 > 600) {
                                boolean writerExists2 = ImageIO.write(ndscaledBuffImage2, formatName2, outputFile2);
                                boolean writerExists3 = ImageIO.write(ndscaledthumbBuffImage2, formatName2, outputfile3);
                    } else {
                        FileOutputStream fileOut = new FileOutputStream(outputFilename);
                        fileOut.write(data);
                        fileOut.flush();
                        fileOut.close();
                        BufferedImage b = null;
                        ByteArrayInputStream bi2 = new ByteArrayInputStream(data);
                        BufferedImage bufi2 = ImageIO.read(bi2);
                        int width2 = bi.getWidth();
                        int height2 = bi.getHeight();
                        Image thumbnail2 = null;
                        if (height2 > width2) {
                            thumb = bufi2.getScaledInstance(-1, 60, Image.SCALE_SMOOTH);
                            BufferedImage scaledBuffImagethumb = StrutsUploadAction.toBufferedImage(thumb);
                            int newWidth7 = scaledBuffImagethumb.getWidth();
                            int newHeight7 = scaledBuffImagethumb.getHeight();
                            if (newWidth7 > 80) {
                                thumb = scaledBuffImagethumb.getScaledInstance(80, -1, Image.SCALE_SMOOTH);
                            b = StrutsUploadAction.toBufferedImage(thumb);
                        } else {
                            thumb = bufi2.getScaledInstance(80, -1, Image.SCALE_SMOOTH);
                            BufferedImage scaledthumb = StrutsUploadAction.toBufferedImage(thumb);
                            int scaledthumbwidth = scaledthumb.getWidth();
                            int scaledthumbheight = scaledthumb.getHeight();
                            if (scaledthumbheight > 60) {
                                thumb = scaledthumb.getScaledInstance(-1, 60, Image.SCALE_SMOOTH);
                            b = StrutsUploadAction.toBufferedImage(thumb);
                        File f = new File(outputthumbFilename);
                        boolean bo = ImageIO.write(b, "jpg", f);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
    }And the helper method:
    // This method returns a buffered image with the contents of an image
        public static BufferedImage toBufferedImage(Image image) {
            if(image instanceof BufferedImage) {
                return (BufferedImage)image;
            // This code ensures that all the pixels in the image are loaded
            image = new ImageIcon(image).getImage();
            // Determine if the image has transparent pixels; for this method's
            // implementation, see e661 Determining If an Image Has Transparent Pixels
            boolean hasAlpha = false;
            // 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;
        }

  • Create thumbnail using excessive memory

    I have the following code to read an image (in a file) and create a thumbnail image, writing it to a file:
    BufferedImage originalBufferedImage = ImageIO.read(new File(imagePathAndFileName));
    int originalWidth = originalBufferedImage.getWidth();
    int originalHeight = originalBufferedImage.getHeight();
    double scale = 0;
    if (((double)75 / originalWidth) <
    ((double)75 / originalHeight)) {
    scale = (double)75 / originalWidth;
    } else {
    scale = (double)75 / originalHeight;
    int width = (int)(originalWidth * scale);
    int height = (int)(originalHeight * scale);
    BufferedImage newBufferedImage = new BufferedImage(width, height, originalBufferedImage.getType());
    Graphics2D graphics2D = newBufferedImage.createGraphics();
    Canvas dummyObserver = new Canvas();
    Image scaledImage = originalBufferedImage.getScaledInstance(width, height, Image.SCALE_SMOOTH);
    graphics2D.drawImage(scaledImage, 0, 0, dummyObserver);
    javax.imageio.ImageIO.write(newBufferedImage, fileType, new File(thumbnailPathAndFileName));
    With a 1.9 Megabyte image, the call to ImageIO.read() tries to allocate 15 Megabytes of memory, as seen from the log (obtained in WebSphere 5.1 by setting an ALLOCATION_THRESHOLD limit):
    Allocation request for 15085072 bytes
    at java.awt.image.DataBufferByte.<init>(DataBufferByte.java:87)
    at java.awt.image.ComponentSampleModel.createDataBuffer(ComponentSampleModel.java:430)
    at java.awt.image.Raster.createWritableRaster(Raster.java:965)
    at javax.imageio.ImageTypeSpecifier.createBufferedImage(ImageTypeSpecifier.java:1146)
    at javax.imageio.ImageReader.getDestination(ImageReader.java:2868)
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:914)
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:886)
    at javax.imageio.ImageIO.read(ImageIO.java:1413)
    at javax.imageio.ImageIO.read(ImageIO.java:1299)
    Why does it use 15M to read in an image of 1.9M ? Is there a more efficient way to create thumbnail images?

    A 15M image correponds to a 5M-pixel RGB 24-bit image. "ImageIO.read" decodes your 1.9M compressed jpeg (beeing roughly a 5Mpixel image, right?) file to a buffered image of some in-memory RGB 24bit format making it consuming 15M. You can get away with using less memory if you can find some ImageIO plugin returning a BufferedImage of type TYPE_CUSTOM with a compressed in-memory representation of the loaded image.
    Regards,
    Arvid

  • Creating Thumbnails of Images without AWT

    I've searched in a lot of places, and am becoming increasingly surprised I cannot find a straightforward answer to a problem I have. I run Tomcat on a server which has no X11, and I do not want to install it. However, I am also trying to create a servlet which will take an image from a byte array and create a thumbnail of it.
    While I have seen many examples of this, all use AWT, which seems to require using X11 or some windowing system even to run at all (despite my not trying to create a window or anything). While I understand that there is an option that can be added to the initialization script for Tomcat ("JAVA_OPTS=-Djava.awt.headless=true") I would far prefer simple code that didn't use AWT at all.
    Does anyone know how to create a thumbnail or resize an image without the use of the AWT library whatsoever? Thanks very much!

    Hmm... sorry I didn't know that.
    I remember seeing some section on this website about Java Imaging or something like that and it seemed totally independent of AWT.
    I came accross another imaging article:
    http://johnbokma.com/java/obtaining-image-metadata.html , this one doesn't seem to use AWT - at least I don't see any in the imports.
    May be Images are supposed to work only with AWT.
    Here's another set of examples:
    http://www.exampledepot.com/egs/javax.imageio/pkg.html
    that demonstrates the javax.imageio package, but those examples also use AWT.
    I think one could re-size an image on a website to create thumbnails, by specifying a percent width and height. and may be there's no need to have a package to create thumbnails on a web page when it could be done with HTML and that's probably why there isn't image processing for web pages (this is just my guess work, I could be wrong)
    Message was edited by:
    appy77

  • PSE unable to create thumbnails after Album Starter removed

    My sister accepted the upgrade to Adobe Reader 8.0 and said Photoshop Album Starter was automatically loaded on her computer with that upgrade. When she had difficulty working with it, we found some instructions for unloading it, which she did. However, then her problems "really" began. Several pictures on her Desktop were renamed with the PDF file extension, and their thumbnails were totally black. Her "Pix" folder on her Desktop and all the pictures she had in it, plus other pictures stored on her Desktop, disappeared into her Recycle Bin. I restored these files and the folder back to her Desktop, but many of these also had the black thumbnails, or black thumbnails with a thin stripe of colors mixed in with the black across the top. We could still open the pictures, which was a blessing, at least.
    However, things became worse as we discovered that ALL new files created with Photoshop Elements (she has both 3.0 and 1.0 and both responded the same way) will no longer create thumbnails. I opened one of the corrupted-thumbnail photos and copied the layer into a new Photoshop Elements document and saved the file with a new filename and a PSD extension thinking that would give us back a file with a thumbnail. Wrong. Still got a black thumbnail. Tried saving as a JPG; still no go. I then selected New and created a totally new document. Same result; no thumbnail. So I created new documents in her Corel Painter IX and Microsoft Paint to see if this was just an "Adobe" thing, and these other programs had no problem creating normal thumbnails with saved documents. So, it's obviously just an Adobe thing.
    My only thought at this point is that unloading Adobe Album also deleted or corrupted a shared Adobe file that allows Adobe products to create thumbnails. I suggested that she try reloading her Photoshop Elements programs to see if that brings back the ability to create thumbnails.
    Sorry for the long background, but does anyone out there know how to get Photoshop Elements to start creating thumbnails again after getting rid of Album? I'd be ever so grateful if you could help us out!
    Marilyn Lee

    Hey, Marilyn, I found an answer! Well, this doesn't "fix" the problem, but it does allow you to work around it. There is a program (shareware) called "Thumbnail View," and you can find it at the address below.
    http://www.seriema.net/thumbview/index.php...e=download_lite
    It worked for me, and my computer's not very new. I can now see PSD thumbnails where before there was just a little icon. Best of luck.
    B.

  • How to save transparent background images to have transparent background thumbnails with Photoshop 2014?

    In old versions of Photoshop there was a feature that made thumbnail images have a transparent background.  I'm a CC member using Photoshop 2014 on a MacBook Pro running OS X 10.9.4 and every thumbnail of a transparent background image I've created in Photoshop 2014 appears on my desktop with a solid white box background that has a thin black outlined box inside of it.  How do I save the transparent background images I've created in Photoshop 2014 so they will appear on my desktop as thumbnails with a transparent background?   I'd like to continue to be able to replace the default background-less folder icon that that appears on files with transparent background thumbnails to customize my files as I use to do with older versions of Photoshop.

    If your layered document has a Photoshop background layer it visibility need to be set off when saving a PNG or Gif file for Photoshop background layers do not support transparency.
    Thumbnail may be a bit more complicated than you think. I do not use Lightroom, and only occasionally use the bridge.  I believe Lightroom and Bridge  keep thumbnails they develop for image files  in their library databases and caches.  Other programs do not have acces to  these.  RAW Files and Image files have Jpeg previews stored in then.  I believe most application use these previews jpeg to create thumbnails.  Jpeg format does not support transparency.
    Icon on the desktop are not always thumbnails some are embedded icons in application modules other are icon in dll these may well have transparency. However image file on the desktop have generated thumbnails.  However you can create a shortcut for an image png file and create a icon with a transparent background for the png file and change the shortcut's icon for the png file to the transparent ico file you created for it.
    Also many Photoshop release ago an Adobe module created Thumbnails for image files in Windows File explorer and most likely system file dialog. Adobe stopped supporting that stating Microsoft changes how windows works.
    Today I use FastPictureViewer Codec Package to generate image thumbnails for image files including RAW and PSD files in File Explorer and system file dialogs.
    I don't use a Mac don't know what available for your Mac.

  • Create Annotations with 'author' name tool property

    Philip Cord has kindly sent me this code that allows to create annotations with the "Author" tool property (older versions than CS3 couldn't get this on script listener - only on the CS3 script listener).
    Hope it helps anyone like me that can't have access anymore to CS3
    var colour = new SolidColor();
    colour.rgb.hexValue = 'ff00ff';
    selectNote(0);
    colourNote(colour);
    addAuthorToNote("Author Name");
    function colourNote(colour) {
    var Saturation = colour.hsb.saturation;
    var Brightness = colour.hsb.brightness;
    var Hue =colour.hsb.hue;
    var desc = new ActionDescriptor();
    var ref = new ActionReference();
    ref.putEnumerated( stringIDToTypeID('annotation'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
    desc.putReference( charIDToTypeID('null'), ref );
    var desc2 = new ActionDescriptor();
    var desc3 = new ActionDescriptor();
    desc3.putUnitDouble( charIDToTypeID('H   '), charIDToTypeID('#Ang'), Hue );
    desc3.putDouble( charIDToTypeID('Strt'), Saturation );
    desc3.putDouble( charIDToTypeID('Brgh'), Brightness);
    desc2.putObject( charIDToTypeID('Clr '), charIDToTypeID('HSBC'), desc3 );
    desc.putObject( charIDToTypeID('T   '), stringIDToTypeID('annotation'), desc2 );
    executeAction( charIDToTypeID('setd'), desc, DialogModes.NO );
    function selectNote(number) {
    var desc = new ActionDescriptor();
    var ref = new ActionReference();
    ref.putIndex( stringIDToTypeID('annotation'), number );
    desc.putReference( charIDToTypeID('null'), ref );
    try{
    executeAction( charIDToTypeID('Shw '), desc, DialogModes.NO );
    }catch(e){}
    function addAuthorToNote(Author) {
    var desc = new ActionDescriptor();
    var ref = new ActionReference();
    ref.putEnumerated( stringIDToTypeID('annotation'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
    desc.putReference( charIDToTypeID('null'), ref );
    var desc2 = new ActionDescriptor();
    desc2.putString( charIDToTypeID('Athr'),  Author);
    desc.putObject( charIDToTypeID('T   '), stringIDToTypeID('annotation'), desc2 );
    executeAction( charIDToTypeID('setd'), desc, DialogModes.NO );
    function makeAnnotation(X,Y,Width,Height) {
    var desc = new ActionDescriptor();
    var ref = new ActionReference();
    ref.putClass( stringIDToTypeID('annotation') );
    desc.putReference( charIDToTypeID('null'), ref );
    var desc2 = new ActionDescriptor();
    var desc3 = new ActionDescriptor();
    desc3.putUnitDouble( charIDToTypeID('Hrzn'), charIDToTypeID('#Pxl'), X );
    desc3.putUnitDouble( charIDToTypeID('Vrtc'), charIDToTypeID('#Pxl'), Y );
    desc2.putObject( charIDToTypeID('Lctn'), charIDToTypeID('Pnt '), desc3 );
    var desc4 = new ActionDescriptor();
    desc4.putUnitDouble( charIDToTypeID('Hrzn'), charIDToTypeID('#Pxl'), Width );
    desc4.putUnitDouble( charIDToTypeID('Vrtc'), charIDToTypeID('#Pxl'), Height );
    desc2.putObject( charIDToTypeID('Sz  '), charIDToTypeID('Ofst'), desc4 );
    desc2.putEnumerated( stringIDToTypeID('annotType'), stringIDToTypeID('annotType'), stringIDToTypeID('annotText') );
    desc.putObject( charIDToTypeID('Usng'), stringIDToTypeID('annotation'), desc2 );
    executeAction( charIDToTypeID('Mk  '), desc, DialogModes.NO );

    This is a bit more robust (it won't fall over if you have no images open or can't find the corresponding image) I've made it so if you have the thumbnail image open it will find the mannequin image and visa versa. Save the script to your PS scripts directory. In photoshop record an action that uses the script. Stop recording! Then you can run the script as an action.
    app.preferences.rulerUnits = Units.PIXELS;
    if (documents.length == 0)
        alert ("No documents open, dude!")
    else
        var dir1 = "Mannequin";
        var dir2 = "Thumbnails";
        // call the current document
        var tempDoc = app.activeDocument;
        // get the info out of the source doc
        var fileName = tempDoc.name;
        var filePath = tempDoc.path.toString();
        var fileNameAndPath = filePath + '/' + fileName;
        var tempDir = filePath.substring(filePath.lastIndexOf("/") +1, filePath.length);
        var goCode = false;
        var docName = fileName.substring(0,fileName.length -4);
        if (tempDir == dir1)
            var otherImagePath = filePath.substring(0, filePath.lastIndexOf(dir1));
            var tempFile  = decodeURI(otherImagePath + "/" + dir2 + "/" + fileName);
            goCode = true;
        if (tempDir == dir2)
            var otherImagePath = filePath.substring(0, filePath.lastIndexOf(dir2));
            var tempFile  = decodeURI(otherImagePath + "/" + dir1 + "/" + fileName);
            goCode = true;
        if (tempDir != dir1 && tempDir != dir2)
            alert("Cannot find matching image.")
            goCode = false;
        if (goCode)
            //open the other image
            var fileRef = new File(tempFile)
            if (fileRef.exists)
                app.open(fileRef);
            else
                alert("Matching file does not exist.")
    }// end doc check
    Hope this helps.

  • Writing JPEG with ImageIO

    Hi,
    I wanted to do this little tool that:
    1. read any type of image format supported by ImageIO
    2. scaled it down to arbitrary size
    3. wrote the image to the same format it was originally
    I got the pieces together, used ImageIO to read the image, then java.awt.image.AffineTransformOp to scale it down and finally ImageIO again to write it back (I get the ImageWriter with ImageIO.getImageWriter(ImageReader)).
    The problem I got was that AffineTransformOp on Linux (it uses native code) does not want to output anything else then ARGB images. If I read a YCbCr JPEG (the most common JPEG format) and do the AffineTransformOp, I get this ARGB image, which ImageIO will happily write back as an JPEG, but as CMYK JPEG file (which is really rare and not understood by most browsers)... which is not fine because the original was YCbCr.
    The question now is, how do I get AffineTransformOp and ImageIO to play nicely together. Either I have to get AffineTransformOp to output to an BufferedImage that has the same colormodel as that read from the file, or I have to get ImageIO to write any BufferedImage to the exact same format as the original image file.
    For the special case I stated above, I got the program to work by converting the BufferedImage I got from AffineTransformOp to a BufferedImage with RGB colormodel. This, however is not the solution because it assumes that we do not want to output ARGB... Anyway I did it whith the following code (yes, it is horrible).
    // do scaling
    BufferedImage scaled = op.filter(original, null);
    // create a new RGB color model... no alpha
    ColorModel rgbcm = new DirectColorModel(24, 0x00ff0000, 0x0000ff00, 0x000000ff);
    // get the DataBuffer from the scaled version
    DataBuffer db = scaled.getRaster().getDataBuffer();
    // and its dimensions
    int w = scaled.getRaster().getWidth();
    int h = scaled.getRaster().getHeight();
    // band masks for rgb (no alpha)
    int[] bandMasks = new int[] {0x00ff0000,0x0000ff00, 0x000000ff}
    // create new WritableRaster that has the same data, but different sample model
    WritableRaster r = Raster.createPackedRaster(db, w, h, h, bandMasks, null);
    // create a new BufferedImage with the no-alpha ColorModel and the raster
    // with no-alpha SampleModel
    BufferedImage rgbimg = new BufferedImage(rgbcm,r, scaled.isAlphaPremultiplied(), null);
    My second question is, if I have to do this, is there any simpler way?

    I just did a project similar to this actually, so you're in luck! My project was doing image compression rather than resizing, but the IO is the same. I used PixelGrabber to get the pixels, then created my new image in a BufferedImage just like you did (so you can keep all your reading and image creation the same since you seemed to use a BufferedImage also).
    Once you have your BufferedImage, it's blazingly simple. There is a JPEGCodec package that is included in the JDK. It's not compiled though. but, if you open up the ZIP file that has the sources in it (it's copied to your java home directory, called "src.zip"), you can get all the sources you needed. In that package there are 2 classes that I used: JPEGCodec and JPEGImageEncoder. It works like follows:BufferedImage bi;
    OutputStream os;
    // create and fill your buffered image and instantiate your output stream (I used a FileOutputStream for obvious reasons).
    JPEGImageEncoder jie = JPEGCodec.createJPEGEncoder(os);
    jie.encode(bi); And that's it! The package does the rest! Let me know if you have any troubles with it.

  • What is the best (easiest) way to create thumbnails?

    From (image) files selected via JFileChooser, what is the best way to create thumbnails so they can be immediately displayed?

    package projects.web;
    import javax.swing.*;
    public class UploadApplet extends JApplet{
         public void displayGUI(){
              AppletGUI createGUI = new AppletGUI(getRootPane());
         public void init(){
              try{
                   SwingUtilities.invokeAndWait(new Runnable(){
                        public void run(){
                             displayGUI();
              } catch (Exception e){
                   e.printStackTrace();
    } // end UploadApplet class
    package projects.web;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.text.*;
    import java.util.*;
    import java.io.*;
    public class AppletGUI{
         // JButtons
         JButton addButton = new JButton("Add");
         // JPanels
         JPanel containerPanel = new JPanel();
         JPanel optionsPanel = new JPanel();
         JPanel thumbnailPanel = new JPanel();
         // JScrollPane
         JScrollPane thumbnailScroll;
         public AppletGUI(JRootPane topContainer){
              // Add actionListener
              addButton.addActionListener(new ButtonHandler());
              // Set border layout
              containerPanel.setLayout(new BorderLayout());
              // Add buttons to target panels
              optionsPanel.add(addButton);
              // Set size and color of thumbnail panel
              thumbnailPanel.setPreferredSize(new Dimension (600,500));
              thumbnailPanel.setBackground(Color.white);
              thumbnailPanel.setBorder(new LineBorder(Color.black));
              // Add thumbnail panel to scrollpane
              thumbnailScroll = new JScrollPane(thumbnailPanel);
              // Set background color of scrollPane
              thumbnailScroll.setBackground(Color.white);
              // Add subpanels to containerPanel
              containerPanel.add(optionsPanel, BorderLayout.NORTH);
              containerPanel.add(thumbnailScroll, BorderLayout.CENTER);
              // Add containerPanel to rootPane's contentPane
              topContainer.getContentPane().add(containerPanel);
         } // end constructor
         class ButtonHandler implements ActionListener{
              public void actionPerformed(ActionEvent e){
                   new FileBrowser();
              } // end actionPerformed method
         } // end inner class ActionHandler
    } // end AppletGUI class
    package projects.web;
    import java.awt.*;
    import java.io.*;
    import javax.swing.*;
    import javax.swing.filechooser.*;
    import javax.imageio.*;
    import java.util.*;
    public class FileBrowser{
         JFileChooser fileChooser = new JFileChooser();
         int fileChooserOption;
         LinkedList<File> selectedFilesList = new LinkedList<File>();
         LinkedList<String> fileNames = new LinkedList<String>();
         public FileBrowser(){
              fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
              fileChooser.setMultiSelectionEnabled(true);
              fileChooserOption = fileChooser.showOpenDialog(null);
              if (fileChooserOption == JFileChooser.APPROVE_OPTION){
              for (File selectedFile : fileChooser.getSelectedFiles()){
                        selectedFilesList.add(selectedFile);
                        fileNames.add(selectedFile.getName());
              } // end enhanced for loop
              } // end if
         } // end constructor
    } // end class FileBrowser

  • How to create thumbnail images on the fly from JSP or servlet?

    Hi all,
    Iam new to this forum. I need a solution for the problem iam facing in building my site. Ihave groups and briefcase section in my site. I allow users to upload files and pictures.
    When they upload pictures i need to create thumbnail for them on the fly.
    Is there any taglibs or java source to do this from JSP or servlets.
    It would be very greatful if i can get an early answer.
    Please let me know if there is any other forum where i can get better answer, if not here?
    thnx.

    Here is how you can create dynamic images:
    http://developer.java.sun.com/developer/JDCTechTips/2001/tt0821.html#tip2
    However, if you want to create gifs/jpegs and save them to the disk it depends from where you want to create the images. It is different if you are creating from another image or just drawing one from scratch etc.. But in the end you will probably need to use one of the imageencoder classes and write the result to the disk with the file io classes.

  • Trying to add album from iphoto into idvd slideshow.  Not all photos are loading.  Message "creating thumbnail images...(31 remaining).  Been there a long time.  What is wrong?

    trying to add album from iphoto into idvd slideshow.  Not all photos are loading.  Message "creating thumbnail images...(31 remaining).  Been there a long time.  What is wrong?

    Open your iPhoto Library, go to that particular album and verify that you can view the full sized version of each image by double clicking on them.  Report back with the results.
    OT

Maybe you are looking for

  • Bf  datasource data is not populating in R/3 side

    Hi Folks, I have loaded 2lis_03_bx first for a plant using MCNB transaction,its showing data in RSA3 then I have loaded 2lis_03_bf datasource for the same plant using transaction 0LI2BW. but it is not showing data in RSA3. I have done the above proce

  • Problems with external monitors

    Just updated to Maverick.  Now when pulggin in the external monitor DVI connector the Macbook monitor goes very dark Anyone else having this problem?  It also happens when I plug in the DVI connector for the DLP projector.  Never happen bofore upgrad

  • Basic Start Date and Schedule Start date

    Dear All, In a Preventive Maintenance order generated through IP30, I am getting Basic Start Date and Schedule Start date as different dates. For all other orders those date as coming same.   I am using forward Scheduling. Can any one of you please t

  • GOTO Functionality from BW Report to Transaction on Portal

    Hi All, I wanted to know if anyone has any idea about having a "go to" function capability from the BW report to a transaction on the Portal? for eg if we can jump from a CRM complaints or opportunity report to the corresponding transaction on portal

  • Flex 2 and SCORM

    Does anyone know if Flex 2 is setup to be SCORM compliant? Working for the USAF all of our new developments need to be and if we could with Flex 2 and still be SCORM compliant that would be one headache down. Thanks