Loading an image in to createImage()

Hello, I am trying to load an image in to the createImage() method so that I can rotate it on a panel (without the whole panel rotating!!). Basically I just want to copy all the pixels from one image and paste them in to another.
Hope someone can help
Andrew
Btw, why do I get a runtime error with image.getGraphics() when when intialising an image using getImage(getDocumentBase(),filename) ?

You have the Image object? If so...
      * Rotates the specified image the specified number of degrees.  The
      * rotation is performed around the center point of the image. 
      * @param  img         the image to rotate
      * @param  degrees     the degrees to rotate
      * @param  bbm         the bounding box mode, default is EXACT_BOUNDING_BOX
      * @param  background  the background paint (texture, color or gradient),
      *                     can be null
      * @return  the image
      * @see  #NO_BOUNDING_BOX
      * @see  #EXACT_BOUNDING_BOX
      * @see  #LARGEST_BOUNDING_BOX
     public static BufferedImage rotateDegrees(Image img, double degrees, int bbm, Paint background) {
          return rotateRadians(img, Math.toRadians(degrees), bbm, background);
      * Rotates the specified image the specified number of radians.  The
      * rotation is performed around the center point of the image.  This
      * method is provided for convenience of applications using radians. 
      * For most people, degrees is simpler to use. 
      * @param  img         the image to rotate
      * @param  radians     the radians to rotate
      * @param  bbm         the bounding box mode, default is EXACT_BOUNDING_BOX
      * @param  background  the background paint (texture, color or gradient),
      *                     can be null
      * @return  the image
      * @see  #NO_BOUNDING_BOX
      * @see  #EXACT_BOUNDING_BOX
      * @see  #LARGEST_BOUNDING_BOX
     public static BufferedImage rotateRadians(Image img, double radians, int bbm, Paint background) {
          // get the original image's width and height
          int iw = img.getWidth(null);
          int ih = img.getHeight(null);
          // calculate the new image's size based on bounding box mode
          Dimension dim;
          if(bbm == NO_BOUNDING_BOX) {
               dim = new Dimension(iw, ih);
          } else if(bbm == LARGEST_BOUNDING_BOX) {
               dim = getLargestBoundingBox(iw, ih);
          } else { // EXACT_BOUNDING_BOX
               dim = getBoundingBox(iw, ih, Math.toDegrees(radians));
          // get the new image's width and height
          int w = dim.width;
          int h = dim.height;
          // get the location to draw the original image on the new image
          int x = (w/2)-(iw/2);
          int y = (h/2)-(ih/2);
          // need to copy the given image to a new BufferedImage because
          // it is, in most cases, going to be a larger image so it
          // needs to be drawn centered on the larger image
          BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
          Graphics2D g2d = bi.createGraphics();
          // set some rendering hints for better looking images
          g2d.setRenderingHints(renderingHints);
          // draw the background paint, if necessary
          if(background != null) {
               g2d.setPaint(background);
               g2d.fillRect(0, 0, w, h);
          // if not rotating, just draw it normally, else create a transform
          if(radians == 0.0) {
               g2d.drawImage(img, x, y, iw, ih, null);
          } else {
               g2d.rotate(radians, w/2, h/2);
               g2d.translate(x, y);
               g2d.drawImage(img, 0, 0, iw, ih, null);
          g2d.dispose();
          return bi;
      * Gets the largest bounding box size that can hold an image of the
      * specified size at any angle of rotation. 
      * @param  width   the image width
      * @param  height  the image height
      * @return  the bounding box size
     public static Dimension getLargestBoundingBox(int width, int height) {
          // The largest bounding box is the largest area needed to fit the
          // specified image at any angle or rotation.  This is simpler then
          // getting the bounding box for a given angle because the largest
          // box will put the corner of the image box directly along the
          // vertical or horizontal axis from the image center point.  The
          // distance between the image rectangle's center and any corner
          // is the hypotenuse of a right triangle who's other sides are
          // half the width (a) and half the height (b) of the rectangle. 
          // A little a^2 + b^2 = c^2 calculation and we get the length of
          // the hypotenuse.  Double that to get a square within which the
          // image can be rotated at any angle without clipping the image. 
          double a = (double)width / 2.0;
          double b = (double)height / 2.0;
          // use Math.ceil() to round up to an int value
          int c = (int)Math.ceil(Math.sqrt((a * a) + (b * b)) * 2.0);
          return new Dimension(c, c);
      * Gets the optimal/smallest bounding box size that can hold an image of
      * the specified size at the specified angle of rotation. 
      * @param  width   the image width
      * @param  height  the image height
      * @return  the bounding box size
     public static Dimension getBoundingBox(int width, int height, double degrees) {
          degrees = normalizeDegrees(degrees);
          // if no rotation or 180 degrees, the size won't change
          if(degrees == 0.0 || degrees == 180.0) {
               return new Dimension(width, height);
          // if 90 or 270 (quarter or 3-quarter rotations) the width becomes
          // the height, and vice versa
          if(degrees == 90.0 || degrees == 270.0) {
               return new Dimension(height, width);
          // for any other rotation, we need to do some trigonometry,
          // derived from description found at: 
          // http://www.codeproject.com/csharp/rotateimage.asp
          double radians = Math.toRadians(degrees);
          double aW = Math.abs(Math.cos(radians) * width);
          double oW = Math.abs(Math.sin(radians) * width);
          double aH = Math.abs(Math.cos(radians) * height);
          double oH = Math.abs(Math.sin(radians) * height);
          // use Math.ceil() to round up to an int value
          int w = (int)Math.ceil(aW + oH);
          int h = (int)Math.ceil(oW + aH);
          return new Dimension(w, h);

Similar Messages

  • How can i load a image into a midlet?

    Hi, i placed the png file together wif the midlet in the src directory.
    Image img = Image.createImage("title.png");
    I tried the above code but when i try to load the image in got this error
    Failed loading image.
    anione can help?

    just place your file in /res/ directory not in /src/

  • Loading an image in an applet

    I am trying to load and display an existing image to my applet and break the image up into segments to allow the pieces to be moved into their correct position. However it is only getting as far as cutting the image up but it does not complete loading the image. Below is the run() method im using to load it:
    public void run()
            int i;
            MediaTracker trackset;              // Tracker for images
            Image WholeImage;                 // The whole image
                        Image ResizedImage;
            ImageFilter filter;
         // Determine the size of the applet
         r = getSize();
            // Load up the image
            if (getParameter("SRC") == null)
              Error("Image filename not defined.");
         WholeImage = getImage(getDocumentBase(), getParameter("SRC"));
         // Scale original image if needed
            // Make the image load completely and put the image
            // into the track set.  Where it waits in paint() method.
            trackset = new MediaTracker(this);
            trackset.addImage(WholeImage, 1);
            // Mix up the puzzle
            System.out.println("Mixing puzzle.");
            PaintScreen = 2;
            repaint();
            try {
            Thread.sleep(100);
         } catch (InterruptedException e) {
            // Tell user of the wait for image loading
           //Trap trackset exceptions that track if the image
           //hasn't loaded properly and output to the user.
            PaintScreen = 0;
            repaint();
            try {
            Thread.sleep(100);
         } catch (InterruptedException e) {
            try {
               trackset.waitForID(1);
            } catch (InterruptedException e) {
               Error("Loading Interrupted!");
            // Check if image loaded up correctly
            //Where is image is held in the same directory
            //as the HTML file use getImage method to pass
            //getDocumentBase(), taking in the getParameter.
            if (WholeImage.getWidth(this) == -1)
                 PaintScreen = 3;
                 repaint();
                 WholeImage = getImage(getDocumentBase(), getParameter("SRC"));
                 trackset = new MediaTracker(this);
                 trackset.addImage(WholeImage, 1);
                 try {
                    trackset.waitForID(1);
                 } catch (InterruptedException e) {
                    Error("Loading Interrupted!");
                 if (WholeImage.getWidth(this) == -1)
                      PaintScreen = 4;
                      repaint();
                      stop();
                      return;
         // Resize picture if needed.
         int ResizeOption = integerFromString(getParameter("RESIZE"));
         if ((r.width != WholeImage.getWidth(this) ||
              r.height != WholeImage.getHeight(this)) &&
                ResizeOption != 0)
              if (ResizeOption == 2)
                ResizedImage =
                  WholeImage.getScaledInstance(r.width, r.height - TOP_MARGIN,
                                     WholeImage.SCALE_FAST);
              else if (ResizeOption == 3)
                ResizedImage =
                  WholeImage.getScaledInstance(r.width, r.height - TOP_MARGIN,
                                     WholeImage.SCALE_SMOOTH);
              else if (ResizeOption == 4)
                ResizedImage =
                  WholeImage.getScaledInstance(r.width, r.height - TOP_MARGIN,
                                     WholeImage.SCALE_AREA_AVERAGING);
              else
                ResizedImage =
                  WholeImage.getScaledInstance(r.width, r.height - TOP_MARGIN,
                                     WholeImage.SCALE_DEFAULT);
              trackset.addImage(ResizedImage, 2);
              PaintScreen = 5;
              repaint();
              try {
              Thread.sleep(100);
              } catch (InterruptedException e) {
              try {
              trackset.waitForID(2);
              } catch (InterruptedException e) {
              Error("Loading Interrupted!");
              WholeImage = ResizedImage;
            // Complete loading image.  Start background loading other things
            // Also put image into the Graphics class
            // Split up main image into smaller images
            PaintScreen = 1;
            repaint();
            try {
               Thread.sleep(100);
            } catch (InterruptedException e){}
            piecewidth = WholeImage.getWidth(this) / piecesx;
            pieceheight = WholeImage.getHeight(this) / piecesy;
            System.out.println("Image has loaded.  X=" +
                               WholeImage.getWidth(this) + " Y=" +
                               WholeImage.getHeight(this));
            imageset = new Image[totalpieces];
            for (i = 0; i < totalpieces; i++)
                 filter = new CropImageFilter(GetPieceX(i) * piecewidth,
                                              GetPieceY(i) * pieceheight,
                                              piecewidth, pieceheight);
                 imageset[i] = createImage(new
                                           FilteredImageSource(WholeImage.getSource(),
                                                               filter));
            // Set up the mouse listener
            System.out.println("Adding mouse listener.");
            addMouseListener(this);
            // Complete mixing the image parts
            System.out.println("Displaying puzzle.");
            PaintScreen = -1;
            repaint();
            while (end != null)
              try {
                 Thread.sleep(100);
              } catch (InterruptedException e){}
         }Any help to where im going wrong would be much appreciated. Thanks!

    ive seen this one many times and it dosent work for me! Shouldnt the second parameter of the getImage(...) method not include the 'http://..." part as that what getDocumentBase() is for, returning the URL of the page the applet is embedded in? I have tried using code like this and event getting a printout of the doc/code base into the console to make sure my images are in the right place (.gif images), and nothing's happening, null pointer every time!
    {code}
    Image image;
    public void init() {
    // Load image
    image = getImage(getDocumentBase(), "http://hostname/image.gif");
    public void paint(Graphics g) {
    // Draw image
    g.drawImage(image, 0, 0, this);
    {code}
    ps this code is from the site mentioned above
    Edited by: Sir_Dori on Dec 8, 2008 8:37 AM

  • Loading j2me images

    Hi all,
    I have a web service through which i am sending a image to j2me mobile device to display on it. when i try to load the image the image doesn't display correctly.
    Please guide me on how do i load the images like jpg, gif, and png images to j2me
    Also i am receiving j2me images are in byte array form the webservice
    Abdul Khaliq

    u can try this code
    <code>
    HttpConnection c = null;
    DataInputStream is = null;
    DataOutputStream os = null;
    try
    String downloadURL = "http://a.com/a.png";
    System.out.println("download url is "+downloadURL);
    c = (HttpConnection) Connector.open(downloadURL);
    c.setRequestMethod(HttpConnection.GET);
    int resCode = c.getResponseCode(); //this will open connection and send request
    is = new DataInputStream(c.openInputStream());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    os = new DataOutputStream(baos);
    int i=0,v;
    byte []data = new byte[2048];
    while ((v = is.read(data)) >0 && downloading)
    i += v;
    os.write(data,0,v);
    os.flush();
    is.close();
    os.close();
    baos.close();
    c.close();
    byte []pngData = baos.toByteArray();
    Image image = Image.createImage(pngData, 0, pngData.length);
    try{
    midlet.imageForm.deleteAll();/// image form is a simple form
    }catch(Exception e){}
    midlet.imageForm.append(image);
    midlet.getDisplay().setCurrent(midlet.imageForm);
    }catch(Exception ex)
    </code>

  • Loading an image

    I have a problem with my code loading a file. I got some code for loading an image on the internet. the code compiles but when I add the module to my main (GraphicEvaluator.java) I get an error. below is the code and how I call the module plus the error that I encounter.
    Please help me to figure this out so that it can work.
    import java.applet.Applet;
    import java.awt.Image;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.io.*;
      public class LoadImage {
          // (example) call routine with something like..
          // Image image = getImageFromJar("images/test.jpg");
         public Image getImageFromJar(String path) {
              //public Image loadimage(String path){
              InputStream is = getClass().getResourceAsStream(path);
              ByteArrayOutputStream baos = new ByteArrayOutputStream();
              ImageIcon icon = null;
              try {
                  byte buf[] = new byte[8192];
                  int len;
                  while ((len = is.read(buf)) > 0) {
                      baos.write(buf, 0, len);
                  is.close();
                  try {
                      Image image = Toolkit.getDefaultToolkit().createImage(baos.toByteArray());
                      return image;
                  } catch (Exception decode) {
                      System.err.println(decode);
                  } catch(IOException ioexception) {
                      System.err.println(ioexception);
              return null;
      }calling the code
    public void actionPerformed (ActionEvent event)
            // Determine which object was the source of the event.
            Object source = event.getSource ();
    if (source == menuOpen)
                   LoadImage loadimage = new LoadImage();
                try
                    Image bg;
                    bg = LoadImage.getImageFromJar("frame.jpg");
                catch(Exception e) {}
            }the error
    G:\workingprog2\GraphicEvaluator.java:278: non-static method getImageFromJar(java.lang.String) cannot be referenced from a static context
                    bg = LoadImage.getImageFromJar("frame.jpg");
                                  ^
    1 error
    Tool completed with exit code 1

    non-static method getImageFromJar(java.lang.String) cannot be referenced from a static contextSo make the method static.
    However, I still don't understand what you are doing using this code. I've mentioned the ImageIO class to you before.
    Even if you ignore that advice I still don't understand why you are playing around with ByteArrayOutputStreams. If you actually look at the Toolkit API you will see a method the takes the filename as a string.

  • Loading an image in from a file

    Hi,
    I am trying to load an image in from a file, I have found an example using the following code:
    import java.awt.Image;
    import java.awt.Toolkit;
    import java.io.BufferedInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    public final class MainClass {
      private MainClass() {
      public static Image getImage(Class relativeClass, String filename) {
        Image returnValue = null;
        InputStream is = relativeClass.getResourceAsStream(filename);
        if (is != null) {
          BufferedInputStream bis = new BufferedInputStream(is);
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          try {
            int ch;
            while ((ch = bis.read()) != -1) {
              baos.write(ch);
            returnValue = Toolkit.getDefaultToolkit().createImage(
                baos.toByteArray());
          } catch (IOException exception) {
            System.err.println("Error loading: " + filename);
        return returnValue;
    }Is this a good way of doing it? I want to load a series of images in from files, so I can later do a comparison against them. I am just wondering how to go about the whole process?
    Many thanks, Ron

    Can you store multiple images in memory and be able
    to reference them all individually, or is it better
    to store them in a construct, such as an array and
    then loop through that when attempting to match?I'm sorry but I don't understand the question. And does it
    have anything to do with images per se? Can it be generalized
    without losing its meaning:
    Can you store multiple objects in memory and be able
    to reference them all individually, or is it better
    to store them in a construct, such as an array and
    then loop through that when attempting to match?It seems to me that multiple objects should be stored in
    an appropriate collection, if that is what is required.
    Perhaps you need to say more about what you are trying to
    do, what your goal is, to make your question meaningful.

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

  • Applet loading of images -- network or JAR approach faster?

    hi all,
    i'm stumped. my applet used to load images over the network. (it was actually designed by someone else.) yes, the applet used to load each image file independently over the network and incurred a network hit per image file.
    to avoid the overhead of a separate network connection for each image file, i bundled all the images into the same JAR file that contains the applet. yet, the loading time for the applet is somehow slower now. i'm totally mystified.
    i put the code for loading each image into a separate thread as well. here's the thread code:
    BEGIN CODE
    public class ImageLoaderThread extends Thread {
         private Hashtable images;
         private DesignApplet applet;
         public ImageLoaderThread(DesignApplet applet, Hashtable images, String imageFile) {
              super(imageFile);
              this.images = images;
              this.applet = applet;
         public void run() {
              try {
                   System.out.println("Starting to load image ...");
                   String imageFile = getName();
                   InputStream is = applet.getClass().getResourceAsStream(imageFile);
                   int arraySize = is.available() * 2; // CH: create extra space just in case
                   System.out.println("Image Loader Thread: " + imageFile + "bytes available: " + arraySize);
                   BufferedInputStream bis = new BufferedInputStream(is);
                   byte[] byBuf = new byte[arraySize]; // a buffer large enough for our image
                   int byteRead = bis.read(byBuf, 0, arraySize);
                   Image buttonImage = Toolkit.getDefaultToolkit().createImage(byBuf);
                   images.put(imageFile, buttonImage);
              catch(Exception e) {
                   System.out.println("Exception while loading: " + getName());
                   e.printStackTrace();
    END CODE
    imageFile is the name of an image file stored in the JAR file. it's not stored on the server anywhere, so i know the image is getting created from the JAR file. despite this, the speed of image creation seems tied to the network. in other words, when i attempt to load the applet over a slow link, it takes longer to load than over a fast link.
    any ideas what i'm doing wrong? i'm seriously stumped and could use help. my goals are to minimize loading time of the applet while minimizing network hits for the server.
    thanks!
    p.s. if you want to play w/ the applet, click on the following link and click the "Customize" button: http://www.cengraving.com/s/z/Photo-plaques/PP024.jsp

    Why are you using a thread to load each image why not just load the images in the gui thread?
    Each thread you create takes a finite time to be started and stopped. This will surely have added to the load and startup time.
    There is also blocking going on since using the Java Console I can see that each thread reports in sequence:
    "Starting to load image ..."
    And then after all threads have reported they are starting they then report in squence:
    Image Loader Thread: " + imageFile + "bytes available: " + arraySize information.
    This shows that there is at least some blocking going on with the threads.
    I don't think using separate threads to do the loading is helping at all. Just load them one after another in the same thread (the thread all your threads are being started from).
    The putting of the images into the images Hashtable will also be blocking since Hashtable is synchronized.

  • Error While loading a image from database

    Purpose
    Error While loading the Image from the database
    ORA-06502: PL/SQL : numeric or value error:Character string buffer too small
    ORA-06512: at "Sys.HTP" ,line 1480
    Requirement:
    I am developing the web pages using PSP(Pl/sql Serverpages) . I have a requirement to show a image in the webpage. I got the following procedures from the oracle website.
    I have created the following table to store the images
    create table DEMO
    ID INTEGER not null,
    THEBLOB BLOB
    And I also uploaded the Images. Now I am try to get a image from the table using the following procedure .But I am getting the error message line 25( htp.prn( utl_raw.cast_to_varchar2( l_raw ) );) .at it throws the following error messages
    ORA-06502: PL/SQL : numeric or value error:Character string buffer too small
    ORA-06512: at "Sys.HTP" ,line 1480
    Procedure that I used to get the image
    create or replace package body image_get
    as
    procedure gif( p_id in demo.id%type )
    is
    l_lob blob;
    l_amt number default 30;
    l_off number default 1;
    l_raw raw(4096);
    begin
    select theBlob into l_lob
    from demo
    where id = p_id;
    -- make sure to change this for your type!
    owa_util.mime_header( 'image/gif' );
    begin
    loop
    dbms_lob.read( l_lob, l_amt, l_off, l_raw );
    -- it is vital to use htp.PRN to avoid
    -- spurious line feeds getting added to your
    -- document
    htp.prn( utl_raw.cast_to_varchar2( l_raw ) );
    l_off := l_off+l_amt;
    l_amt := 4096;
    end loop;
    exception
    when no_data_found then
    NULL;
    end;
    end;
    end;
    What I have to do to correct this problem. This demo procedure and table that I am downloaded from oracle. Some where I made a mistake. any help??
    Thanks,
    Nats

    Hi Satish,
    I have set the raw value as 3600 but still its gives the same error only. When I debug the procedure its throwing the error stack in
    SYS.htp.prn procedure of the following line of code
    if (rows_in < pack_after) then
    while ((len - loc) >= HTBUF_LEN)
    loop
    rows_in := rows_in + 1;
    htbuf(rows_in) := substr(cbuf, loc + 1, HTBUF_LEN);
    loc := loc + HTBUF_LEN;
    end loop;
    if (loc < len)
    then
    rows_in := rows_in + 1;
    htbuf(rows_in) := substr(cbuf, loc + 1);
    end if;
    return;
    end if;
    Its a system procedure. I don't no how to proceed .. I am really stucked on this....is their any other method to take picture from the database and displayed in the web page.....???? any idea..../suggesstion??
    Thanks for your help!!!.

  • How do I run a simple script that loads an image into photoshop CS - CS4?

    Hello,
    I am at a loss on how to get my simple application to work. I have a small desktop air application that simply opens Photoshop and runs an action. I used switchboard and the application ran great on PC and MAC. However it only worked for CS3, and CS4 not CS or CS2?. Plus the size of switchboard was a bit large for my small app. I am willing to live with that though . I am using Air with Flex and wanted to know if perhaps there is a beter approach? All the application does is open photoshop, loads an image, and runs an action. Can I do this for all versions of Photoshop using switchboard? Can I do this without switchboard and just use javascript. The big issue is the Air app needs to open Photoshop, and most of the examples have me open PS first and then execute a script located in the PS directory. This needs to work outside of the PS directory. Any examples are appreciated.
    I have looked at the following:
    - SwitchBoard : only works for CS3-CS4 (on my tests)
    - PatchPanel: same issue, plus seperate SDKs
    - ExtendScript: requires script to be run from PS not Air

    Hello,
    I am at a loss on how to get my simple application to work. I have a small desktop air application that simply opens Photoshop and runs an action. I used switchboard and the application ran great on PC and MAC. However it only worked for CS3, and CS4 not CS or CS2?. Plus the size of switchboard was a bit large for my small app. I am willing to live with that though . I am using Air with Flex and wanted to know if perhaps there is a beter approach? All the application does is open photoshop, loads an image, and runs an action. Can I do this for all versions of Photoshop using switchboard? Can I do this without switchboard and just use javascript. The big issue is the Air app needs to open Photoshop, and most of the examples have me open PS first and then execute a script located in the PS directory. This needs to work outside of the PS directory. Any examples are appreciated.
    I have looked at the following:
    - SwitchBoard : only works for CS3-CS4 (on my tests)
    - PatchPanel: same issue, plus seperate SDKs
    - ExtendScript: requires script to be run from PS not Air

  • Using ImageIcon load an image

    Hi I'm having a lot of trouble getting the below code to work. Its copied out of my textbook and its supposed to load an image using the getImage method in the ImageIcon class. The strange thing is I have gotten this to work before, but after I installed Windows 2000 the image doesn't seem to load right anymore.
    getWidth and getHeight - on the image afterwards returns -1.
    Could this be windows 2000's problem? I'm pretty sure it isn't .. but when you run out of ideas, it feels good to put the blame on something other than yourself.
    import java.awt.*;
    import javax.swing.*;
    import java.net.*;
    public class DisplayImage extends JApplet
    public void init()
    ImageIcon icon = null;
    try
    icon = new ImageIcon(new URL(getCodeBase(), "Images/backTile.bmp"));
    catch(MalformedURLException e)
    System.out.println("Failed to create URL:\n"+e);
    return;
    int imageWidth = icon.getIconWidth();
    int imageHeight = icon.getIconHeight();
    resize(imageWidth, imageHeight);
    ImagePanel imagePanel = new ImagePanel(icon.getImage());
    getContentPane().add(imagePanel);
    class ImagePanel extends JPanel
    public ImagePanel(Image image)
    this.image = image;
    public void paint(Graphics g)
    g.drawImage(image,0,0,this);
    Image image;
    Again thx a lot. I know its a lot of code to read. Any help at all would be much appreciated.

    ".bmp" ? Windows bitmap isn't a supported file type, you should save your image as .gif, .png, or as .jpg.

  • Unable to Load the images Required by Classroom in a Book

    Just purchased Adobe Photoshop Elements 12.  I am trying the follow the lessons in the above book.  When I create the files and download the images, I am unable the import the files and images into the Photoshop Organizer.  Some images will import but most just display a weird icon.  I have reloaded, updated Windows, Photoshop, display drivers, you name it.  Nothing works.
    Using Windows 7 with 8 GBs of 64 bit memory.
    I like the book, and feel it will be a great introduction to Photoshop.  But if I can't load the images into the Photoshop 12 Organizer. I can't follow or use the book
    Lou (tobytussah)

    Lou again.
    As a follow up.  I am also unable to reliability load any Images into the Organizer either by using the Organizer File find functions or totally unable to move images into the Organizer using the Windows Explorer.
    Should the ask for help better belong in some other forum?
    Lolu

  • Unable to load TIF images into Photoshop.

    CS4 (11.0.2) and Windows 7 Home Edition.
    Have developed a problem trying to load some TIF images into Photoshop. I have a large number of images archived over a decade or more. At this point it may some of the older files that exhibit the problem. Now all these files were edited and stored using the Photoshop versions during the complete time period. The files are always saved with no compression. Have tried to load from Photoshop and clicking on the file in a file list. Photoshop just hangs and I get the message Program not responding. I can take these same files and load them into the ROXIO photo editor with no problem. Stranger yet is if I simply load the file into the ROXIO editor then "save as" back into the same folder (overwrite) the file can then be brought into Photoshop with no problem! Any ideas?

    Noel,
    Will try to keep short.
    I reinstalled Photoshop CS4 from the cd CS set. Did not uninstall first. Restarted PC and Photoshop. Still failed the same way with a 3001 image.
    Did the following, changing one item in the Edit->Preference->GPU Setting. After each change, closed Photoshop, reopened, brought in 3001 image, restored original setting. 3001 failed each time.
    * Unchecked Enable OpenGL Drawing
    * Advanced setup: Unchecked Advanced Drawing.
    * Advanced setup: Unchecked Color Matching
    Next went to the Edit->Color Profile.
    Scanned thru options and saw in the Convert Options: Engine. It was set to Adobe (ACE). ACE was the module name in the error detail!
    Only other option for this is Microsoft ICM. Changed to that, close/open Photoshop and 3001 came in no problem. So did the Nikon 3000, srgb IEC 61922 2.1 and Untagged. However, when briging in an Adobe RGB(1998) image Photoshop notes Profile Mismatch. It allows me to decide what to do (use embedded profile instead of workspace; convert color to work space color; discard embedded profile. and I choose use the convert color and it loads ok. At least it loads the image! Will use this approach for now. I need to get educated on color profiles!!
    Joe

  • Dynamic load of images in to established Timeline effect

    Is it possible to dynamicly load images in to an already
    established timeline effect?
    Steps I've done.
    Stuffed a JPG in to the library by draging and dropping it in
    to the SWFs library.
    Dropped the JPG on to the main stage
    Right clicked the image then going down to Timeline effects
    and choosing an effect.
    Completing any changes in effects dialogue box and then
    clicking OK.
    Play the movie, and pat myself on the back that it worked.
    So then, how can I get Actionscript to load an image
    dynamically in to that same Timeline effect and have it do the
    effect to that instead of the one found in the library?
    I'm using Flash MX Professional 2004.

    hii
    Can u mention the error message getting while the status become RED??
    As what I understand, this may be the issue of invalid characteristics inPSA Data Records or also there may be records that does not support the lower case or upper case data.
    So just check the data in PSA Level
    Thanks
    Neha

  • Problem in Loading Multiple image in Single Sprite/MovieClip

    Hi All,
    I am having a killing problem in loading multiple images in single movie clip/sprite using a separate class.
    Here is the ImageLoader.as class
    package com.project.utils{
        import com.project.*;
        import com.project.utils.*;
        import flash.events.EventDispatcher;
        import flash.display.MovieClip;
        import flash.events.Event;
        import flash.events.ProgressEvent;
        import flash.display.Loader;
        import flash.events.IOErrorEvent;
        import flash.net.URLLoader;
        import flash.events.MouseEvent;
        import flash.net.URLRequest;
        import flash.display.Bitmap;
        public class ImageLoader extends EventDispatcher {
            public var imgloader:Loader;
            public var imgMc:MovieClip;
            public var imgObject:Object;
            public var loaded:Number;
            public function ImageLoader():void {
                imgMc = new MovieClip();
                imgObject = new Object();
                imgloader = new Loader();
            public function loadImage(imgHolder:MovieClip, imgObj:Object):void {
                imgMc = new MovieClip();
                imgObject = new Object();
                imgloader = new Loader();
                imgMc = imgHolder;
                imgObject = imgObj;
                imgloader.contentLoaderInfo.addEventListener(Event.COMPLETE,onImgLoad);
                imgloader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onImgLoadProgress);
                imgloader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,onImageLoadFailed);
                imgloader.load(new URLRequest(imgObj.FilePath));
            private function onImgLoad(Evt:Event):void {
                var image:Bitmap = Bitmap(Evt.target.content);
                try {
                    imgMc.removeChildAt(0);
                } catch (error:Error) {
                imgMc.addChild(image);
                try {
                    if (imgObject.URL != undefined) {
                        imgMc.buttonMode = true;
                        imgMc.removeEventListener(MouseEvent.CLICK, onImageClicked);
                        imgMc.addEventListener(MouseEvent.CLICK, onImageClicked);
                } catch (err:Error) {
                dispatchEvent(new CustomEvent("CustomEvent.ON_IMGE_LOAD"));
            private function onImageClicked(evt:MouseEvent):void {
                trace("Image Attrs:"+imgObject.URL +" Target "+imgObject.Target);
            private function onImgLoadProgress(Evt:ProgressEvent):void {
                if (Evt.bytesLoaded>0) {
                    loaded = Math.floor((Evt.bytesLoaded*100)/Evt.bytesTotal);
                    dispatchEvent(new CustomEvent("CustomEvent.ON_IMGE_LOAD_PROC",loaded));
            private function onImageLoadFailed(Evt:IOErrorEvent):void {
                trace("Image Loading Failed");
                dispatchEvent(new CustomEvent("CustomEvent.ON_IMGE_LOAD_FAIL"));
    Here I am loading some images using the above class in a for loop, like
                for (var i=0; i < 3; i++) {
                    //imgLoader=new ImageLoader;
                    imgLoader.addEventListener("CustomEvent.ON_IMGE_LOAD",onImageLoad);
                    var target:MovieClip=videolist_mc["list" + mcCount + "_mc"];
                    target.list_mc.visible=false;
                    var imgObj:Object=new Object;
                    imgObj.FilePath=list[i].Thumbnail;
                    imgObj.Url=list[i].Url;
                    imgObj.Target=list[i].Target;
                    target.list_mc.urlObj=new Object  ;
                    target.list_mc.urlObj=imgObj;
                    imgLoader.loadImage(target.list_mc.imgholder_mc,imgObj);
                    target.list_mc.lable_txt.htmlText="<b>" + list[i].Label + "</b>";
                    target.list_mc.imgholder_mc.buttonMode=true;
                    target.list_mc.imgholder_mc.addEventListener(MouseEvent.CLICK,onItemPressed);
                    mcCount++;
    In this case, the ImageLoader.as works only on the last movie clip from the for loop. For example, if i am trying to load three image in three movie clips namely img_mc1,img_mc2 and img_mc3 using the for loop and ImageLoader.as, I am getting the image loaded in the third movie clip only img_mc.
    See at the same time, If i uncomment onething in the for loop that is
    //imgLoader=new ImageLoader;         
    its working like a charm. But I know creating class objects in a for loop is not a good idea and also its causes some other problems in my application.
    So, help to get rid out of this problem.
    Thanks
    -Varun

    package com.project.utils{
        import com.project.*;
        import com.project.utils.*;
        import flash.events.EventDispatcher;
        import flash.display.MovieClip;
        import flash.events.Event;
        import flash.events.ProgressEvent;
        import flash.display.Loader;
        import flash.events.IOErrorEvent;
        import flash.net.URLLoader;
        import flash.events.MouseEvent;
        import flash.net.URLRequest;
        import flash.display.Bitmap;
        public class ImageLoader extends EventDispatcher {
            public var imgloader:Loader;
            public var imgMc:MovieClip;
            public var imgObject:Object;
            public var loaded:Number;
            public function ImageLoader():void {
    // better add you movieclip to the stage if you want to view anything added to it.
                imgMc = new MovieClip();
                imgObject = new Object();
                imgloader = new Loader();
            public function loadImage(filepath:String):void {
                imgloader.contentLoaderInfo.addEventListener(Event.COMPLETE,onImgLoad);
                imgloader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onImgLoadPr ogress);
                imgloader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,onImageLoadF ailed);
                imgloader.load(new URLRequest(filepath));
            private function onImgLoad(Evt:Event):void {
                var image:Bitmap = Bitmap(Evt.target.content);
                try {
                    imgMc.removeChildAt(0);
                } catch (error:Error) {
                imgMc.addChild(image);
                try {
                    if (imgObject.URL != undefined) {
                        imgMc.buttonMode = true;
                        imgMc.removeEventListener(MouseEvent.CLICK, onImageClicked);
                        imgMc.addEventListener(MouseEvent.CLICK, onImageClicked);
                } catch (err:Error) {
                dispatchEvent(new CustomEvent("CustomEvent.ON_IMGE_LOAD"));
            private function onImageClicked(evt:MouseEvent):void {
                trace("Image Attrs:"+imgObject.URL +" Target "+imgObject.Target);
            private function onImgLoadProgress(Evt:ProgressEvent):void {
                if (Evt.bytesLoaded>0) {
                    loaded = Math.floor((Evt.bytesLoaded*100)/Evt.bytesTotal);
                    dispatchEvent(new CustomEvent("CustomEvent.ON_IMGE_LOAD_PROC",loaded));
            private function onImageLoadFailed(Evt:IOErrorEvent):void {
                trace("Image Loading Failed");
                dispatchEvent(new CustomEvent("CustomEvent.ON_IMGE_LOAD_FAIL"));
    Here I am loading some images using the above class in a for loop, like
                for (var i=0; i < 3; i++) {
                    var imgLoader:ImageLoader=new ImageLoader();
                    imgLoader.addEventListener("CustomEvent.ON_IMGE_LOAD",onImageLoad);
                    var target:MovieClip=videolist_mc["list" + mcCount + "_mc"];
                    target.list_mc.visible=false;
                    var imgObj:Object=new Object;
                    imgObj.FilePath=list[i].Thumbnail;
                    imgObj.Url=list[i].Url;
                    imgObj.Target=list[i].Target;
                    target.list_mc.urlObj=new Object  ;
                    target.list_mc.urlObj=imgObj;
                    imgLoader.loadImage(pass the image file's path/name);
                    target.list_mc.lable_txt.htmlText="<b>" + list[i].Label + "</b>";
                    target.list_mc.imgholder_mc.buttonMode=true;
                    target.list_mc.imgholder_mc.addEventListener(MouseEvent.CLICK,onItemPressed);
                    mcCount++;

Maybe you are looking for

  • Is there any way to find an ipod touch with out the "Find my Ipod" App?

    Could I have some one else track it down like some one from a apple store?

  • Upgrade Win XP Bootcamp partition to Win7?

    I read the docs that says you cannot upgrade XP directly to Win 7 as it requires a 'clean install' from an external CD. I have someone on ebay who purports to be selling me an upgrade CD that will do this "The Win7 upgrade I'm selling will allow you

  • Synchronous read file and status update

    Hi, CSV file to be loaded into the database table. ASP used as front end and ESB should be used for backend processing! A csv file is placed in a fileshare by an asp page. After that a button is clicked on the asp page which inserts a record into a d

  • Change visibility of table in interactive form through scripting

    Hi all, I am designing an interactive form in wd java. I used a table to display records in the interactive form.I want to make the table invisible if there is no data in the node. The table is wrapped in a subform . What scripting I need to do to ma

  • Gallery for pics & movies?

    This m,ight be off topic for this discussion, but I wasn't sure where else to ask. Feel free to point me to a different discussion group if you know of a more appropriate one. I am looking for a gallery application for web creation that will accept b