How to load an image without a gui? big problems...

Hey guys, I usually try my best to not ask for help and figure stuff out myself. But this last week i've been having big problems with this work project.
My goal is to load images from disk, and append them to each other to create one big image.
The images are 0-9.jpg each file containing a number in it. then i create one big file with 4 numbers in it. called final.jpg.
so far i can do all this, but whenever the program is finished, the application just keeps running. the program has literally gone through all the steps... i have a system.out.println printed on the last line after the main, after the class instantiation... and still it stays running.
how do you guys load images without a gui? This program will probably be running under unix, so i can't create a (for component example)
Panel() and media track the file load... so i'm pretty much stumped
any help you guys can provide would be really incredibly helpfull at this point. I have searched these threads for a few hours without luck. I found only 1 real post related to my problem, but eventually they said use MediaTracker = new Mediatracker( new Panel() ); which i can't use. :(
Thanks a lot guys.
:D

yeah tried doing that, didn't work either.
UPDATE
I FINALLY found a way...
and here it is for others to find!
public BufferedImage getImage(String filename) throws Exception {
FileInputStream input = new FileInputStream( filename );
JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder( input );
BufferedImage image = decoder.decodeAsBufferedImage();
return image;
it returns an image buffer, but it's better than nothing! :)
atleast this functions under unix.

Similar Messages

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

  • How to load a image after getting it with a file chooser?

    I'm still starting with JavaFX, and I simply would like to know how to load the image (e.g. png or jpg) that I selected using a FileChooser in the user interface. I can access the file normally within the code, but I'm still lost about how to load it appropriately. Every time I select a new image using the FileChooser, I should discard the previous one and consider the new one. My code is shown below:
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.shape.Rectangle;
    import javafx.scene.paint.Color;
    import javafx.scene.layout.HBox;
    import javafx.scene.control.Button;
    import javax.swing.JFileChooser;
    import javafx.scene.image.ImageView;
    import javafx.scene.image.Image;
    var chooser: JFileChooser = new JFileChooser();
    var image;
    Stage {
        title: "Image"
        scene: Scene {
            width: 950
            height: 500
            content: [
                HBox {
                    layoutX: 670
                    layoutY: 18
                    spacing: 10
                    content: [
                        Button {
                            text: "Open"
                            action: function() {
                                if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(null)) {
                                    var imageFile = chooser.getSelectedFile();
                                    println("{imageFile.getCanonicalFile()}");
                                    image = Image{
                                        width: 640
                                        url:imageFile.getAbsolutePath()
                // Image area
                Rectangle {
                    x: 10
                    y: 10
                    width: 640
                    height: 480
                    fill: Color.WHITE
                ImageView {
                    x: 10
                    y: 10
                    image: bind image
    }Thank you in advance for any suggestion to make it work. :)

    As its name implies, the url param expect... an URL, not a file path!
    So, use {color:#8000FF}url: imageFile.toURI().toURL(){color} instead.

  • How to load an image into blob in a custom form

    Hi all!
    is there some docs or how to, load am image into a database blob in a custom apps form.
    The general idea is that the user has to browse the local machine find the image, and load the image in a database blob and also in the custom form and then finally saving the image as blob.
    Thanks in advance
    Soni

    If this helps:
    Re: Custom form: Take a file name input from user.
    Thanks
    Nagamohan

  • I saw a post on how to load iMovie 6 without deleting iMovie 9 or iLife 11 I can't find the post now does anyone know if this is possible. I do not want risk not being able to reload iMovie 9 it appears that I would have to reload the whole  iLife suit

    I saw a post on how to load iMovie 6 without deleting iMovie 9 or iLife 11 I can't find the post now does anyone know if this is possible. I do not want risk not being able to reload iMovie 9 it appears that I would have to reload the whole  iLife suit

    Could have been mine!
    Happily this is easily achieved, but it has to be done backwards.
    Delete iMovie 9 (just drag it to the trash). Now install iMovie 6 from the iLife 6 install disks.
    Now re-install iMovie 9. This automatically moves iMovie 6 into a folder it creates in your Applications folder called iMovie Previous Version.
    Now you have them both, and you can have both in the Dock as well.
    Alternatively you could try this method, suggested by poster Uitech:
    Open a terminal and type "touch /Library/Preferences/com.apple.iLife08.plist"
    (No quotes)
    Install iMovieHD6 from the iLife 6 install disk.
    This works with both Leopard and Snow Leopard Macs.

  • Can anyone tell me how to load an image to custom shape in Photoshop? I can't save it as csh...

    I've made an image, as the watermark of our photos, but I can't load it to Custom Shape in PS CS4 as I can't save it as csh. Do you know how to upload an image type file that is not csh? Or how to convert the image to csh? Thanks.

    As Chris says, you can't make it into a custom shape unless you create it as a path. But you can save it as a Custom Brush (in monochrome).

  • How to best arc image without distortion to fit curved cup template?

    I have tried searching forum for this and I know it has been discussed before but not really finding what I need to do correctly.  I have attached the layered image (reducing opacity so you can both template and image). The vendor provided me a flat template, not a path, to do my artwork. As you can see I need to arc the image without distorting to fit a cup template. I am more comfortable in photoshop but I can export to AI if necessary to complete which appears what I need to do via envelope distort from what I keep seeing. However, the template provided is not a path. I tried to trace template shape manually with pen tool and use envelope distort to arc my image to conform but it looked very distorted and no even close to what I was trying to achieve. I tried to do tradition arc warp in photoshop but it still seems to distort proportions. Steps on how best to do this would be much appreciated! I know there must be a easier/more efficient way to achieve this.

    I would not trace the template and will simply use it as a visual reference for deforming (conforming) the image to it. You can make the template image transparent to certain degree using the Transparency panel so you can see through it then move its layer on top of all other layers and lock it. Scale and position your image in such way that at least two of its corners fit two corners of the template for example the two top corners and then its bottom edge is on the same level as the template.Then select the image to be deformed and in the control panel at the top of your screen click the Embed button which allows you to deform the image (edit: just noticed you wrote it is already embedded, so skip this).
    Choose Object > Envelope Distort > Make it with a Mesh. and chose 1 for rows and columns. Make sure the Smart Guides are on (View > Smart Guides). With the Selection tool (white arrow) Shift click or drag a selection box to select the two points of one of the vertical sides of your image. Pick the Sheer Tool and first just click on the selected top corner point to set the reference point of the sheer then click and drag the corresponding bottom point to match it to the corresponding point of your template. You may hold Shift while dragging to constrain although the Smart Guides will do that by snapping to edge of the envelope if your mouse is close to it. Repeat this for the other side of image. To make the image curved, pick the Selection tool (white arrow) click a corner point which will display its handles, pick a handle that is on a horizontal side of the image and pull it up to deform the shape referring to the template. You may do this first roughly with all horizontal handles and then you can drag guides from the ruler when a handle is selected to snap a guide to it and use it to put the corresponding handle on the opposite side on the same level.
    Once you have deformed the image to conform to the template, you can fine tune the distribution of the vertical deformation with the vertical handles of the corner points. You can grab a handle and drag it along the vertical paths of the envelope (the Smart guides will snap to it). Drag the vertical handles on one each side lower until you like the distribution of the deformation.
    Try to follow my instructions and I'll clarify if you are stuck.

  • How to load a image from database to image item in oracle 10 g form

    I have stored some images in the Database Table with BLOB datatype. Now I need to load that image in the non database image item. Please advise. Thanks.

    You need to have a print server installed to generate the pdf. Either use BI Publisher and it's desktop development tool or use FOP/Cocoon.. Adding an image with them is a little more involved..
    Thank you,
    Tony Miller
    Webster, TX
    While it is true that technology waits for no man; stupidity will always stop to take on new passengers.

  • How to load the image on to the Java applet?

    Hey,
    I need help on loading a image to java, I am using Eclipse, I have no idea what class I should use. Please help me thanks

    I found this with search problem with loading images

  • How to load an image from local disk?

    Hi!
    I have spent hours on the net searching for an example, that
    could
    show me how could I make a flex script that user could browse
    (like fileReference.browse() ) for a
    file (picture) and then show this picture in the browser (so
    the source of some existing picture would change).
    I found only multiple solutions on how to upload a picture,
    but
    that is not the thing I wanna do. I want a user to load a
    picture from
    his disk and simply to be seen in a browser (on a page).
    I tried programming it alone, but the FileReference class has
    no attribute path or similar, that I could use for source of my
    image.
    Please help, I need to do this urgently.
    Thank you very very much
    Gus

    OK, I tried without FileReference, simply by changing String
    variable of the source path when calling image.load(path), but it
    works ONLY FOR REMOTE pictures (online), I also tried with
    [Bindable]
    [Embed(source="C:/somePicture.jpg")]
    public var _img0:Class;
    , but it appears that you CANNOT CHANGE THE PATH DOURING
    EXECUTION (dinamically)
    So please, someone?
    Is it even possible to do that?
    I could try uploading picture and then downloading, but why
    would I need a server side if I don't need it...
    Help

  • How to Load External Images - Please Help!

    I have created a simple portfolio site. The buttons I created
    trigger separate frames. Could I not create a MC (Movie Clip) on
    each frame where the images now reside and then when the button is
    clicked (On "Click' Goto frame 1) for e.g. then the image would be
    loaded from an external folder named "Images" in my website?
    I am stumped as to how to set this up. Could someone please
    help me?
    Thanks

    Yes, you can do that. Which version of Flash and which
    version of Actionscript are you using?

  • How to load an image on a LAP1252 with the bootloader

    Hello--
    I have a LAP1252 that lost the flash image, consequently, when it tries to boot, the boot loader can not find anything to load. I can not find any documentation on how to use the TFTP client on the AP, can anyone point me in the right direction?
    Thank you.

    Converting a Lightweight Access Point Back to Autonomous Mode
    http://www.cisco.com/en/US/docs/wireless/access_point/conversion/lwapp/upgrade/guide/lwapnote.html#wp161272

  • How to Create an image without a background?

    Hi,
    So I've been learning the ropes of photoshop all week and I started and am almost finished with my first project.
    I created a cutout and I want to make a sticker out of it, but I'm not sure how to save it without the white background.
    Here's what it looks like to get a better idea of what I'm asking, I want the player to just be on his own on a sticker, like a cutout.

    You need to save your document that has  transparency in an image file format that supports transparency. If you want to use the image on the web it needs to be an image file format that browsers supports.   That means PGN or GIF format.  GIF only supports 255 mapped colors when there is transparency. And the Transparency is complete no partial transparency.  PNG supports 8 or 16 bit color and transparency.  You should use sRGB color space for only some browsers use color management the rest assume images are sRGB. Gif file sizes are smaller the PNG files.

  • How to load background image in canvas fast?

    Hi all,
    I am loading dynamic background in canvas with http path. It takes little bit time. How can i make it fast?
    Please help me.
    Thanks,
    -CK

    Make a friend with firebug &  you could find yourself from where it is getting applied.
    For the website you have given the background image it is using is [1] and it is getting set in css of body tag [2]. So Find the css at [3] and modify it OR replace [1] with other image with same file name.
    [1]   www.hanwha.com/etc/designs/hanwha/images/bg-body.jpg
    [2]
    body {
        background: url("images/bg-body.jpg") repeat-x scroll 50% 0 #FFFFFF;
        color: #757373;
        font: 14px/18px Arial,Verdana,Helvetica,sans-serif;
        margin: 0;
        min-width: 979px;
    [3]
    /etc/designs/hanwha/...../*.css

  • How to eject disk image without needing it to run a program

    When ever i install a program from the internet such as Skype an image appears on my desktop...when i eject it and open Skype it says i cannot use it because i need it.how do i get rid of the image and still be able to use the program?
    Thanks-

    The sequence usually goes something like this:
    1. Download the disk image or package.
    2. Open or Double-click the disk image.
    3. Install or Drag the application into the applications folder.
    4. Eject the disk image or package.
    5. Run the application from the applications folder, keeping it in the dock if you choose.
    I say this without knowing specifically how Skype works, but this is generally how programs install.
    Joe

Maybe you are looking for