Fastest way to draw Pixel at a time?

so far, from what ive seen, an applet is fairly fast for creating and displaying images, im working with a fairly new shading method(its like a year old, which is fairly new compared to the other 4 or so shading methods), but this requires me to draw pixel at a time, im only drawing each pixel once(not drawing over the same pixel when drawing another shape) so everything is calculated before the pixels are set and drawn. the only way from which i can see with a standard graphics object i can see to draw a pixel(or a point) would be to draw a line with the same start and end point or to draw a rectangle with a width and lenght of 1 pixel(both of these methods for drawing a point are a little slower than i want them to be). ive tried using a Buffered Image in a JFrame, setting each pixel one at a time, then updating the frame to display the new image, but that has proven to be fairly slow, so is there any way(faster than using an applet) to draw pixels one at a time?

what does the array parameter of setPixel in the WritableRaster class do?Depends on the type of buffered image you are using. I gave you an example of using a grey scale. 0 is black, 255 is white and you can have shades of grey in between.
how can i use it to set the color i want? Above example doesn't help since you want more colors. So you would use a different type:
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);Now you need 3 entries in the array to specify the color. So to set a pixel red you would use:
int[] pixelColor = new int[3];
pixelColor[0] = 255;
pixelColor[1] = 0;
pixelColor[2] = 0;Here is a modified example that builds the image completely from an array:
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
public class ImageFromArray2 extends JFrame
     int width = 50;
     int height = 50;
     int imageSize = width * height;
     public ImageFromArray2()
          JPanel panel = new JPanel();
          getContentPane().add( panel );
          int[] pixels = new int[imageSize * 3];
          //  Create Red Image
          for (int i = 0; i < imageSize * 3; i += 3)
               pixels[i] = 255;
               pixels[i+1] = 0;
               pixels[i+2] = 0;
          panel.add( createImageLabel(pixels) );
          //  Create Green Image
          for (int i = 0; i < imageSize * 3; i += 3)
               pixels[i] = 0;
               pixels[i+1] = 255;
               pixels[i+2] = 0;
          panel.add( createImageLabel(pixels) );
          //  Create Blue Image
          for (int i = 0; i < imageSize * 3; i += 3)
               pixels[i] = 0;
               pixels[i+1] = 0;
               pixels[i+2] = 255;
          panel.add( createImageLabel(pixels) );
     private JLabel createImageLabel(int[] pixels)
          BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
          WritableRaster raster = image.getRaster();
          raster.setPixels(0, 0, width, height, pixels);
          JLabel label = new JLabel( new ImageIcon(image) );
          return label;
     public static void main(String args[])
          JFrame frame = new ImageFromArray2();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.setLocationRelativeTo( null );
          frame.setVisible( true );
}

Similar Messages

  • Fastest way to draw a grid

    What is the best or quickest way to draw the walls on PacMan
    Making the game pacman and wondering is there a fast way to draw the board...
    instead of loads of lines saying
    g.drawLine(......);

    Uh, I was asking if there was another way...
    fillrect/drawrect are the only other ways to do it
    lol... and I've tried Graphics2D.How about drawOval or drawPolygon (doubt that)?
    >
    I was wondering if there was maybe another class/set
    of functions... etc?You could drop down to some native library like DirectX or OpenGL or some such, but I don't know of any other way to paint the screen with Java. (but then, I'm certainly not a "screen painting" sorta guy, so take that for what it's worth)

  • What is the ABSOLUTE FASTEST way to draw a point on a JFrame in Java?

    I am currently using:
    g.drawLine(x,y,x,y);with g being a Graphics object. Is there any faster way to draw a point in Java?

    Uh, I was asking if there was another way...
    fillrect/drawrect are the only other ways to do it
    lol... and I've tried Graphics2D.How about drawOval or drawPolygon (doubt that)?
    >
    I was wondering if there was maybe another class/set
    of functions... etc?You could drop down to some native library like DirectX or OpenGL or some such, but I don't know of any other way to paint the screen with Java. (but then, I'm certainly not a "screen painting" sorta guy, so take that for what it's worth)

  • Drawing float* buffer fastest way

    Hi,
    I am little out-of-date about pixel buffer objects, native pixel formats, etc. on OSX. Can you briefly point me out what is the fastest way to visualize grayscale data represented as float* 2d array (non power of two domain, [0,1] range) to the frame buffer? Is OpengGL my best option or is there any faster OSX specific direct frame buffer drawing?
    In case of OpenGL, how do I do this. I am using Cocoa, on 10.5x.
    Thanks a lot
    Sunil

    Hi,
    I am little out-of-date about pixel buffer objects, native pixel formats, etc. on OSX. Can you briefly point me out what is the fastest way to visualize grayscale data represented as float* 2d array (non power of two domain, [0,1] range) to the frame buffer? Is OpengGL my best option or is there any faster OSX specific direct frame buffer drawing?
    In case of OpenGL, how do I do this. I am using Cocoa, on 10.5x.
    Thanks a lot
    Sunil

  • What is the fastest way of getting data?

    With a scanning electron microscope, I need to scan a 512*512 pixel area with a pixel repetition of 15000 (two channels), meaning averaging over 15000 measurements. Simultaneously I have to adjust the voltage output for every pixel.
    I am using a 6111E Multifunction I/O board in a 800MHz P3. The whole task has do be done as fast as possible (not more than 20 minutes altogether).
    What is the fastest way to get this huge amount of data with averaging and output in between? (E.g. do I use buffered read with hardware triggering or is there a faster way?)

    Using the NI-DAQ API (not LabView) will give you a significant amount of more control over what happens and when to the data stream; which translates to a more efficient program. But you need to program in C/C++ or Delphi then. The Measurement Studio provides ActiveX controls that are like the LabView ones for C&C++ (they�re slow like the LabView ones though � not a lot you can do about the Windows GDI).
    What are you trying to sample 15000 times? The 512*512 pixel field?
    That�s almost 15Gigs of data! And it means you need to process data at 12.8MB/s to finish it in 20 minutes. I hope you know C, x86 assembly and MMX.
    I would setup a huge circular buffer (NI-DAQ calls them �double buffers�), about 30 seconds worth or so, to use with SCAN_Start. Then I would proces
    s the actual buffer the card is DMA�ing the data into with a high priority thread. Progressively sum the scan values from the 16bit buffer (the samples are only 12 bit, but the buffer should still be 16bits wide) into a secondary buffer of DWORDs the size of the screen (512*512), and you�ll need two of those, one for each channel. Once the 15000 scans are complete, convert each entry into a float divide by 15000.0f, and store it in a third buffer of floats.
    If you wish to contract this out, send me an email at [email protected]

  • Efficiant way of drawing?

    Im looking for the most efficiant way to draw, my application requires drawing of images every 50m/s or so.
    What im doing is using a class which uses PixelGrabbar for a pixel array, this is left there to use so it dosn't have to load every single time.
    For example;
    public ImageClass image1 = new ImageClass("myimage");Then, there i have a class which has a set pixel array size, for example;
    public ScreenDrawing sd1 = new ScreenDrawing(400, 600, this);This uses the following code;
    public ScreenDrawing(int w, int h, Component component)
            drawingAreaHeight = h;
            drawingAreaWidth = w;
            drawingAreaSize = new int[w * h]; //pixel array
            drawingAreaImage = component.createImage(this);
            component.prepareImage(drawingAreaImage, this);
            component.prepareImage(drawingAreaImage, this);
            component.prepareImage(drawingAreaImage, this);
        }Basically, when i want to draw the whole screen image i would do this;
    sd1.drawPixels(x, graphics, y);This would draw the pixel array to the screen at x, y.
    To get the pixels set on the "screenDraw" class i would do;
    image1.setPixels(x, y);After this is set it paints it to the screen.
    public void drawGraphics(int xOffset, Graphics g, int yOffset)
            setImageConsumer();
            g.drawImage(drawingAreaImage, xOffset, yOffset, this);
    public synchronized void setImageConsumer()
            if(imageConsumer != null)
                imageConsumer.setPixels(0, 0, drawingAreaHeight, drawingAreaWidth, colorModel, drawingAreaSize, 0, drawingAreaHeight);
                imageConsumer.imageComplete(2);
        }This is basically everything i use.
    But i have a problem, when drawing an image, for example just the size, 96 x 96 pixels, this will just flicker the image instead of drawing it because of the speed it needs to be drawn to update with the image placed above of this image.
    If anyone knows any more efficiant way to draw please help.
    Thanks.

    If you are painting by using repaint(), then for an AWT component you need to override
    public void paint(Graphics g) {
         //call methods to do painting stuff
    }and override
    public void update(Graphics g) {
         paint(g);
    }to call paint. What's happening is that when you call repaint(), the AWT painting mechanism calls update(...) . This method in turn erases the background before calling paint(...) . The flickering is from seing the erasing.

  • How to print the table values in fastest way?

    Dear Friends,
    I'm having table in my application and i need to print the table values. For that I used print() method to print the table values.
    boolean complete = tableObj.print(mode, header, footer, showPrintDialog, null, interactive,
                                  null);But, the time taken for displaying print dialouge box so late and printing operation is done very slowly.
    Could anyone please tell me is there any better way and fastest way to print the table values?
    Thanks in advance

    Hi,
    In the Module pool you will have fields. For those fields you have created the name also. Assign those name to work area and from there to internal table.
    And for your requirement viceversa you need to done.
    With Regards,
    Sumodh.P

  • Fastest way to transfer information from my old MacBook Pro to a new one?

    What is fastest way to transfer data between MacBook pros? It takes forever on wi-if.

    Sometimes the fastest way would be just to transfer only your files via a external hard drive via drag and drop methods into the same named accounts on the new machine. This is especially useful if you want to avoid corruption of the old machine and have a chance to clean house of older files.
    By the time one fiddles around finding a Firewire cable and adpaters, a standard USB 3 external hard drive could be done already and be gotten at any local computer or office store.
    Also Retina's have SSD's and any data on them is not scrubbable like hard drives can be. Scrubbing SSD's would involve the entire drive being filled and this would wear them out prematurely as they have limited writes to each sector.
    If you want to use Migration or Setup Assistant, there is some element of risk involved because your copying the corruption over from the previous machine if it exists. If you know the previous software is fine on the older machine, then you can use Carbon Copy Cloner to clone the whole OS X boot parititon to the external USB drive, then hook this up to the new machine and run Migration/Setup Assistant against it, just like you would in Firewire Target Disk Mode if you don't want to wait to get a Thunderbolt to Firewire adpater from Apple.
    If you already have the Thunderbolt to Firewire adapter and a cable/adpater to the old Mac, then that's the fastest way.

  • Fastest way to create child class from parent?

    As the subject states, what do you folks find is fastest when creating child classes directly from the parent? (esp. when the parent is in a lvlib) I thought I'd post up and ask because the fastest way I've found to get working takes a few steps.
    Any suggestions ae appreciatized!
    -pat

    Thanks for the quick response Ben!
    Yea, I apologize, in your response I realize my OP was more than vague haha (it hapens when you get used to your own way of doing things I guess huh)- I'm trying to create a child from a parent so that it has all of the methods that the parent has.
    In order to do so I currently have to open and close LV a few times during my current process so that vi's in memory dont get mixed up- Currently I save a copy of the parent class in a sub dir of where it is saved, close out of LV, open the new 'copy of parent.lvclass', save as>>rename 'child class.lvclass', close LV, and open up the project to 'add file', then right click>>properties>>inheritance.
    Is this the only way to do this?
    Thanks again!
    -pat
    p.s. I'm tempted to steal your cell phone sig, hope you dont mind haha good stuff!

  • Fastest way to create subtitles

    Hi! What is the fastest way to create subtitles. I have a short film with one hundred subtitles. I have a text list with time codes, can I use that somehow? Or do I have to enter every subtile separately? And what are the basic settings?

    A possibility seems to be using Quicktime Pro to add your text to a Quicktime movie. The Apple instructions are in Text Track Tutorial. I never used it in real life,... but I tested it in the past and it seemed to be doing what I expected: to layout text over an existing movie at preassigned timecodes...
    For sure you must first adapt your text and timecodes to the required format, and most of all you must have the "original" timecode in your movie untouched (all timecodes your text is making reference to). But if you edited and exported your movie from FCE you lost the original timecodes... so I'm not sure this may help you.
    The other approach is manual: in FCE add a text clip at the correct timecodes, one at the time...
    Piero

  • Fastest way to create buttons from TOC entries?

    I am trying to make a TOC interactive by applying rollovers and links to each entry. What is the fastest way to create buttons out of each entry? Would the "create outlines" command be appropriate? As it stands now, I am copying an entry, pasting it into a new frame, aligning it over the original entry, then converting to button and applying behaviors. There's got to be a more efficient way to do this!
    Using CS3 Design Standard.
    Thanks for any help you can provide.

    Matt,
    function(){return A.apply(null,[this].concat($A(arguments)))}
    Sorry about the attachment. Not sure what happened
    See
    Announcement: File Attachments temporarily disabled
    above. The "temporarily" was an understatement at the time -- this has been in effect for, what? the past 2 years? Now it's just a poignant Daily Reminder of Jive's many shortcomings.

  • Fastest way to create a track of Whole notes beginning to end

    I am trying to create a tapper track consisting of a series or low G (G2) whole notes.
    What is the fastest way of doing this. (they really should be quantized) And, they should also be on beat-one only, throughout an occasional meter change.
    In logic you could drag blocks. I realize I could simply loop and then convert loop to real midi...
    But.. would this run amuck with meter changes. (Remember I just want notes beginning on beat one, and ONLY beat one.
    -Thanks

    Where you have sig changes, copy the region, and adjust it's length to fit the meter … you only need 1 region, rather than try to anticipate the myriad of time sigs that may crop up.
    I understand exactly what you mean, and it makes a lot of sense. I think it's strictly a question of the pattern of usage. If his style when writing is to frequently throw in some odd time sig that he hasn't used much before and is not likely to use again anytime soon, then what you say seems like the best approach. On the other hand, I'm assuming he's more in a situation where he tends to throw in, say, a measure of 2/4, 3/4 or 5/4 every now and then. And it's just a few sigs like that which he tends to use frequently. Therefore it might be slightly easier to have a few regions like that already prepared, and in a place where I can grab them easily. If I have them marked clearly by name and color, I can feel comfortable that I'm avoiding an error. Whereas if I'm creating them over and over again each time I need one, the snap settings and zoom level are relevant, and it's a little too easy to make a careless mistake, if the phone rings at the wrong time.
    Also, he sometimes wants whole notes, and sometimes quarter notes. And maybe there are some other variations like this. This would also be a reason to have some material prepared that I can use over and over again.
    But of course if one day I decide to emulate Stockhausen and throw in a bar in 142/8 time, it makes sense to create that only when I need it, because if I create that region in advance it probably won't get used much.
    So in practice I could picture him doing it a combination of both ways, because chances are certain sigs are used often and others are used rarely. I think it really depends on the writing style, and the pattern of how the unusual sigs are distributed. And also if he sees an advantage in the marking by color. That could be considered helpful, or it could be considered ugly and distracting.

  • Fastest way to read a 5MB textfile (200,000 lines)?

    My current code:
    String file = "";
    BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
    while(in.ready()) file = file.concat(in.readLine());Unfortunately it is awfully slow (starting with 2,000 lines per second but dropping to like 100 lines per second over time). What is the fastest way to load the content of that file in a string and out of curiosity, why are my lines per second dropping?
    Thank you for your help!

    tjacobs01 wrote:
    This is exactly what I've done - it's the fastest thing out there. One thing to comment on though: Using a BufferedInputStream is not necessary; BufferedInputStream only improves performance if you're doing inefficient reading (such as reading blocks by newlines). If you doubt what I'm saying set up a quick performance test bed and test it... I did this a while back which is why I know the truth :)I believe you. Thanks for the tip.
    In my case I needed the BIS because I only wanted to load the 40 MB audio file in 1 MB chunks at a time
    to process it and store it in my own representation.

  • Fastest way to view clips

    I have a hard drive camera and it creates hundreds of clips. I want to look at each clip and then create subclips. Is there a way to speed up the process of opening up each clip individually and then setting my in and out points? Can I put them all in viewer stacked up and then just exit the one I'm done with and go to the next? Any keyboard shortcuts anyone can recommend? I would rather not throw them all into the timeline, wait to export all the clips into one .mov file and then edit them that way, but I know that is an option. Any advice would help.

    use the keyboard. It's the fastest way. cmd-4 takes you to the browser, use the arrow keys to select the clip you want to view. Up and down arrows bring you from bin to bin, when a bin is selected. To open and enter a bin, use the left and right arrow. Once in the bin use the up and down arrows again to go up and down within the bin. Press the return key to load the clip in the viewer and the spacebar or "L" key to play. cmd-4 to go back to the browser and select another clip. If you want to rename a clip after you have watched it, press the Enter key (not the return key) and you will open the dialog box for the name. You can rip through the browser items without ever going to the mouse, which is what really slows you down.
    In addition, if you have Leopard you can use the Quicklook feature in the Finder window and just use the up and down arrows to cycle through the clips. You don't even need to press the spacebar because every time you arrow to a new clip it automatically plays. You don't even need to launch an application to view them.
    Just a couple of time saving features. If you have Adobe, you can use Bridge in the same way, but it's easier to name and add metadata to the clips before you import them into FCP.

  • Fastest way to enter multiple events (monthly work schedule)?

    I have a question that has been driving me mad. I am wondering what is the fastest ways to enter multple events into iCal.
    Every month, my wife gets her work schedule which is composed of various shifts throughout the week. What I would like to do, ideally, would be to set up an excel spreadsheet with a few variables (time on, time off, date, etc) and then have automator take all of that info and create the months worth of events in iCal.
    I am sick of having to click and drag each event and work through 20+ events each month because it simply takes too long. iCal must have an easy way to do this that I am unaware of. Any help?

    Happy first post! (unless you have been posting for ages and the new system has lost your record
    My teaching schedule changes from time to time. I keep a copy of it in a text file. When it changes, I edit the text file then run an applescript which removes all entries in iCal calendar timetable, then uses the text file to make a new set of entries. I use a text file because it is also the html file that I use to post a copy on my web server, but the script could fairly easily be modified to pull the data from a spreadsheet. You are welcome to have a copy to play around with.
    How does your wife's new schedule arrive? If it is by email, then you could consider having the email fire off the script, and pull the data directly from the mail.
    AK

Maybe you are looking for

  • Steps to deploy an ejb application and running an ejb client in weblogic server6.1

    steps to deploy an ejb application and steps to run an ejb client in weblogic server6.1 if the client is an simple java application and if the client is a servlet

  • Tablespace/datafile drop

    version 817/ os Solaris 8 There is request from user to take tablespace offline, and then drop this and its datafile...will i be able to startup db without issue after that? Edited by: DBA2011 on Mar 27, 2012 2:11 PM

  • Layer mask levels, How to get to it?

    Im watching a photoshop video, and he tells me to go into levels for the layer mask, but doesnt tell me how to do it. Any one know how?

  • Raw Files from Pentax  ist D L Camera

    I have chosen the RAW format for pictures I have taken on the camera but am having trouble downloading from the camera to Adobe Photoshop Elements 4. It says APE will handle RAW files but it doesn't seem to work for me. Does anyone out there have any

  • EEO / Ethnicity Reporting

    We are on ERP2004, currently installng HR Stack 15.  We have implemented all EEO changes to capture appropriate master data on IT0077.  However, EEO reporting seems to be an issue.  SAP will be releasing a new report which accomodates the new governm