Array to bufferedimage

why doesn't this work?
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.awt.image.*;
public class Firew extends Applet {
public BufferedImage img2 = new BufferedImage (320,240,BufferedImage.TYPE_BYTE_INDEXED);
public byte[] scratch2 = new byte[80000];
public Firew() {
public void init() {
for (int i=38500; i<38620; i++)
scratch2=12;
System.arraycopy(scratch2,0,img2,0,40000);
repaint();
public void start() {
public void paint(Graphics g) {
g.drawImage(img2,0,0,null);

Also array copy is used for Arrays hence the name.
You're trying to copy an array to an Image.
Use MemoryImageSource.

Similar Messages

  • BufferedImage array into JScrollPane

    Hi, i want to put an array of bufferedimage into a JScrollPane, the problem is that i want that the shown images are selectable therefore i want to put them into a JCheckBox.
    Is possible? Someone can advise me? Do you have some idea?
    Thanks

    I think you should put a Panel in JScrollPane and and draw the images with JCheckBox on your panel. I did a something very similar in the past, If you want, I can send you the snap shot.

  • Converting Image to Byte Array and then to String

    Hi All...
    Can anyone please help me. I have got a problem while converting a Byte array of BufferedImage to String.
    This is my code, First i convert a BufferedImage to a byte array using ImageIO.wirte
    public String dirName="C:\\image";
    ByteArrayOutputStream baos=new ByteArrayOutputStream(1000);
    BufferedImage img=ImageIO.read(new File(dirName,"red.jpg"));
    ImageIO.write(img, "jpg", baos);
    baos.flush();
    byte[] resultimage=baos.toByteArray();
    baos.close();
    Then i tried to convert this byte array to a string
    String str=new String(resultimage);
    byte[] b=str.getBytes();
    This much worked fine. But when i reversed this process to re-create the image from that string. i found the image distroted.
    BufferedImage imag=ImageIO.read(new ByteArrayInputStream(b));
    ImageIO.write(imag, "jpg", new File(dirName,"snap.jpg"));
    I got this snap.jpg as distroted.
    Please help me i have to convert the image to a string and again i have to re-create the image from that string.

    To conver the bytearray to string use base64.encoding
    String base64String= Base64.encode(baos.toByteArray());
    To convert back use Base64.decode;
    byte[] bytearray = Base64.decode(base64String);
    BufferedImage imag=ImageIO.read(bytearray);

  • Animated GIF image gets distorted while playing.

    Hi,
    I have some animated gif images which I need to show in a jLabel and a jTextPane. But some of these images are getting distorted while playing in the two components, though these images are playing properly in Internet Explorer. I am using the methods insertIcon() of jTextPane and setIcon() of jLabel to add or set the gif images in the two components. Can you please suggest any suitable idea of how I can get rid of this distortion? Thanks in advance.

    In the code below is a self contained JComponent that paints a series of BufferedImages as an animation. You can pause the animation, and you specify the delay. It also has two static methods for loading all the frames from a File or a URL.
    Feel free to add functionality to it, like the ability to display text or manipulate the animation. You may wan't the class to extend JLabel instead of JComponent. Just explore around with the painting. If you have any questions, then feel free to post.
    The downside to working with an array of BufferedImages, though, is that they consume more memory then a single Toolkit gif image.
    import javax.swing.JComponent;
    import java.awt.image.BufferedImage;
    import java.awt.Graphics;
    import javax.imageio.ImageIO;
    import javax.imageio.ImageReader;
    import javax.imageio.stream.ImageInputStream;
    public class JAnimationLabel extends JComponent {
        /**The default animation delay.  100 milliseconds*/
        public static final int DEFAULT_DELAY = 100;
        private BufferedImage[] images;
        private int currentIndex;
        private int delay;
        private boolean paused;
        private boolean exited;
        private final Object lock = new Object();
        //the maximum image width and height in the image array
        private int maxWidth;
        private int maxHeight;
        public JAnimationLabel(BufferedImage[] animation) {
            if(animation == null)
                throw new NullPointerException("null animation!");
            for(BufferedImage frame : animation)
                if(frame == null)
                    throw new NullPointerException("null frame in animation!");
            images = animation;
            delay = DEFAULT_DELAY;
            paused = false;
            for(BufferedImage frame : animation) {
                maxWidth = Math.max(maxWidth,frame.getWidth());
                maxHeight = Math.max(maxHeight,frame.getHeight());
            setPreferredSize(new java.awt.Dimension(maxWidth,maxHeight));
        //This method is called when a component is connected to a native
        //resource.  It is an indication that we can now start painting.
        public void addNotify() {
            super.addNotify();
            //Make anonymous thread run animation loop.  Alternative
            //would be to make the AnimationLabel class extend Runnable,
            //but this would allow innapropriate use.
            exited = false;
            Thread runner = new Thread(new Runnable() {
                public void run() {
                    runAnimation();
            runner.setDaemon(true);
            runner.start();
        public void removeNotify() {
            exited = true;
            super.removeNotify();
        /**Returns the animation delay in milliseconds.*/
        public int getDelay() {return delay;}
        /**Sets the animation delay between two
         * consecutive frames in milliseconds.*/
        public void setDelay(int delay) {this.delay = delay;}
        /**Returns whether the animation is currently paused.*/
        public boolean isPaused() {
            return exited?true:paused;}
        /**Makes the animation paused or resumes the painting.*/
        public void setPaused(boolean paused) {
            synchronized(lock) {
                this.paused = paused;
                lock.notify();
        private void runAnimation() {
            while(!exited) {
                repaint();
                if(delay > 0) {
                    try{Thread.sleep(delay);}
                    catch(InterruptedException e) {
                        System.err.println("Animation Sleep interupted");
                synchronized(lock) {
                    while(paused) {
                        try{lock.wait();}
                        catch(InterruptedException e) {}
        public void paintComponent(Graphics g) {
            if(g == null) return;
            java.awt.Rectangle bounds = g.getClipBounds();
            //center image on label
            int x = (getWidth()-maxWidth)/2;
            int y = (getHeight()-maxHeight)/2;
            g.drawImage(images[currentIndex], x, y,this);
            if(bounds.x == 0 && bounds.y == 0 &&
               bounds.width == getWidth() && bounds.height == getHeight()) {
                 //increment frame for the next time around if the bounds on
                 //the graphics object represents a full repaint
                 currentIndex = (currentIndex+1)%images.length;
            }else {
                //if partial repaint then we do not need to
                //increment to the the next frame
    }

  • Problem in using LookupOp

    hi everybody....
    1. In my program i am using LookupOp to modify my images...such as invert or nullify a component....
    Before editing , i save the original image into an array of bufferedImage ( for Undo operation)...
    but after using LookupOp if i use undo...it dosen't work!!!.....Can someone suggest me what is the problem!!???
    2. When i use ImageIO.read to read an PNG file.....the type returned is Zero!!!
    How can i solve this problem???

    hi venkat,
    la_PLANTDATA-plant = '5530'.
    la_PLANTDATAX-plant = 'X'.
    in this for plantdatax plant is of component type WERKS_D
    with length 4 so u have to pass la_PLANTDATAX-plant = '5530'.
    it wil solve the problem.
    i hope this wil help to u
    thanks,
    dilip

  • Loading ImageView with in-memory bitmap

    I am new to JavaFX, and I have search all over the internet but I cannot find the answer.
    My Java code is creating an in-memory bitmap image and I would like to display it in JavaFX ImageView class (without saving it to a file). ImageView can load an image from a URL, but how do I do that from a member variable in a Java class?
    As an alternative, I tried to subclass SwingComponent (instead of using ImageView) and have the java.awt.Image member variable in this class. I can bind to this member variable, but now I am stuck, since I cannot get JavaFX to invoke my paintComponent repaint routine. If I could then I can use graphics drawImage in this routine.
    Also, Timeline, while it is cool, does not apply to my solution since the image is generated at various times based on system events.
    Which is the best approach?
    Any help would be appreciated.
    - Tosh

    Thank you for your answer. I also found it difficult to convert the int[] of the image to BufferedImage. I did manage to cobble together some code that does this, although, I think it is inefficient. Anyway, I am glad that I have some working code now. As an aid to others I am placing my routine to convert int array to BufferedImage. If anyone has a more efficient way, please add to this trail.
    BufferedImage bimg = null;
    public BufferedImage intArraytoImage(int[] buf, int w, int h) {
    int[] BM = new int[]{0xff0000, 0xff00, 0xff}; // I don't have alpha channel... {0xff0000, 0xff00, 0xff, 0xff000000};
    SinglePixelPackedSampleModel sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT, w, h, BM);
    DataBufferInt db = new DataBufferInt(buf, w * h, 0);
    Point p = new Point(0, 0);
    WritableRaster raster = null;
    try {
    raster = Raster.createWritableRaster(sm, db, p);
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
    int[] nBits = {24};
    ColorModel cm = new ComponentColorModel(cs, nBits, false, true, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
    bimg = new BufferedImage(w, h, 1); // 1 = TYPE_INT_RGB
    bimg.setData(raster);
    } catch (Exception e) {
    System.out.println("exception in creating BufferedImage");
         e.printStackTrace();
    return bimg;
    - Tosh
    fixed typo

  • Loading custom image formats

    Hello all.
    I am wanting to load a custom image format into my Java application, and am wondering how to do that. I have a few ideas to try but I figure if there is a site out there (or someone with the knowledge), there is no need for me to re-invent the wheel. So hopefully, someone might be able to expedite my learning. :)
    The image format I want to read actually contains multiple images, with 1 color palette at the end of the file. I'd like to create a series of (I assume) BufferedImages for all the images contained within the file.
    Are there any sites out there that can send me through a quick tutorial on rolling my own images, or can anyone give me a short function to do so?
    Thanks so much!

    Okay... I failed. I could really use some help in getting this work. Please.
    I have a file, which contains 1 or more compressed bitmap images and a palette. I have a small Perl script that will convert the images in the file into multiple bitmap image files, so I know where the data is and I know I have the data locations right. :)
    To create a BITMAP, I must reverse the order of the palette (perl function):
    sub reversePalette() {
      my $output = "";
      for (my $i=0; $i < length($_[0]); $i=$i+4) {
        $output = $output . substr($_[0], $i+2, 1) . substr($_[0], $i+1, 1) . substr($_[0], $i+0, 1) . chr(0);
      return $output;
    }For the image data itself, it uses a simple RLE encoding. If I see a 0, I check the next number and "uncompress" the data by adding that many 0's to the output file.
    So, what I would like to do is convert my Perl script into a Java class that will take this sprite file and return an array of BufferedImages, which can then be used for whatever.
    Any help in this would be greatly appreciated! I can't even figure out how to properly load a valid BMP file manually using WritableRaster and ColorModel. I'm so lost. :(

  • Multiple Images in JInternalFrames

    Hi,
    I'm trying to open n number of images in a desktop, each in its own JInternalFrame. I've set up an array of bufferedImages which store each required image. I have a class called MYJPanel which paints the image into an internal frame and have set up an array of instances of this class. It successfully opens images but when I go to open more than one, it creates a new internal window with this image as desired, but it also replaces the image in the first internal frame with this new image. I think its got something to with the paintComponent(Graphics g) but I'm not too sure. Here's a sample of the code below:
    public void OpenNewImage()
    openImageCount++;
    panels[openImageCount] = new MyJPanel();
    fileBrowser.setVisible(false);
    c[openImageCount] = new Container();
    frames[openImageCount] = new JInternalFrame("Image " + openImageCount, true, true, true,true);
    c[openImageCount] =frames[openImageCount].getContentPane();
    c[openImageCount].add(panels[openImageCount], BorderLayout.CENTER);
    frames[openImageCount].setOpaque(true);
    frames[openImageCount].setSize(300,200);
    frames[openImageCount].show();
    //To move the second image to the right hand side of the screen
    if (openImageCount == 2)
    frames[openImageCount].setLocation(350,0);
    theDesktop.add(frames[openImageCount]);
    class MyJPanel extends JPanel implements MouseListener, MouseMotionListener
    public MyJPanel()
    // Store chosen image into images array
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    images[openImageCount] =readInImage(filePath);
    public BufferedImage readInImage(String filename) {
                        BufferedImage bimage;
                        // Read in original image
                        Image im = Toolkit.getDefaultToolkit().getImage(filename);
                        try {
         MediaTracker tracker = new MediaTracker(new Component() {});
    tracker.addImage(im, 0);
    tracker.waitForID(0);
                             bimage = new BufferedImage(im.getWidth(null), im.getHeight(null), BufferedImage.TYPE_3BYTE_BGR);
                   Graphics2D big = bimage.createGraphics();
         big.drawImage(im,0,0,null);
                             return(bimage);
    catch ( Exception e ) {
                             System.out.println("Error Reading Image...Check Filename and Extension");
                             return(null);
    public void paintComponent(Graphics g)
    for (int i=1; i<=openImageCount; i++){
    g.drawImage(images,0,0,300,200,this);
    Does anyone know where I'm going wrong?
    Many thanks,
    CG.

    u have to do some custom painting in order to achieve this. override the paintComponent() method in your JButton subclass and write code to display the images in some sequence...
    cheers,
    ram

  • Low-level image drawing

    Hi All,
    I'm using a MemoryImageSource for animation, in the hope of speeding up refresh rates (I'm using quite an old machine). I can get the MemoryImageSource to render ok, and can draw lines/pixels, and animate them.
    The problem I'm having is drawing sprites onto the int[] of the MemoryImageSource. I can get the sprite into an integer array using:
    BufferedImage.getData().getPixels(0,0,60,60,pix[]);
    but when I try to update the pixels in the MIS array I'm calculating the offset correctly for each scan-line), all I get is a white rectangle the size and shape of the sprite.
    I'm trying to set the MIS array like this:
    for(int j=0;j<height;j++) {
    for(int i=0;i<width;i++) {
    MISPixel[MISWidth*j+i]=sprite[width*j+i];
    updateOffset();
    Anyone got any ideas? Thanks in advance.

    if you arn't doing per-pixel operations, you shouldn't be considering either of those solutions. For regular image drawing they will be far far slower.
    Use BufferStrategy and ManagedImages
    However, to answer your question, There are several solutions.
    You can use PixelGrabber (which is ugly and old),
    or you could copy your image into a BufferedImage of known pixel format, and use bufferedImage.getRaster().getDataBuffer().
    If you are using ImageIO to read in your images, then you already have a BufferedImage and there is no need to copy it into a new 1.(though the pixel format of the BufferedImage returned from ImageIO might not be what you want)

  • Re: Hardware Accelleration / Playing Video

    Yes, such image indeed will not be accelerated - because you have the pointer to the raw data.
    Here is an approach which I've suggested to other people with similar issues.
    Create a VolatileImage
    Copy your BufferedImage to this volatile image
    copy the volatile image to the back-buffer
    This approach especially helps if you need to copy the image to the backbuffer more often that it's updated by the video stream, or if you need to scale the frames (in the last case you'll need to use -Dsun.java2d.ddscale=true parameter if you're running on windows, or the opengl pipeline with -Dsun.java2d.opengl=true if your hardware/drivers is supported).
    Take a look at this thread on javagaming.org which discusses almost exactly the same case as yours:
    http://www.javagaming.org/forums/index.php?topic=12453.msg100335#msg100335
    Thank you,
    Dmitri
    Java2D Team

    Thank you very much dmitri, the thread you linked showed me just how to make it work. Now I can get 30fps with two videos at once.
    Previously, I was trying to build up a BufferedImage from a 24bit RGB array of pixels, which I don't think is compatible with most hardware acceleration. Now I get a pointer to a 32bit RGBA array, using:
    BufferedImage videoImage;
    GraphicsConfiguration gc = videoCanvas.getGraphicsConfiguration();
    videoImage = gc.createCompatibleImage(vidWidth, vidHeight);     
    pixelData = ((DataBufferInt) videoImage.getRaster().getDataBuffer()).getData();With minor changes to my C code I store the pixels in this buffer instead. This works much better, as the resulting BufferedImage is hardware accelerated. I then can render this BufferedImage straight to the screen, with scaling, very quickly.
    Rendering it first to a VolitileImage was causing problems for me, as performance would slow down for some reason if I changed the window's size at all while it was running.

  • Problems Using IOImage.Write

    Hi all cracks of image manipulation
    (I'm not sure where yto put this network 2D or image)
    I'm trying to transfer images through a network using RMI to store on a sever
    since Image can't directly be transfered I'm converting my picture to an array int[]
    ((BufferedImage) image).getRGB(0,0,image.getWidth(jc),image.getHeight(jc),temp,0,image.getWidth(jc)),on the other side I have
    image = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(rect.width, rect.height, is.getImageInPixel(), 0,rect.width));for the moment no problem
    I managed to transfer the picture and rebuilded on another client
    but the problem is when I want to save it on the server
    try {
                        int Imagewidth = requests.getChanges().getElement().getRect().width;
                        int Imageheight = requests.getChanges().getElement().getRect().height;
                        ImageIcon img = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(Imagewidth, Imageheight, ((ImageSendable)requests.getChanges().getElement()).getImageInPixel(), 0,Imagewidth));
                        ImageIO.write(
                                (RenderedImage)img
                                , "jpg"
                                , new File("/images_document/"+IDDocument+"_"+requests.getChanges().getElement().getID())
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }I get
    Exception in thread "Thread-2" java.lang.ClassCastException: sun.awt.image.ToolkitImage cannot be cast to java.awt.image.RenderedImage
        at XMLToStyledDocument.XMLDrawingDocument.requestDecompilerServer(XMLDrawingDocument.java:86)
        at serveur.FileHandler.MyDrawingFileHandlerThread.run(MyDrawingFileHandlerThread.java:46)I'm no crak in pictures and its not my research subject, but its a cool little feature that I would like to add before friday
    so if somebody could help me out
    when I use IOImage to save an Image no problem
    when I decopose and recompose my picture from Image to int[] no problem
    But when I combien both it fails...
    if somebody know a way to trafer though RMI and save on a server and be able to display this image (I use Graphics g => g.add(image)) it would help me a lot
    Edited by: anarkia on Sep 10, 2008 5:54 AM

    You can't do this: (RenderedImage)ImageIcon An image can't be transformed to a RenderedImage that way.
    try:
    try {
                        int Imagewidth = requests.getChanges().getElement().getRect().width;
                        int Imageheight = requests.getChanges().getElement().getRect().height;
                        Image img = (Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(Imagewidth, Imageheight, ((ImageSendable)requests.getChanges().getElement()).getImageInPixel(), 0,Imagewidth))).getImage();
                        ImageIO.write(
                                (RenderedImage)img
                                , "jpg"
                                , new File("/images_document/"+IDDocument+"_"+requests.getChanges().getElement().getID())
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

  • How to get a string or byte array representation of an Image/BufferedImage?

    I have a java.awt.Image object that I want to transfer to a server application (.NET) through a http post request.
    To do that I would like to encode the Image to jpeg format and convert it to a string or byte array to be able to send it in a way that the receiver application (.NET) could handle. So, I've tried to do like this.
    private void send(Image image) {
        int width = image.getWidth(null);
        int height = image.getHeight(null);
        try {
            BufferedImage buffImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
            ImageIcon imageIcon = new ImageIcon(image);
            ImageObserver observer = imageIcon.getImageObserver();
            buffImage.getGraphics().setColor(new Color(255, 255, 255));
            buffImage.getGraphics().fillRect(0, 0, width, height);
            buffImage.getGraphics().drawImage(imageIcon.getImage(), 0, 0, observer);
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            JPEGImageEncoder jpeg = JPEGCodec.createJPEGEncoder(stream);
            jpeg.encode(buffImage);
            URL url = new URL(/* my url... */);
            URLConnection connection = url.openConnection();
            String boundary = "--------" + Long.toHexString(System.currentTimeMillis());
            connection.setRequestProperty("method", "POST");
            connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
            String output = "--" + boundary + "\r\n"
                          + "Content-Disposition: form-data; name=\"myImage\"; filename=\"myFilename.jpg\"\r\n"
                          + "Content-Type: image/jpeg\r\n"
                          + "Content-Transfer-Encoding: base64\r\n\r\n"
                          + new String(stream.toByteArray())
                          + "\r\n--" + boundary + "--\r\n";
            connection.setDoOutput(true);
            connection.getOutputStream().write(output.getBytes());
            connection.connect();
        } catch {
    }This code works, but the image I get when I save it from the receiver application is distorted. The width and height is correct, but the content and colors are really weird. I tried to set different image types (first line inside the try-block), and this gave me different distorsions, but no image type gave me the correct image.
    Maybe I should say that I can display the original Image object on screen correctly.
    I also realized that the Image object is an instance of BufferedImage, so I thought I could skip the first six lines inside the try-block, but that doesn't help. This way I don't have to set the image type in the constructor, but the result still is color distorted.
    Any ideas on how to get from an Image/BufferedImage to a string or byte array representation of the image in jpeg format?

    Here you go:
      private static void send(BufferedImage image) throws Exception
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        ImageIO.write(image, "jpeg", byteArrayOutputStream);
        byte[] imageByteArray = byteArrayOutputStream.toByteArray();
        URL url = new URL("http://<host>:<port>");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setDoOutput(true);
        connection.setRequestMethod("POST");
        OutputStream outputStream = connection.getOutputStream();
        outputStream.write(imageByteArray, 0, imageByteArray.length);
        outputStream.close();
        connection.connect();
        // alternative to connect is to get & close the input stream
        // connection.getInputStream().close();
      }

  • Error when creating BufferedImage with IndexColorModel from a byte array.

    Hi, I have a 1-dimentional byte array and an IndexColorTable, and I can't figure out how to combine the 2 into an BufferedImage without unnecessary copying/reallocating of the image buffer.
    The color model I have is:
    int [] cmap = new int [numColors];
    cmap[i++] = 0xffa0f000;  /etc.
    new IndexColorModel(8, 22, cmap, 0, true,  transparentIndex,  DataBuffer.TYPE_BYTE );Thanks for your help
    -Ben
    Ps.
    I've was looking at some example code (http://javaalmanac.com/egs/java.awt.image/Mandelbrot2.html?l=rel), and can't figure out how to go from the color model they're using to the one I have (the 8 bit one specified above). When I replace the 4bit colormodel in the code below with the 8bit color model specified above, I get the following error:
    [java] java.lang.IllegalArgumentException: Raster ByteInterleavedRaster: width = 5120 height = 3520 #numDataElements 1 dataOff[0] = 0 is incompatible with ColorModel IndexColorModel: #pixelBits = 8 numComponents = 4 color space = java.awt.color.ICC_ColorSpace@c51355 transparency = 2 transIndex = 22 has alpha = true isAlphaPre = false
    [java] at java.awt.image.BufferedImage.<init>(BufferedImage.java:613)
    Code:
    byte[] pixelArray = (byte[]) getData_CHAR();                
    int width = 5120;
    int height = 3520;
    int numbytes = width*height;
    //create DataBuffer using byte buffer of pixel data.
    DataBuffer dataBuffer = new DataBufferByte(pixelArray, numbytes, 0);
    //prepare a sample model that specifies a storage 8-bits of pixel data in an 8-bit data element
    int bitMasks[] = new int[]{0xf};
    SinglePixelPackedSampleModel sampleModel = new SinglePixelPackedSampleModel(DataBuffer.TYPE_BYTE, width, height, bitMasks);
    //create a raster using the sample model and data buffer
    WritableRaster writableRaster = Raster.createWritableRaster(sampleModel, dataBuffer, new Point(0,0));
    //generate 16-color model
    byte[] r = new byte[16];
    byte[] g = new byte[16];
    byte[] b = new byte[16];
    r[0] = 0; g[0] = 0; b[0] = 0;
    r[1] = 0; g[1] = 0; b[1] = (byte)192;
    r[2] = 0; g[2] = 0; b[2] = (byte)255;
    r[3] = 0; g[3] = (byte)192; b[3] = 0;
    r[4] = 0; g[4] = (byte)255; b[4] = 0;
    r[5] = 0; g[5] = (byte)192; b[5] = (byte)192;
    r[6] = 0; g[6] = (byte)255; b[6] = (byte)255;
    r[7] = (byte)192; g[7] = 0; b[7] = 0;
    r[8] = (byte)255; g[8] = 0; b[8] = 0;
    r[9] = (byte)192; g[9] = 0; b[9] = (byte)192;
    r[10] = (byte)255; g[10] = 0; b[10] = (byte)255;
    r[11] = (byte)192; g[11] = (byte)192; b[11] = 0;
    r[12] = (byte)255; g[12] = (byte)255; b[12] = 0;
    r[13] = (byte)80; g[13] = (byte)80; b[13] = (byte)80;
    r[14] = (byte)192; g[14] = (byte)192; b[14] = (byte)192;
    r[15] = (byte)255; g[15] = (byte)255; b[15] = (byte)255;
    //create buffered image    
    ColorModel colorModel = new IndexColorModel(4, 16, r, g, b);
    BufferedImage image = new BufferedImage(colorModel, writableRaster, false, null);Message was edited by:
    ben_weisburd
    Message was edited by:
    ben_weisburd

    I had the same problem too.
    anyone found the solution for this problem?
    thanks
    Bruno Rabino
    When I try to make a MD-form, where the base-table for the detail contains a column with a BLOB-datatype. I get following error when I finish creation of the form.
    Error: Exception from wwv_generate_component.build_procedure (WWV-01821)
    Error creating module: ORA-01403: no data found (WWV-16042)
    When I use the table with the BLOB as master or in a form, it works fine.
    Has anyone else experienced this problem? Or knows a way to fix or work around it. Thanks in advance.
    Portal version: 3.0.6.6.5
    null

  • BufferedImage to RGB Array

    I realize there's an advanced imaging forum, but this doesn't seem like it should be an advanced topic. Plus this forum has more activity =)
    I have a 2000x1312 pixel JPG that I load into a BufferedImage. I want to have three arrays: R[2000][1312], G[2000][1312], B[2000][1312] that hold values from 0-255 corresponding to the image in RGB space. My program used to do this in about 4 seconds. I didn't change any code involving this process, but for some reason, it now takes 100+ seconds to run.
    The slow line of code is:
    pixels = originalImage.getRGB (0, 0, 2000, 1312, null, 0, 2000);
    pixels is an int[2000*1312], originalImage is a bufferedImage.
    I don't have the dimensions hardcoded like this on my end, but I think you get the idea.

    A BufferedImage is basically a ColorModel plus a WritableRaster.
    A WriteableRaster is a SampleModel plus a DataBuffer.
    DataBuffer is an abstract class with concrete implementations like DataBufferByte and DataBufferInt.
    These buffer classes store data in arrays of primitive component type.
    With that in mind, try this code:
    int[] accessData(BufferedImage bi) {
        WritableRaster r = bi.getRaster();
        DataBuffer db = r.getDataBuffer();
        if (db instanceof DataBufferInt) {
            DataBufferInt dbi = (DataBufferInt) db;
            return dbi.getData();
        } else {
            System.err.println("db is of type " + db.getClass());
            return null;
    }This code does no copying of pixel data, so it should be very fast.
    Your data may be in a byte[], so you may need to adjust this code.
    Also, examine the size of the array. There may be some padding
    involved and so it may be longer than WxH.

  • Displaying the value of an array in swing? Almost like a chess baord

    Hi all.
    After a long time from coding I thought I'd have a bash.
    Here's a short outline of what I'm trying code.
    I have a robot, a simple robot, does nothing but move around, pick up objects and drop them.
    This robot lives in a world that is a square 1000x1000 for example.
    The world is populated with objects, the robot goes around, if the robot is not holding an object and comes across one it will pick it up.
    Then the robot moves around and if it comes across another object of the same type it will then drop the object.
    These are the class names that I've created, the names give it away what they are for:
    RobotProject (main class, not much in here apart from the starting parameters, such as starting position, how big the world is, number of objects in the world etc)
    SandBox (is the class that the world object will be created from)
    Robot (is the class the robot will be created from, I did it this way just in case I wanted more then one robot in the world)
    GridCheck (this is a static class as it's only a set of instructions to carry out depending where in the world it the robot is and what is around it)
    Movement (this class is not built yet, but all it does is check the current location of the robot, give options of where to move, then randomly picks a move)
    Gui (this is going to be used to display the world, not built yet)
    The object I create of SandBox is called world1, the only thing need to be known about this world is that it has an array, this array is what keeps track of each of the grid in the world and there state.
    So let?s imagine a chess board, top left grid is 0 going from left to right/ top to bottom we end up with 63 (or 64 arrays).
    What would be the best way to display this "chess board"?
    At the moment I have a method in the SandBox class that will return all the grids states and a string.
    This was put in there "just in case" but I think this is the wrong way to go.
    Really what I'm after is a few pointers to make this work, maybe my way of doing this is incorrect?
    I know I've been thinking that maybe I should have created an array of objects (SandBox, but with only an int rather than the array) rather than an object with an array var.
    Anyways, I hope that makes sense, if not feel free to "bust my chops"
    If you would like to see some of the mode feel free to ask, I'm not a student or anything, to be frank the last time I coded anything was over 4 years ago, so as you can guess the code is simply.
    Jon.
    Thanks in advance.
    Edited by: jontelling on Jan 12, 2009 9:47 AM

    I agree with BDLH that Swing would work well here. There are a million and one way to create your "grid" one option include using a 2D grid of JLabels, another being a single JPanel with a grid BufferedImage as its background image (which is probably how I'd do it), etc... which one to choose will depend on the rest of the program, so it may be very early to say. Perhaps at this point you just want to create an interface of invariant behaviors to represent the Grid and thus allowing you flexibility with its implementation.

Maybe you are looking for

  • Error while viewing CR from Infoview

    Hi, I have developed Crystal Reports using OLE DB connection. I have published the report on BOE server. But when I try to view it from InfoView, it is displaying error message like u2018Entered information in either incomplete or incorrectu2019 I be

  • Ethernet Card in promiscuous mode

    Hello, I have a Powerbook G4 15p (1.25GHz) and I want to capture network trafic on a cisco trunk port. It works fine but I have no informations concerning vlan tags : is it possible to configure the Ethernet driver in promiscuous mode ? Best Regards,

  • Vendor return of produced components

    Client receives "R" material from vendor- A, it goes for subcontracting at B and changes to "S" material. "S" material is received back by client. Machining operation happens at clients machine shop C, after 5 operations- final confirmation  "S" mate

  • Travel expense

    hi Does anyone has implemented Travel Expense whereby employee just submit General Trip and no need to submit expense details?

  • IDOC Issue using ALE

    Hi, I am trying to create Invoice using T-code FB60/FBV1. When I save the document should see the entries in NAST table right? but I am not able to find those entries. When I have entry in NAST table only then I can send IDOC to the XI system. When I