About graphics in Java

Hello there,


This Java message board looks like it's not visited very often. That's too bad.

I am new at Java programming (I mainly do C/C++). I am currently writing some simple applets just to try some stuff out, and now I am stuck on the following problem, which is probably solved easily for those who know a bit more about it than I do: I have an int array filled with RGB values. Every int element represents a pixel of an image, like this: 0x00BBGGRR. My question: Is there a way to sort of 'blit' it to screen in its entirety? And how do I convert RGB values to a valid Java Color? (Note that I do not have Visual Cafe, or Jbuilder or whatever, just Sun's plain ol' JDK).

Also, could someone email me or point me to a Java class reference?


Thanks,

Mark


Comments

  • : Hello there,


    : This Java message board looks like it's not visited very often. That's too bad.

    : I am new at Java programming (I mainly do C/C++). I am currently writing some simple applets just to try some stuff out, and now I am stuck on the following problem, which is probably solved easily for those who know a bit more about it than I do: I have an int array filled with RGB values. Every int element represents a pixel of an image, like this: 0x00BBGGRR. My question: Is there a way to sort of 'blit' it to screen in its entirety? And how do I convert RGB values to a valid Java Color? (Note that I do not have Visual Cafe, or Jbuilder or whatever, just Sun's plain ol' JDK).

    : Also, could someone email me or point me to a Java class reference?


    : Thanks,

    : Mark




    How are you doing Mark?


    I am unsure of your questions, but I have all kinds of Java class references that I can provide to you. I have some bookmarks of different places on the web that you can visit to find out more information concerning Java Class reference. They are as follows:


    http://java.sun.com/products/jdk/1.1/docs/api/packages.html


    Java for C++ Programmers:

    http://www.cs.wisc.edu/~solomon/cs537/java-tutorial.html


    The Java Tutorial:

    http://java.sun.com/docs/books/tutorial/index.html


    The Java Language Specifaction:

    http://java.sun.com/docs/books/jls/html/index.html


    I hope these links are helpful towards your Java Class reference request. I am sorry I could not help you further on your question. Maybe you will be able to find the answer to your question in these links.


    Have a excellent day, Mark!




    Sincerely,

    Keenan


    Keenan Stewart (keenan_stewart@scholars.com)

    Learning Advisor, http://scholars.com


    Microsoft Certified Technical Education Center

    Novell Authorized Online Training Provider


    URL:http://scholars.com

  • : : Hello there,


    : : This Java message board looks like it's not visited very often. That's too bad.

    : : I am new at Java programming (I mainly do C/C++). I am currently writing some simple applets just to try some stuff out, and now I am stuck on the following problem, which is probably solved easily for those who know a bit more about it than I do: I have an int array filled with RGB values. Every int element represents a pixel of an image, like this: 0x00BBGGRR. My question: Is there a way to sort of 'blit' it to screen in its entirety? And how do I convert RGB values to a valid Java Color? (Note that I do not have Visual Cafe, or Jbuilder or whatever, just Sun's plain ol' JDK).

    : : Also, could someone email me or point me to a Java class reference?


    : : Thanks,

    : : Mark


    Hi Keenan,


    I am fine, thank you. What I meant with my question is simply that my applet generates a picture and stores every pixel of it in an array of type int as a RGB (Red Green Blue) value. I would like to know if I can convert an array like this to a picture or something (to an Image class maybe) so that Java can draw the image on screen for me. Else I would have to use drawLine for each pixel in the array, which would be terr


  • : : Hello there,


    : : This Java message board looks like it's not visited very often. That's too bad.

    : : I am new at Java programming (I mainly do C/C++). I am currently writing some simple applets just to try some stuff out, and now I am stuck on the following problem, which is probably solved easily for those who know a bit more about it than I do: I have an int array filled with RGB values. Every int element represents a pixel of an image, like this: 0x00BBGGRR. My question: Is there a way to sort of 'blit' it to screen in its entirety? And how do I convert RGB values to a valid Java Color? (Note that I do not have Visual Cafe, or Jbuilder or whatever, just Sun's plain ol' JDK).

    : : Also, could someone email me or point me to a Java class reference?


    : : Thanks,

    : : Mark


    Hi Keenan,


    I am fine, thank you. What I meant with my question is simply that my applet generates a picture and stores every pixel of it in an array of type int as a RGB (Red Green Blue) value. I would like to know if I can convert an array like this to a picture or something (to an Image class maybe) so that Java can draw the image on screen for me. Else I would have to use drawLine for each pixel in the array, which would be terribly slow.

    Thanks for the links, I will check them out.


    Greets,

    Mark


  • :My applet generates a picture and stores every pixel of it in an array of type int as a RGB (Red Green Blue) value. I would like to know if I can convert an array like this to a picture or something (to an Image class maybe) so that Java can draw the image on screen for me.


    Here is part of the jdk example program DitherTest.

    The path for a windows installation is (on jdk1.2)


    jdk1.2demoappletsdithertestDitherTest.java


    It seems to do what you want.


    (can view online by going to http://java.sun.com/

    and search for dithertest)

    (You can also download the docs for jdk

    -16Mb zip- or read them online.)


    Notice how MemoryImageSource() is used to return an Image.

    (if your browser makes a mess of the listing use the link above.)


    /*

    * @(#)DitherTest.java 1.6 98/06/29

    *

    * Copyright (c) 1997, 1998 Sun Microsystems, Inc. All Rights Reserved.

    */




    /* includes

    import java.applet.Applet;

    import java.awt.event.*;

    import java.awt.*;

    import java.awt.image.ColorModel;

    import java.awt.image.MemoryImageSource;

    import java.lang.InterruptedException;

    */


    /**

    * Calculates and returns the image. Halts the calculation and returns

    * null if the Applet is stopped during the calculation.

    */

    Image calculateImage() {

    Thread me = Thread.currentThread();


    int width = canvas.getSize().width;

    int height = canvas.getSize().height;

    int xvals[] = new int[2];

    int yvals[] = new int[2];

    int xmethod = XControls.getParams(xvals);

    int ymethod = YControls.getParams(yvals);

    int pixels[] = new int[width * height];

    int c[] = new int[4];

    int index = 0;

    for (int j = 0; j < height; j++) {

    for (int i = 0; i < width; i++) {

    c[0] = c[1] = c[2] = 0;

    c[3] = 255;

    if (xmethod < ymethod) {

    applymethod(c, xmethod, i, width, xvals);

    applymethod(c, ymethod, j, height, yvals);

    } else {

    applymethod(c, ymethod, j, height, yvals);

    applymethod(c, xmethod, i, width, xvals);

    }

    pixels[index++] = ((c[3] << 24) |<br>
    (c[0] << 16) |<br>
    (c[1] << 8) |<br>
    (c[2] << 0));<br>
    }


    // Poll once per row to see if we've been told to stop.

    if (runner != me)

    return null;

    }


    return createImage(new MemoryImageSource(width, height,

    ColorModel.getRGBdefault(), pixels, 0, width));

    }


    Hope this helps.

    Thomas Kay


  • Thank you, Thomas.


    : :My applet generates a picture and stores every pixel of it in an array of type int as a RGB (Red Green Blue) value. I would like to know if I can convert an array like this to a picture or something (to an Image class maybe) so that Java can draw the image on screen for me.


    : Here is part of the jdk example program DitherTest.

    : The path for a windows installation is (on jdk1.2)


    : jdk1.2demoappletsdithertestDitherTest.java


    : It seems to do what you want.


    : (can view online by going to http://java.sun.com/

    : and search for dithertest)

    : (You can also download the docs for jdk

    : -16Mb zip- or read them online.)


    : Notice how MemoryImageSource() is used to return an Image.

    : (if your browser makes a mess of the listing use the link above.)


    : /*

    : * @(#)DitherTest.java 1.6 98/06/29

    : *

    : * Copyright (c) 1997, 1998 Sun Microsystems, Inc. All Rights Reserved.

    : */


    :

    : /* includes

    : import java.applet.Applet;

    : import java.awt.event.*;

    : import java.awt.*;

    : import java.awt.image.ColorModel;

    : import java.awt.image.MemoryImageSource;

    : import java.lang.InterruptedException;

    : */


    : /**

    : * Calculates and returns the image. Halts the calculation and returns

    : * null if the Applet is stopped during the calculation.

    : */

    : Image calculateImage() {

    : Thread me = Thread.currentThread();


    : int width = canvas.getSize().width;

    : int height = canvas.getSize().height;

    : int xvals[] = new int[2];

    : int yvals[] = new int[2];

    : int xmethod = XControls.getParams(xvals);

    : int ymethod = YControls.getParams(yvals);

    : int pixels[] = new int[width * height];

    : int c[] = new int[4];

    : int index = 0;

    : for (int j = 0; j < height; j++) {

    : for (int i = 0; i < width; i++) {

    : c[0] = c[1] = c[2] = 0;

    : c[3] = 255;

    : if (xmethod < ymethod) {

    : applymethod(c, xmethod, i, width, xvals);

    : applymethod(c, ymethod, j, height, yvals);

    : } else {

    : applymethod(c, ymethod, j, height, yvals);

    : applymethod(c, xmethod, i, width, xvals);

    : }

    : pixels[index++] = ((c[3] << 24) |<br>
    : (c[0] << 16) |<br>
    : (c[1] << 8) |<br>
    : (c[2] << 0));<br>
    : }


    : // Poll once per row to see if we've been told to stop.

    : if (runner != me)

    : return null;

    : }


    : return createImage(new MemoryImageSource(width, height,

    : ColorModel.getRGBdefault(), pixels, 0, width));

    : }


    : Hope this helps.

    : Thomas Kay





Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories