Creating Thumnail

Hi Friends ...
I am creating thumnail by this code ...
public static void createThumbnail(String original, String thumbnail, int maxDim , String format) {
try {
Image inImage = new ImageIcon(
original).getImage();
     double scale = (double)maxDim/(
     double)inImage.getHeight(null);
if (inImage.getWidth(
null) > inImage.getHeight(null)) {
scale = (double)maxDim/(
double)inImage.getWidth(null);
int scaledW = (int)(
scale*inImage.getWidth(null));
int scaledH = (int)(
scale*inImage.getHeight(null));
BufferedImage outImage =
new BufferedImage(scaledW, scaledH,
BufferedImage.TYPE_INT_RGB);
// Set the scale.
AffineTransform tx =
new AffineTransform();
// If the image is smaller than
//the desired image size,
// don't bother scaling.
if (scale < 1.0d) {
tx.scale(scale, scale);
// Paint image.
Graphics2D g2d =
outImage.createGraphics();
g2d.drawImage(inImage, tx, null);
g2d.dispose();
// JPEG-encode the image
//and write to file.
OutputStream os =
new FileOutputStream(thumbnail);
/*JPEGImageEncoder encoder =
JPEGCodec.createJPEGEncoder(os);
encoder.encode(outImage);*/
ImageIO.write(outImage , format , os);
os.flush();
os.close();
os = null;
}catch(Exception e){
System.out.println("Exception in Creating Thumbnail :" +e);
PROBLEMS :::
The problem is that when ever i am updating my original image ..i can;t see the updated thumnail copy of it ..this code always return copy of thumnail that i have created first time during invoketion of code..and subsequent time it return only that copy (First Copy) irespect of original image.update...can any body guess what is happing ..with this ..
Please give me replay as soon as possible..
Thanks ADvance..
Parthiv Patel

If I understand your problem, it's that after the first time you call this method, it always makes a thumbnail of the original image instead of using the one on disk? If that's the problem it's because the ImageIcon uses Toolkit.getImage, which caches requests for images in a file to return the same image. You need to get the image like this:Image image = Toolkit.getDefaultToolkit().createImage(original);
if (image == null) return;
MediaTracker mt = new MediaTracker(new Component());
mt.addImage(image, 0);
try { mt.waitForAll(); }
catch (Exception e) {}

Similar Messages

  • Creating thumnail of an image

    how can i creat the thumbname of an image

    Hey, i was looking for a solution recently, and found javax.imageio.
    Use ImageReader to read image files. If you want to create thumbnails, create a ImageReadParam, and setSourceSubsampling(2,2,0,0) basicly skips every second pixel as its reading the file.
    Have a look at ftp://ftp.java.sun.com/docs/j2se1.4/imageio_guide.pdf
    very cool.

  • Create thumnail from image

    Can we create thumbnail from a image in Oracle 11g database?

    The image is stored as blob secure file in oracle 11g database.
    What is the difference between blob and ORDImage?
    Can I create thumbnail from a image and store it in the database?

  • How to create Thumnails images of word/excel documents

    Hi Experts,
    I need java code which can generate thumbnail images of any Word/Excel document.
    I have found code related to creation of thumbnail of any JPEG image.
    Please help me out on this issue. Your suggesions are also appriciated

    Hi i dont know,but you can giave a look to Jakarta POI that can have a awt preview for Excell document,or you can try to replicate your document with Jasper,design a pdf like your word or excell document , and use the AWTPreview.
    Are only suggestion!

  • HiRes photos

    I have created photo pages using the conventional iPhoto / iWeb functionality. But my photos only load in low / med resolution when accessing the site.
    Can I provide an option for HiRes - large size - access to the photos?

    Making my own thumbnails and creating hyperlinks is quite a bit more difficult than just dragging photos into a photos template but sometimes you have to do what you have to do. You can create thumnails with iPhoto but I decided to create a workflow and I saved it as a finder plugin so I can right click on a photo and create a thumbnail on the spot. Then you drag the thumnail to your iWeb page, select it, open the Inspector, click on the hyperlink tab, and choose the file you want it linked to. If you want a caption, that will require a text box. I chose not to use captions so I avoid that step.
    For the Make Thumbnail plugin, it's been a while since I made it but I remember having an issue with Automator's "make thumbnail" workflow listed under "Preview". If I recall, the thumbnails ended up relatively large (in kilobytes). But it did make them. I think I ended up doing something with the iMagine Photo tools instead. Plus I used iMagine to create several "scale image" plugins so really large photos could be scaled down to a more manageable and downloadable size.
    As with a lot of things, getting everything set up takes some time. But once it's set up right, everything goes smoothly from there.
    http://www.yvs.eu.com/imaginephoto.html

  • Resizing Images in fly (while downloading)

    I have a program which downloads images in to File System and show it to the user, like an online album.The images are downloaded in multipart.Before showing the full image we first show the album (thumbnails).
    The problem we are facing is that the images downloaded are of very large byte length.To create thumnail of every images , we first create the image and then manipulate the pixels of the image using getRGB () to resize.
    But if the image is of larger byte lenght holding that much array or image crash the phone(Motorola V3i , )
    Do any one know about any reference we can look so that we can create the thumnail image from the byte array while it is been downloaded ?
    cheers
    Abhijith

    This option is already there.The problem comes when we are loading images from phone gallery,which were taken using device's native camera.
    When we create image for the thumnail creation the app crashes or shows out of memory.We are forced to show a message to the use that , the image is large and can not be shown into display.

  • How to load mutiple image

    I'm trying to create a photo manager but I can't find a way to load multiple images onto my frame. I have a thumbnail class that makes thumbnails for an image (which is a modified version of the class ImageHolder from FilthyRichClient)
    public class Thumbnails {
         private List<BufferedImage> scaledImages = new ArrayList<BufferedImage>();
    private static final int AVG_SIZE = 160;
    * Given any image, this constructor creates and stores down-scaled
    * versions of this image down to some MIN_SIZE
    public Thumbnails(File imageFile) throws IOException{
              // TODO Auto-generated constructor stub
         BufferedImage originalImage = ImageIO.read(imageFile);
    int imageW = originalImage.getWidth();
    int imageH = originalImage.getHeight();
    boolean firstScale = true;
    scaledImages.add(originalImage);
    while (imageW >= AVG_SIZE && imageH >= AVG_SIZE) {
         if(firstScale && (imageW > 320 || imageH > 320)) {
              float factor = (float) imageW / imageH;
              if(factor > 0) {
              imageW = 320;
              imageH = (int) (factor * imageW);
              else {
                   imageH = 320;
                   imageW = (int) (factor * imageH);
         else {
              imageW >>= 1;
         imageH >>= 1;
    BufferedImage scaledImage = new BufferedImage(imageW, imageH,
    originalImage.getType());
    Graphics2D g2d = scaledImage.createGraphics();
    g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
    RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g2d.drawImage(originalImage, 0, 0, imageW, imageH, null);
    g2d.dispose();
    scaledImages.add(scaledImage);
    * This method returns an image with the specified width. It finds
    * the pre-scaled size with the closest/larger width and scales
    * down from it, to provide a fast and high-quality scaled version
    * at the requested size.
    BufferedImage getImage(int width) {
    for (BufferedImage scaledImage : scaledImages) {
    int scaledW = scaledImage.getWidth();
    // This is the one to scale from if:
    // - the requested size is larger than this size
    // - the requested size is between this size and
    // the next size down
    // - this is the smallest (last) size
    if (scaledW < width || ((scaledW >> 1) < width) ||
    (scaledW >> 1) < (AVG_SIZE >> 1)) {
    if (scaledW != width) {
    // Create new version scaled to this width
    // Set the width at this width, scale the
    // height proportional to the image width
    float scaleFactor = (float)width / scaledW;
    int scaledH = (int)(scaledImage.getHeight() *
    scaleFactor + .5f);
    BufferedImage image = new BufferedImage(width,
    scaledH, scaledImage.getType());
    Graphics2D g2d = image.createGraphics();
    g2d.setRenderingHint(
    RenderingHints.KEY_INTERPOLATION,
    RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g2d.drawImage(scaledImage, 0, 0,
    width, scaledH, null);
    g2d.dispose();
    scaledImage = image;
    return scaledImage;
    // shouldn't get here
    return null;
    A loop will loop through a collection of files and pass them to the constructor of Thumbnails to create thumbnails and then set them as icon for JLabels that will be added to a JPanel, but it throws a java.lang.OutOfMemoryError at this line:
    BufferedImage originalImage = ImageIO.read(imageFile);
    even when there're only about 8 image files in the collection (total size 2,51MB).
    I've seen other people's software that could load hundreds of photos in a matter of seconds! How do I suppose to do that? How to load mutiple images efficiently? Please help!! Thanks a lot!

    another_beginner wrote:
    Thanks everybody! I appreciate your help! I don't understand why but when I use a separate thread to do the job, that problem disappear. You were likely doing your image loading and thumnail creation on the Event Dispatching Thread. Among other things, this is the same thread that updates and paints your panels, frames, buttons, ect.. When a programer does something computationaly expensive on the event dispatching thread then the GUI becomes unresponsive until the computation is done.
    Ideally what you want to do is load images and create thumnails on a seperate thread and update your GUI on the event dispatching thread. I supect that while you are finally doing the first item, you might now be violating the second item.
    Whatever, the program seems to be pretty slow on start up 'cause it have to reload images everytime. I'm using Picasa and it can display those thumbnails almost instantly. I know that program is made by professionals. But I still want to know how.I took a look at this Picasa you mentioned. It's the photo manager from google right? You're right in that the thumnails display instantly when starting up. This is because Picasa is actually saving the thumnails, instead of creating them everytime the program starts up. It only creates the thumnails once (when you import a picture) and saves the thumnail data to " +*currentUser*+ /AppData/Local/Google/Picasa2/db3/" (at least on my computer --> Vista).
    Also, if your looking for speed then for some inexplicable reason java.awt.Toolkit.getDefaultToolkit().createImage(...); is faster (sometimes much faster) than ImageIO.read(...). But there comes a price in dealing with Toolkit images. A toolkit image isn't ready for anything until it has been properly 'loaded' using one of several methods. Also, when you're done and ready for the image to be garbage collected then you need to call Image.flush() or you will eventually find yourself with an out of memory error (BufferedImages don't have this problem). Lastly, Toolkit.createImage(...) can only read image files that the older versions of java supported (jpg, png, gif, bmp) .
    And, another question (or maybe I should post it in a different thread?), I can't display all thumbnails using a JPanel because it has a constant height unless I explicitly set it with setPreferredSize. Even when put in a JScrollPane, the height doesn't change so the scrollbar doesn't appear. Anyone know how to auto grow or shrink a JPanel vertically? Or I have to calculate the preferred height by myself?Are you drawing the thumnails directly on the JPanel? If so then you will indeed need to dynamically set the preferred size of the component.
    If not, then presumebly your wrapping the thumnails in something like a JLabel or JButton and adding that to the panel. If so, what is the layout manager you're using for the panel?

  • Empty music folders!

    I just moved a hard drive with my iTunes music folder on it into my 'new' G4 tower.
    I pointed iTunes to that music folder but nothing showed.
    I made a new music folder and tried to Add the old folder to Library but nothing.
    I poked around and found a music folder in users/me/ etc on the moved hard drive (I had partitioned it into a boot volume and a storage volume) and Added that to Library but that omitted everything I ripped in the last month or so.
    The music folder I added from didn't have folders for the music I ripped lately.
    The music folder I thought I was using does have folders for all the music I ripped right up until I moved the hard drive but those folders and all the others actually, are empty.
    I'm very confused....
    G4/1.2Ghz   Mac OS X (10.4.8)   iTunes 7

    If it's the last file in the folder then iTunes should delete the folder too, and if that's the last folder in the parent folder then the parent should go as well. I.e. if you delete the last track by a given album artist then the album & the artist folders should both be removed.
    It doesn't always work that way on a PC where Windows Media Player has had access to the same media, as WMP creates thumnail artwork in the folders, so when the last track is deleted there can still be orphaned artwork in the folder. I have written a windows script called CleanDearArt for just this purpose. If for some reason iTunes can't/won't clean up on a Mac then there is almost certainly a tool to do it at Doug's AppleScripts for iTunes
    tt2

  • Servlet that produces thumbnails

    Hi there,
    Does anyone know how to create thumnails and display them in a results page?
    I ve created a search servlet that enables you to search documents and images on a server and then displays the results in a webpage.
    I ve basically been stuck trying to create thumbnails of the images and displaying them within the HTML.
    however i found a thumbnail class that creates thumnails of the image and outputs the thumbnail to a file using the fileoutput stream.
    what someone else suggested is that i write a class that takes the location of the file and
    returns an outputstream with the image info to the servlet.
    I am not exactly sure how to do this. Do I pass a HttpServletResponse object to the new class and then return it to the main servlet somehow?
    Or another suggestion was to create the HTML with the url to a tumbnail servlet in an image tag????????
    ie <img SRC="/servlets/Serlvetlocation?location="blah.txt">
    I doubt this would work!
    Anyone have any ideas?
    Thanks a million
    Dave

    <img SRC="/servlets/Serlvetlocation?location="blah.txt">
    I doubt this would work!Actually, that works just fine. :-)
    The only requirement is that the servlet sets content-type to "image/gif", "image/png" or whatever.

  • How can I create an image gallery with "next" buttons?

    So I am almost done with my portfolio site (YES!)..now I just need the actual content (the images). My site is written in AS3.
    I've watched many tutorials on how to create an image gallery (auto scrolling ones, scrolling ones that require mouse hover, etc etc), but those aren't what I am looking for.
    I want a gallery that looks exactly like this one here:
    http://jalbum.net/res/help/integrating-tutorial.html
    I have a lot of work to display in my porfolio so there must be arrows at the end of the thumbnails so I can add more stuff. So I am just stumped on how to make the image gallery work with the ability to scroll for more photos with the click of the arrows.
    Any ideas? Thank you.

    Watching tutorials and learning from them are two different things.  If you have learned from them you should be able to use what you have learned to devise a gallery such as the one you link to.  If you have learned from them and cannot use what you learned, then you probably need to find/learn more.
    If you study the design you linked you should be able to reason out what elements you need to devise... it is not overly complicated. 
    For the large picture you could have a Loader into which you load whatever image is selected from the thumnails. To get a brief transition you could just set the alpha of the Loader to 0 when an image change is occuring and gradually fade it in after the image has loaded.
    The greatest challenge you are likely to face is in getting the thumbnails to advance back and forth depending on which is selected.  All of the thumbs would be placed in a container (movieclip or sprite) and that would be masked so that only a portion of them is visible. 
    All thumbs that are not selected have their alpha property set to some value less than 1.  Selecting one calls for the file it associates with to be loaded into the Loader.  If the choice happens to lie off screen, then you need to move the movieclip that contains all of the thumbs some set value in the right (+x) or left (-x) direction.
    If you want the thumbnails to wrap infinitely then when one leave the thumbnails area for movement in a direction, you need to take that thumb and relocate it to the other end of the thumbs in the container.

  • Bridge CS6 not creating preview extractions for .mp4, .mov .wmv or .avi

    In all versions up to now when I would cache my folders with video files they would create preview extractions so that I could scroll through the video in the Preview Pane.
    The only files that are doing this now are the .flv files (which ironically do not create a thumnail image, and never have in Bridge, but that's another topic altogether.)
    I looked through all the preferences and I don't see a way to turn preview extractions on or off.
    How do I "force" Bridge to create the previews and why did it not do it automatically like all previous versions have?
    Thank you!
    I have a brand 2 month old top of the line iMac with all the latest software and plenty of free space. This is definitely an issue w Bridge, not my computer.

    I was having an issue very similar to this. I tested it on CC, CS6 and both did the same thing. No previews and if i tried to purge the cache, it would stop responding all together. Then I noticed I had an eps file with no file extention. I went ahead and removed it from the folder and now everything works like it should. If the above option of purging does not work, try to remove the files and see if one of them is an issue.

  • Copy-paste of a chart or table in new iWork creates a low resolution raster rather than a vector

    In iWork '09 I regularly copied charts, tables, etc. from iWork applications to other applications. They were in vector format. For instance, I have made a chart in Numbers, copied it, and pasted in Preview. This resulted in a vector which I saved to PDF, everything in less than 5 seconds.
    It seems that in the new iWork this is not possible anymore, because the result is a low-resolution raster, which totally broke my workflows.
    Is this an "enhacement" of the new iWork or I am missing something?

    Hi Badunit,
    A possible explanation for our discrepency:
    If I copy an entire page from a vector pdf using the thumnails bar in preview and paste that page into keynote, the image is a raster.
    If I select a portion of that page with the preview selection tool, copy, and paste into keynote, the image is a vector.
    This issue is especially damaging because I can't drag and drop pdf files I create into keynote. Major bugs have been introduced with regards to vector images, and I'm unable to identify a single rule characterizing this process. This is a disaster as I've relied on keynote as a longterm storage and organization tool for many vector images. Many of these images have now been corrupted in what I assume is an irreversible process.

  • 10.8.3 update kills cd-roms created with Mac OS Standard HFS format

    Archived CD's created with HFS (MacOS Standard in get info) would mount and you could copy and open documents with no problems a couple of weeks ago in 10.8.2. But after 10.8.3 update are now mounting but you cannot copy or open the files on them.
    Below a CD in finder under 10.8.3, while trying to copy to desktop and trying to open from CD.
    Below same CD in finder of 10.8.2. CD contents show with thumnail preview and the document opens from the CD no problem.
    Why would Apple drop support for HFS in an incremental update with no documentation able to be found anywhere? Any ideas?

    I can't reproduce that. I have a very old backup CD, made in April of 2000 and using the Mac OS Standard format. It works just fine on my 10.8.3 system:
    As you can see, I can open an image file on that CD just fine.
    It's important to note that home-burned CDs don't last forever. They have a limited shelf life, and if they're being used (and exposed to light) frequently, that life will be shorter. All CDs will eventually fail, and I'm guessing that's what happened with yours. Perhaps they are failing in a way that 10.8.2 could deal with, but 10.8.3 can't? I don't know.
    I did see some very strange behavior from the first disk I tried, which was also Mac OS Standard, but was much older (it had no date on it, but I'm guessing mid-90s). Files would show up very briefly, then would disappear from view. Even the Terminal behaved oddly when trying to list the contents. Trying to copy folders to the hard drive resulted in -43 (ie, file not found) errors. It looks like that disk has failed.

  • Looking to create archive system to replace Thumbsplus have questions

    Hi all,
        I need to have these questions answere so I know if I can switch my archiving system from Thumbsplus to Lightroom. FYI: My archiving sytem has worked for me for about 12 years & I need the following functions or a work around.
    Can lightroom read files within a zipped folder? If not is there a pluggin for that?
    I give names to my CDs. In Thumbsplus I can see a list of my offline CDs. Does Light room have something similar? FYI: I Imported the files from a CD and something funny happened. When I click on the arrow iin the Folders Panel (in lightroom) I don't see the name of the CD, instead I see the names of the folders that were on the CD. Ideally I would click on the arrow iin the Folders Panel (in lightroom) and see the names of the CDs that were imported. Am I being clear? Is there a solution to this?
    Can I convert psd files to jpegs
    I also need the ability to type a name of a file and find which offline CD it's on (like thumbsplus does).
    In Thumbs  plus if I go to a folder and there are thumbnails that weren't created it shows be a blank box with an X with the name of the file under it. This is a great benefit to my art studio. We have a large art studio and alot of artists forget to make the thumnails - they see the blank boxes and know they have to create them. Does lightroom have a similar feature. If this is so can I make thumbnails of individual files (the blank ones with the Xs in them).
    Is the a way of saving the entire database offline. I need this in case I my system crashes or If I want to transfer my offline CD thumbnails to another pc (that has lighrooom installed).
    If any has the time to answer these questions it would be greately appreciated. Please try to explain in simple terms.
    PS: Also if I'm off base with my ideas on how to use lightroom to archive things, can someone please steer me towards an archiving program that addresses these issues?
    Thanks,
    Frederick
    Thanks,
    Frederick

    www.migcalendar.com.
    But this is not a free software. After completion of ur deveopment please inform us.

  • Created 2 slideshows, but only 1 works??

    Hi there
    I have created two slideshows, but only one works. I have
    reverted back to the tradisional tile layout of images of the one
    that does not work, but that is not what my client wants.
    The one that works can be viewed at
    Catering
    The images of the one that does not work can be viewed at
    Gallery
    I am using the same player in both cases. I have tested both
    on my laptop using all browsers I could think of. After I FPT'ed
    the files to the hositng server, the Gallery does not display
    anything in the "Image Viewer". Thumnails, headers, etc are
    displayed.
    Any suggestions? I am at a complete loss.
    P.S.: I am using Fireworks and Dreamweaver CS3.
    Many thanx

    Check these out:
    iPod Does Not Appear in My Computer
    iPod Appears in Windows but not in iTunes
    I hope this helps!

Maybe you are looking for

  • Remote Update Server setup

    Using the AUSST tool to set up a remote update server on Windows Server 2012R2 which is IIS 8.5. Working through this document: http://helpx.adobe.com/creative-cloud/packager/update-server-setup-tool.html#Preparing a web server to use as the update s

  • Ordinal 55 could not be found in the dynaminc link library iertutil.dll cs5.5 installation problem.

    Okay, so when i downloaded the trial version of Flash Professional CS5.5, the following popup "popped up". "The dynamic link library iertutil.dll could not be found. Reinstalling the application may solve this problem." So i went to a site that had h

  • How do i rotate pictures in ipad albums?

    How do I rotate pictures in ipad albums?  The icon they show in the user instructions does not appear on my ipad.

  • Slow framerates and weird shaders in game

    Inside the game "Sauerbraten" which is a 3D shooter, I get very low framerates and some surfaces with shaders have strange glitches on them. I have Mac OS X Leopard 10.5.2, and I have the game and OS up to date. To make sure this wasn't just with the

  • Survey Application

    I am looking for an App to administer surveys and then upload the data to a website. The only one I have found is touchmetric and they do not answer their support. Any information would be appreciated. I need the survey to do rating scales. Thanks, R