Forcing images to be drawn

Hello. I am working on a program that will display an image for a tenth of a second and then allow the user to click a button representing the image they thought they saw. I am having trouble because it seems like Java draws the images when it wants to instead of when I tell it to. I have extended the JPanel class as seen below. I have also written a class called ImageTimer which just waits a tenth of a second before notifying the semaphore it was created with (I know this part of the code works right). The ShapePanel constructor is passed a blank image, and I call the changeImage(Image) method every time a button is clicked.
public class ShapePanel extends JPanel{
     private Image currentImage, blankImage;
     private Semaphore semaphore = new Semaphore(0, true);
     public ShapePanel(Image b){
          blankImage = b;
          currentImage = b;
          setBackground(Color.WHITE);
     public void changeImage(Image a){
          currentImage = a;
          update(getGraphics());
          ImageTimerTask task = new ImageTimerTask(semaphore);
          Thread thread = new Thread(task);
          thread.start();
          try{
               semaphore.acquire();
          }catch(InterruptedException e){
          currentImage = blankImage;
          update(getGraphics());
     public void paintComponent(Graphics g){
          super.paintComponent(g);
          g.drawImage(currentImage, 0, 0, this);
}The problem is that the "drawImage(Image, int, int, ImageObserver)" method doesn't draw the first image, but rather waits until the ActionListener code for the button has been completed, and then draws both images immediately (so I don't ever end up seeing anything but the blank image). If anyone has any idea how I can force the image to be drawn when I want it to, it would be greatly appreciated. Thanks:

but rather waits until the ActionListener code for the button has been completed, What button? I don't see any code for a button. The code you posted doesn't really help without knowing the entire context of you program.
I don't know why you extended JPanel to draw an image. Just add add an ImageIcon to a JLabel. Every time you use setIcon it will repaint itself automatically. In your button you would probably set the icon then start a Swing Timer. The Timer would fire in a tenth of a second and then use a new icon for the label. You should never use update(...);
If for some reason you want to do custom painting on a JPanel instead of using a JLabel with an ImageIcon, then you use repaint() to for the repainting of the panel.

Similar Messages

  • Force Image Caching

    I'm using an servlet to serves up image http://servletsuite.com/servlets/imageview.htm
    now my problem is that the image is not cached.
    I searched this forum and google, I have attempted the followings:
    - rewriting my servlet url using urlrewrite http://urlrewrite.dev.java.net/ so that my servlet url looks like a normal path to an image
    - setting http header
    Cache-Control: max-age:<large value here>, must-revalidate
    Expires: I have tried past date, future date
    Last-modified: I have tried past date, future date
    along with the combination of the above that suggests the image served should be cached.
    However, none of those work. My servlet container (currently using Tomcat 5.0) still serves the image and the response code is 200.
    Is there anyone out there who has really done it and proves that caching image served from a servlet can be done ?
    Is it actually possible to force caching of images served using a servlet? What are the criterias, and is there any documentation available on the net?
    Kind Regards,
    Take.
    p.s. any suggestion is very much appreciated :). I will gladly give it another attempt at every possibility.

    I have tried response.setIntHeader("Expires", large number here) ... and I gave it another try just now to re-verify that it doesn't work.
    The tutorials online should work. I agree, and I have verified that they work. But not with servlet which serves images, something like http://servletsuite.com/servlets/imageview.htm (you can decompile the .class file to view the source).
    One poster mentioned that he/she had it working with Expires header, I'm guessing that the servlet doesn't serve an image. That's why I asked about further details.
    From the posts in this forum, the problem with caching images from a servlet remains a mystery. And that's why I asked, is there anyone who succeed in caching an image from a servlet?
    The headers from various online tutorials work with most servlet, but not when the servlet serves an image.
    I would be interested if someone points me to a resource about response header and the person has also verified that it works with servlet serving an image.

  • Error: images are not drawn?!?!

    hi, i am having a BIG problem! i've developed an applet that works perfect when running it local thru appletviewer. i then uploaded the applet to a webserver and when i tried to start it by playing online it doesn't show any images. they are loaded (i guess) since there are no errors and i use a mediatracker to see when they have finished loading.
    try for yourself:
    http://www.paron.nu/sinkit/online/Sinkit.htm
    i am using ie6 on winxp.

    I tried it.
    In yer browser, look for some pull down menu that says "Java Console". Open it and you'll see this output and error:
    Simulation started
    Simulation resumed
    Simulation suspended
    Simulation suspended
    java.security.AccessControlException: access denied (java.io.FilePermission data/mainboard.jpg read)
         at java.security.AccessControlContext.checkPermission(AccessControlContext.java:269)
         at java.security.AccessController.checkPermission(AccessController.java:401)
         at java.lang.SecurityManager.checkPermission(SecurityManager.java:524)
         at java.lang.SecurityManager.checkRead(SecurityManager.java:863)
         at sun.awt.SunToolkit.getImageFromHash(SunToolkit.java:472)
         at sun.awt.SunToolkit.getImage(SunToolkit.java:486)
         at Background.<init>(Background.java:20)
         at Sinkit.start(Sinkit.java:49)
         at sun.applet.AppletPanel.run(AppletPanel.java:377)
         at java.lang.Thread.run(Thread.java:534)
    You are probably doing something like:
    Image i = Toolkit.getDefaultToolkit().getImage("data/mainboard.jpg");
    This is a security violation. Remember that your applet will be executing on someone elses browser. How would you like it if you visited a web site and some jerks applet opened your "pornlinks.html" file and read it? Or how about your plain-text password file? Applets are only allowed to read files off the "codebase" they originated from. So if you get your applet from "http://www.dorkland.com", you'd better load your pictures from there as well.
    What you need to do is put the image file in the same location as the applet. Then do something like this:
    public class MyApplet extends Applet {
      Image loadImage() {
        URL url = getClass().getResource("mainboard.jpg");
        return getImage(url);
    }Ian

  • Better to draw graphics or show image of previously drawn image?

    I have an AWT app that I have a fundamental question about best practices. I have a (double buffered) panel that has objects that move across it. As it is now, on each iteration, each of the objects is redrawn every time with the graphics object from the panel. For instance, is it better to do this (I am going to water this down heavily):
    class BlobImage{
         drawImage(Graphics g){
              g.drawABunchOfStuff
    class BlobImagePanel{
         private List<BlobImage> blobImages = new ArrayList<BlobImage>();
         public repaint{
              Graphics g = this.getGraphics;
              for (BlobImage bi: blobImages){
                   bi.drawImage(g);
         }Or is it better for the BlobImage to render a BufferedImage once, and then just give back that image each time like this:
    class BlobImage{
         private BufferedImage bufferedImage=null;
         public BlobImage(){
              if (bufferedImage==null){
                   bufferedImage = new BufferedImage(width, height, imageType);
                   Graphics g = bufferedImage.getGraphics();
                   this.drawImage(g);
         drawImage(Graphics g){
              g.drawABunchOfStuff;
         getImage(){
              return bufferedImage;
    class BlobImagePanel{
         private List<BlobImage> blobImages = new ArrayList<BlobImage>();
         public repaint{
              Graphics g = this.getGraphics;
              for (BlobImage bi: blobImages){
                   g.drawImage(bi.getImage,x,y,width,height,this);
    }Assuming the x and y positions change each time the panel is repainted, is it better to continually draw each object with the parameterized graphics object with the new positions, or is it better to just create the image, and then let the panel move the entire image around?
    Let me reiterate() that this is pseudocode, and probably not compilable. It's the concepts that I am asking about.
    Edited by: J_Y_C on Jan 10, 2008 2:04 PM

    Ah ha! ARGB, got it.
    What I ended up doing was something like this:
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();          
    GraphicsDevice gs = ge.getDefaultScreenDevice();
    GraphicsConfiguration gc = gs.getDefaultConfiguration();
    redWordImage = gc.createCompatibleImage(this.dimensions.width, this.dimensions.height, Color.BITMASK);Would there be any reason I would be better off with one versus the other? Or am I just doing more typing to arrive at the same destination?

  • "Save for web" forces image optimisation

    1.I don't know at which point it happened, but when I open "save for web" it open's on an "optimised" tab and saves it like that, which is really horrible. when I open it in photo viewer it look's normal but in an explorer small preview  and website it looks "optimised". Any ideas what I messed up?

    I just found this article document:
    http://www.adobeforums.com/webx/.3bc4cd31/2
    It looks like they now have to be saved via drop down menus in order for Illustrator to remember the slice names for export again:
    "Object - Slice - Slice Options, and then in Save for Web, set the Output Settings for Saving Files"
    In my opinion this is incredibly poor UI design. In prior versions of Illustrator, I would save the names in the Save for Web dialog box by simply double clicking the slice frame, and it would remember the names of my slices for export again.
    Clicking through drop down menus just to name a slice is inefficient compared to just double clicking a slice frame to name the slice.
    If this is a bug, is there a solution to this? (Or are we really stuck with this poor system?)

  • Flickering Image update (only one Image drawn on Component), 10+ Duke Dolla

    I've made an RBGFilter for Images and Combined it with a Thread
    to make an Image fade from Color to Grayscale.
    I use it together with an home made JComponent. It works, but the Image flickers.
    I've tried longer sleep periods (I thougt that maybe the filter was to slow) but it still flickered when changing the Image. I tried dubbel buffering, but couldn't get it to change the Image. Anyway, I suppose double buffering wouldn't help much, while it's only one Image to be drawn and it covers the entire Component.
    Does anyone have a clue about how to do?? You'll get plenty of Duke Dollars!
    (in the fade class)
    public void run()
    try{
    while( !Thread.interrupted() ){
    Thread.sleep( 70 );
    //Change colors:
    Image tmpImage = Toolkit.getDefaultToolkit().createImage(
    new FilteredImageSource( colorImage.getSource(), fadeFilter ) );
    ImageComponent.setImage( tmpImage ); //Home made component
    //test if fading is finished...
    catch( InterruptedException ie ){}
    (in the home made component)
    public void setImage( Image theImage )
    this.theImage = theImage;
    repaint();
    public void paintComponent( Graphics g )
    g.drawImage( theImage, 0, 0, this );
    }

    I dont know much about java but i do know a bit about MFC and this reminds me of a similiar issue in mfc. So heres my bet:
    Calls to repaint do call directly to paintComponent they first execute some code that paints the background of the component then calls the paintComponent routine. Typically the background is white and this results in flickering.
    Thats just a hunch. Because its similiar to an issue that you get in MFC around animation with framework paint calls.
    You can play the hunch by calling paintComponent directly and see if your flickering goes away. If it does find a way to use repaint without it repainting the background before it calls paintComponent (im sure theres a way or a similiar framework routine)
    One last thing? is the custom componet that your working with swing based? Cause swing based components are supposed to double buffer by default.

  • Image not drawn for a JComponent

    Hi
    I've got a JComponent which I use as a TableCellRenderer.
    The problem is that the Image is not drawn to the Graphics object of the paint method. Only when the form is resized is the Image shown. If the image change it is not shown at all. (remove //loadPicture((String)value); in the getTableCellRendererComponent method of the TestCellRenderer class)
    I've used other methods on the JComponent just to see if it is working... all the other methods works fine... like the drawLine, drawString ...... but not the drawImage.
    Any ideas ?
    Here is the code
    CODE
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
    import javax.swing.table.*;
    public class TestCellRenderer extends JComponent implements TableCellRenderer{
    Image img;
    ChangeListener cl;
    public TestCellRenderer(){
    try{
    loadPicture("ac1.gif");
    setSize(new Dimension(100,100));
    this.setPreferredSize(new Dimension(100,100));
    this.setBorder(new LineBorder(Color.RED));
    catch(Exception e){
    e.printStackTrace();
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column){
    //loadPicture((String)value);
    this.updateUI();
    return this;
    public Image getImage(){
    return img;
    public void setImage(Image img){
    this.img = img;
    public void addChangeListener(ChangeListener l){
    cl = l;
    private void loadPicture(String path){
    try{
    //if (img != null){
    // img.flush();
    // img = null;
    img = Toolkit.getDefaultToolkit().createImage(path);
    if (cl != null){
    cl.stateChanged(new ChangeEvent(this));
    catch(Exception e){
    e.printStackTrace();
    public void paint(Graphics graphics){
    Graphics2D g = (Graphics2D)graphics;
    try{
    g.drawLine(0,0,getWidth(),getHeight());
    g.drawImage(img,0,0,getWidth(),getHeight(),null);
    g.setColor(Color.RED);
    g.drawLine(getWidth(),0,0,getHeight());
    super.paint(g);
    catch(Exception e){
    e.printStackTrace();
    CODE
    import javax.swing.table.*;
    public class TestModel extends DefaultTableModel{
    public TestModel(){
    this.addColumn("Image Column");
    this.addColumn("Column Two");
    CODE
    import java.awt.*;
    import java.util.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    import javax.swing.*;
    class TestPaintInTable extends JFrame{
    private static TestCellRenderer viewer = new TestCellRenderer();
    public static void main (String args[]){
    TestPaintInTable frame = new TestPaintInTable();
    frame.setSize(300,300);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    TestModel model = new TestModel();
    //Data
    Vector vecData = new Vector();
    vecData.add("ac.gif");
    vecData.add("Aircraft One");
    model.addRow(vecData);
    vecData.removeAllElements();
    vecData.add("ac1.gif");
    vecData.add("Aircraft Two");
    model.addRow(vecData);
    TestTable testTable = new TestTable(model);
    TableColumn col = testTable.getColumnModel().getColumn(0);
    TestCellRenderer tCR = new TestCellRenderer();
    tCR.addChangeListener(new ChangeListener(){
    public void stateChanged(ChangeEvent e){
    System.out.println("State has changed. Image = " + ((TestCellRenderer)e.getSource()).getImage() );
    viewer.setImage(((TestCellRenderer)e.getSource()).getImage());
    viewer.update(viewer.getGraphics());
    col.setCellRenderer(tCR);
    JScrollPane scr = new JScrollPane(testTable);
    frame.setLayout(new BorderLayout());
    frame.getContentPane().add(viewer,BorderLayout.NORTH);
    frame.getContentPane().add(scr,BorderLayout.CENTER);
    frame.setVisible(true);
    CODE
    import javax.swing.*;
    import javax.swing.table.*;
    public class TestTable extends JTable{
    public TestTable(DefaultTableModel model){
    super(model);

    change this line
    g.drawImage(img,0,0,getWidth(),getHeight(),null);
    to this
    g.drawImage(img,0,0,getWidth(),getHeight(),this);
    for the images in the cells, try this link
    http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=2&t=000610

  • Hand Drawn Animation Troubleshooting (image)

    I am following several tutorials for an end effect of a hand or writing tool that appears to draw a picture. I am attempting to have the hand draw out the picture by first taking the picture and using a stroke effect and tracing it with the pen tool. However, I am experiencing a few issues with it so far, namely:
    1.  I trace the image I want drawn with the stroke effect. I copy the mask produced from tracing and then paste into the positon keyframe of my hand comp. The problem here is it masks out section of my hand.
    2. Get the hand to follow the mask path created on the image. The alternative in the video tutorials for this type of effect often manually keframes the hand into position. I was hoping by pasting the mask path into the position keyframes for the hand it would automatically follow the drawing.
    Please see image below for illustration (please click to enlarge), thanks for your time

    You will need to convert the hand layer to 3D to make the lights and shadows work. In 2D the top layer is always visible. It is just better work flow to start in 2D, do the 2D motion, then convert to 3D.
    It's kind of like cell animators doing quick pencil studies first to see if the shot works before going through the trouble of making all of the layers and doing the final artwork.
    For projects that require a lot of client review and input I always do very simple motion and timing studies before wasting time finessing lighting, textures, color grading and the like. I haven't got time in the budget to do that kind of work twice. I can't tell you how many projects start with some rough pencil sketches (previously scanned now show with my phone) and laid in a composition to an audio track and animated. When the client (or even me) approves the timing and the flow of the story I go about the tasks of cleaning it up.
    Here's a shot from a previous post that shows my normal starting workflow. It was in answer to this question on the forum.
    On your screenshot: I just opened your image in a new window and it's much easier to read. Sorry about making assumptions. Making that wide composite was the problem. I try to keep my screen captures at about 1000 to 1500 pixels wide. If you need to show multiple views just upload multiple screen shots. My mac also creates PNG files. If I have time I convert them to medium quality JPGS because the file size is smaller.
    The forum style sheet keeps the images to the width of your browser when they pop out and limites their size when embedded.
    Hope this helps.

  • Why doesn't Image Capture work with document feeders?

    I've tried to scan a bunch of different types of documents using Image Capture and my Samsung CLX-3175FW's document feeder (multifunction color laser printer) but every time what gets scanned is a thin vertical slice of each page - completely useless. I don't see any way to force Image Capture to scan at 8.5" x 11" rather than doing whatever it's doing resulting in a thin vertical slice.
    Any ideas on how to fix this?
    Thanks!

    Quick update... I've done some troubleshooting and confirmed that when Image Capture scanning via USB and using the document feeder, everything looks great. When the ONLY option I change is printing via wireless, I get the thin vertical slice of each page. I sent some screenshots to Samsung to see if they have any ideas.

  • Get Rid of the Text-as-Image Export

    For the life of me I can't figure out why Adobe would add such an irritating feature and not allow it to be toggled.
    Come on Adobe developers, exercise some intelligence here.
    I am aware there are potential licensing issues but let's review:
    You cannot use system fonts that are not considered 'web safe' without them exporting as image, even though 99% of Windows users will have them and Mac users will have no trouble with them being substituted.
    It makes manual CSS font stacks useless since Muse abandons this possibility when it goes the image route.
    There are plenty of TypeKit fonts available through Creative Cloud that are accessible when synced, yet many of them are not in Muse's library so will also force image export. If it synced through CC and is licensed for web use then there are no licensing issues. Export as text and let the user drop in their TypeKit code.
    Many users will use Google/Typekit web fonts perfectly fine but downloading and self-hosting the font files just to use them in Muse is a waste of time and not necessarily possible.
    The workaround is to use a completely different font, thus upsetting the page layout, just so that it exports as text and a simple find and replace can be used to change font-family.
    I can't even use Open Sans without it exporting as an image. Seriously? Likely the most widespread web font in existence and you force an image export. That's just bad.
    Please get rid of this... allow users to turn image exports off and handle font styling ourselves or remove it entirely.
    It was fine beforehand when you could use any font installed locally, including CC synced Typekit fonts, with only the Muse fonts triggering placing of a Muse Typekit code.
    This resulted in users having to intervene post-export to have web fonts render properly if they weren't available through Muse which was perfectly reasonable.

    Feature Requests
    1. Provide access to the complete Typekit font offering.
    2. Provide the ability to define and use your own font fallback stacks (aka Web Safe font definitions)
    Possible Misconceptions
    1. Open Sans isn't readily available as a Web Font in Muse
    2. We've changed something in the generated code that makes it more difficult to manually edit the output.
    You're correct. The paid Typekit library is not currently easily available from within Muse. We continue to lobby the Typekit team for changes required to enable paid Typekit in a seamless UI within Muse, but thus far we have yet to reach the top of their development team's priority list.
    If you're familiar with font stacks you're aware there are very few truly "web safe" fonts. In most cases using a "web safe" font means settling for one of a handful of fonts depending on the OS or device being used to view your site. That font variation means variations in the line breaks within text frames and thus changes to text frame heights which are likely to result in changes to the overall layout of your pages. In most cases a Web Font is a much better choice if the visual fidelity of your design is an important part of your site. It's unlikely Muse will provide the ability to define arbitrary font stacks. Given the target market of Muse and our small development team, future additional font support will likely continue to be in the area of Web Fonts.
    If you select "Add Web Fonts" in the Web Fonts section of the Fonts menu you can browser a library of 500+ font families that are provided for free and hosted on Adobe's Typekit service. This set of free fonts is marketed as "Edge Web Fonts." The Edge Web Fonts offering started as the set of public domain fonts hosted by Google with a small number removed due to quality issues and a small number added from the set of fonts Adobe wholly owns. The majority of the ~650 web fonts now hosted by Google are part of the 500+ web fonts readily available within Muse.
    Open Sans is one of the font families in the Edge Web Fonts library. Go to "Add Web Fonts" in the Fonts menu, type "open" in the search field of the Web Fonts dialog, click on Open Sans and it will be added to the Web Fonts section of your Muse Font menu for easy future use. On your site the font will be provided via Typekit without any page view limits or requirement to be a Creative Cloud subscriber.
    To my knowledge there have not been any changes in Muse output that should impact your ability to use a Web Safe font in Design view, then alter the generated code to replace that font with a font from some other source (i.e. paid Typekit, Fonts.com hosting, etc.). It's never been possible to use a System Font in Muse and then alter the output code to replace the font, since the output for a text frame that uses a System Font has always been an image.
    Thank you for taking the time to voice your opinions and provide feature requests.

  • Background Image on a Component

    How do I add a background image to a component, in this case, a scrollpane containing a drawing area. This is for a level editor for my game. I want a level's background image to be drawn and tiled so the user can get a better preview of what the level will really look like. Is there an easy way to do this?

    Do you have a little code-snippet on how to use this
    class? The only things I've ever needed to do in
    graphics is loading, transforming, and drawing images,
    so I'm a bit in the dark on anything outside that.I think something like this will do it. I don't know for sure though since I've never used it:
    private BufferedImage bImage;
    // ... constructors, code blahdy blah, construct the bufferedimage here etc.
    public void paintComponent(Graphics g) {
      // the Rectangle2D in user space used to anchor and replicate the texture:
      Rectangle2D anchor = new Rectangle2D.Double(0,0,20,20);
      // the actual paint object:
      TexturePaint tpaint = new TexturePaint(bImage, anchor);
      Graphics2D g2d = (Graphics2D) g;
      g2d.setPaint(tpaint);
      // g2d.fillRect(0,0,getWidth(), getHeight());
    }

  • Resizing image in JFrame

    Im trying to get the following code to resize the image that is drawn in TrackPanel, im added a resize listener but am not sure how to get the image to resize when the frame is resized.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.Dimension;
    import java.awt.event.*;
    import java.net.URL;
    public class MyFrame {
         public static void main(String[] args)
              Frame frame = new Frame();
    class Frame extends JFrame {
         private Image track;
         public Frame() {
              Class cl = this.getClass();
              Toolkit T = this.getToolkit();
    track = T.getImage("C:\\track6.gif");
              MediaTracker mediaTracker = new MediaTracker(this);
    mediaTracker.addImage(track, 1);
    try {
    mediaTracker.waitForID(1);
    catch (InterruptedException ie) {
    System.err.println(ie);
              addComponentListener(new ComponentAdapter() {
    public void componentResized(ComponentEvent evt) {
    int width = getWidth();
              int height = getHeight();
              TrackPanel track1 = new TrackPanel(track);
              getContentPane().add(track1, null);
              pack();
              setVisible(true);
    class TrackPanel extends JPanel {
         private Image track;
         private int imageWidth;
         private int imageHeight;
         public TrackPanel(Image tr)
              track = tr;
              setPreferredSize(new Dimension(800, 500));
         public void paintComponent(Graphics g)
              g.drawImage(track,0,0, 800,500,this);
    }

    import javax.swing.*;
    import java.awt.*;
    import java.awt.Dimension;
    import java.awt.event.*;
    import java.net.URL;
    public class MyFrame {
         public static void main(String[] args)
              Frame frame = new Frame();
    class Frame extends JFrame {
         private Image track;
         public Frame() {
              Class cl = this.getClass();
              Toolkit T = this.getToolkit();
            track = T.getImage("C:\\track6.gif");
              MediaTracker mediaTracker = new MediaTracker(this);
            mediaTracker.addImage(track, 1);
            try {
                mediaTracker.waitForID(1);
            catch (InterruptedException ie) {
                System.err.println(ie);
              addComponentListener(new ComponentAdapter() {
                public void componentResized(ComponentEvent evt) {
                    int width = getWidth();
                      int height = getHeight();
              TrackPanel track1 = new TrackPanel(track);
              getContentPane().add(track1, null);
              pack();
              setVisible(true);
    class TrackPanel extends JPanel {
         private Image track;
         private int imageWidth;
         private int imageHeight;
         public TrackPanel(Image tr)
              track = tr;
              setPreferredSize(new Dimension(800, 500));
         public void paintComponent(Graphics g)
              g.drawImage(track,0,0, 800,500,this);
    }Sorry this should do it !!!

  • Flicker while redrawing an Image (only one)

    I've made an RBGFilter for Images and Combined it with a Thread
    to make an Image fade from Color to Grayscale.
    I use it together with an home made JComponent. It works, but the Image flickers.
    I've tried longer sleep periods (I thougt that maybe the filter was to slow) but it still flickered when changing the Image. I tried dubbel buffering, but couldn't get it to change the Image. Anyway, I suppose double buffering wouldn't help much, while it's only one Image to be drawn and it covers the entire Component.
    Does anyone have a clue about how to do?? You'll get plenty of Duke Dollars!
    (in the fade class)
    public void run()
    try{
    while( !Thread.interrupted() ){
    Thread.sleep( 70 );
    //Change colors:
    Image tmpImage = Toolkit.getDefaultToolkit().createImage(
    new FilteredImageSource( colorImage.getSource(), fadeFilter ) );
    ImageComponent.setImage( tmpImage ); //Home made component
    //test if fading is finished...
    catch( InterruptedException ie ){}
    (in the home made component)
    public void setImage( Image theImage )
    this.theImage = theImage;
    repaint();
    public void paintComponent( Graphics g )
    g.drawImage( theImage, 0, 0, this );
    }

    Create an adjustment layer then clip it to the layer you want to lighten by clicking between the two layers while holding the alt/opt key.

  • Synchronous image display on external display

    Hi,
    I'm trying to get structural illumination microscopy using a LCoS spatial
    light modulator working. The modulator is controlled using DVI interface, and
    having no dedicated DVI capable hardware I'm stuck controlling the modulator
    using a dual video output desktop PC. I've developed a VI that executes
    following algorithm:
    1) Show grid 1 on external display
    2) Acquire frame 1
    3) Show grid 2
    4) Acquire frame 2
    5) Show grid 3
    6) Acquire frame 3
    7) Compute and store image
    8) Advance stage and repeat
    I'm using the External Display VIs form the Vision menu group to display the
    grids, and IMAQdx for the acquisition.
    The problem I'm having is that when this looping is slow enough, say 5 s,
    everything goes well, but when I optimized it and increased the speed, some of
    the acquired frames are wrong. After some tedious debugging I've think the
    problem is that shown images are delayed because of all the Windows fuss. There
    is no way of synchronizing the displayed image with the acquisition routine -
    after the image is "displayed" it's up for windows to actually
    display it.
    1) Is there a way to know that the image is actually drawn using IMAQ
    WindDraw VI ?
    2) Is there a better (as in faster, more predictable) way of showing a
    bitmap image on an otherwise empty external display?
    3) Maybe it is possible to control the external display using some kind of
    low level video driver functions (OpenGL, DirectX, the card is NVIDIA, fairly
    recent)?
    4) Maybe the right way to do it would be to play a looping video? And if so,
    how could this synchronizing issue resolved then.
    Any kind of input would be appreciated.
    lukas

    Hi,
    And thanks for the input. Yes, in fact we've made some progress, so I'll add some details on this problem. First the answers to A Person's questions:
    1) The loop rate when this issue occurs is about 2-5 fps.
    2) We are using a simple delay to throttle down the execution. Originally we intended to run this as fast as possible, so there was no need for specific execution speed.
    And our progress is as follows:
    1) As it appears and was confirmed by NI staff, we were unable to come up with any kind of workaround on the WindDraw method, so we're dropping it.
    2) We've developed an simple DLL using VisualBasic to load our three bitmaps into a form window placed on the external display. The shown on one or the other bitmap now happens with a simple call to the DLL to change the visibility of a particular bitmap. It seems to solve our initial problem. Also, if that isn't enough, we're considering an analogous DLL using OpenGL orthographic projection window using three bitmaps and triple buffering. The specific bitmap would be shown then just by offsetting the video memory buffer.
    3) The video idea was not that good after all I think. The advantage would still be fast DirectDraw accesses, but 2) method seems more reasonable.
    And a little bit off this topic:
    4) After solving this problem, we've encountered another. Now the camera acquisition isn't synchronized to the frame clock signal of the SLM. This produces a well known screen flicker seen on the TV when a computer or TV screen is filmed without a sync signal. Our camera, the Kappa DX4 274FW, has an external trigger connection, but the interface connection is a mini centronix. To be honest this is the first time I heard of it and it is next to impossible to get one for a reasonable price. Even if we could, there is no pinout nor the inner workings information concerning the trigger, the official site just states "External trigger". The official support is also ignorant. So that's thumbs down for Kappa. We've switched to Point Gray Chameleon camera, which has proper technical documentation on it's triggering functionality and the again present "we have and you don't, please buy from us" type connector was changed to a proper SMA connector with a bit soldering and drilling. The bad news is that the ActiveX interface used by this camera is using user defined return data types and some of the methods are grayed out when trying to call from LabView. According to
    http://digital.ni.com/public.nsf/allkb/27B959B430BA501486256A920071F567
    It wont and should not work, so now we're considering moving to VisualBasic completely. Again, it's worth mentioning that the initial problem could be solved using method 2), but this felt kind of connected and this "industrial connector hindering" business got me frustrated. So sorry for the lengthy post.

  • My programming? JRE 1.4 bug? Images not displayed properly!

    I made this simple card game which you can checkout at http://www.koutbo6.com I used AWT components and used Panels for drawing the cards and the main game panel has a null Layout. It runs perfectly on all java enabled browsers ... except for IE on windows XP.
    I came across a problem where the card images are not displayed at all. some images that are drawn disrectly on the backround are partially drawn or not drawn correctly. The IExplorere had microsft virtual machine donloaded for windows XP. I managed to correct the problem by disabling JIT compiling from IE advanced setting.
    Then I installed XP on another PC and was surprized that Microsoft stopped distributing the Java Virtual Machine for XP, so I opted for sun java plugin V1.4 and the same problems occur. There is no way to turn off JIT compiling and i read in oone of the bug postings that the option has been taken off in versio 1.4.
    when the problem occurs I noticed that g.drawString works perfectly and all the AWT components are displayed even in the main panel with the null layout. the problem occurs with displaying the images. It could be with the way im doing things.
    this is how I draw my images using the paint method:
         public void paint(Graphics g){
              super.paint(g);
              if(cardImage != null){
                   g.drawImage(cardImage,0,0,this);
           }this is how I draw cards images on card panels, if i wana clear the image I would set cardImage to null and repaint. This is how i draw all the images in the client.
    Is there a problem with my way of doing things? or is there a problem with the java plug in? I'v yet to try installing older java plug-ins on this PC, I will try it and post if it solves the problem.
    Thanks in advance

    Well I tried other versions of the plug in and they seem to have the same problem. But I have noticed that images loaded using Applet.getImage() were displayed without problems. And when I ran the server/client locally "without" JARing the files, the images displayed perfectly.
    I am using a load image method that I picked up from the forums to enable the loading of images from jars when using netscape. This is the code I use to load the images from JAR:
         /** get an image from anyt sorce.*/
         public Image getImageFromJAR(String fileName){
              if (fileName == null) {
                   return null;
              Image image = null;
              byte[] thanksToNetscape = null;
              Toolkit toolkit = Toolkit.getDefaultToolkit();
              java.io.InputStream in = getClass().getResourceAsStream(fileName);
              int x = 0;
              try{
                   int length = in.available();
                        thanksToNetscape = new byte[length];
                        in.read( thanksToNetscape );
                        image = toolkit.createImage( thanksToNetscape );
              }catch(Exception exc){
                   System.out.println( exc +" getting resource " +fileName );
              return image;

Maybe you are looking for

  • I want to SHARE Sync Settings with my Family Members, How Can I Share Some of My Settings with Them.

    I want to SHARE Sync Settings with my Family Members & Friends, How Can I Share Some of My Settings like tabs, bookmarks, browser extension with them. Also it is obvious I would not like to share my Passwords. Can you please help. This feature "Shari

  • How to delete users from my shared list

    I have users in my shared tab in the finder. Some of these computers/users i dont know or dont what to have the risk of being to access my data. How do i remove them?

  • Can you help with problem

    I'm new in java programming the machine problem is for ordering system \\input character import java.io.*; class InputChar{      public InputStreamReader reads;      public InputStream reads2;      public DataInputStream keyboard;      public char in

  • Can python be invoked inside a fetchlet?

    Hi Guys I'm trying to build a customized plug-in for our storage device which only has a python API exposed to developers. I'm wondering if it is supported by enterprise manager to invoke python script inside a fetchlet. if it is possible, I'll manag

  • Complex XML DataSet and Sorting

    Hello, Please consider the following XML data: <viewentries>     <viewentry>         <entrydata name="column1">             <text>text1</text>         </entrydata>         <entrydata name="column2">             <text/>         </entrydata>         <e