Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2005

Tip: Looking for answers? Try searching our database.

MemoryImageSource and using it...

Thread view: 
JariTapio - 08 May 2005 20:40 GMT
Hei!

Im tryin to make a random screen with MemoryImageSource but faling to do
it..

I do not know what is wrong please help...

The Source follows...

Please be a friend and reply...

JariTapio/Helsinki/08may2005
www.EuroJari.com

//<applet code ="Testi.class" width=640 height=480></applet>
//

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.image.*;

public class Testi extends java.applet.Applet implements Runnable{

   Thread thread;
   Image image;
   int [] pix = new int [999999];

   public void init()
   {
   }
   public void start()
   {
       thread = new Thread(this);
       thread.start();
   }
   public void stop()
   {
       thread.stop();
   }
   public void run()
   {
       while ( true )
       {
           for (int cc=0; cc< 640*480; ++cc )
               pix [cc]=(int)(Math.random ()*255);

           ImageProducer ip = new MemoryImageSource ( 640,480,pix,0,640 );
           image = createImage (ip);
       }
   }

   public void paint(Graphics g)
   {
       g.drawImage(image,0,0,640,480,this);
   }

   public void update(Graphics g)
   {
       paint(g);
   }
}
Thomas Fritsch - 09 May 2005 00:01 GMT
> Hei!
Hei!

> Im tryin to make a random screen with MemoryImageSource but faling to do
> it..
[quoted text clipped - 40 lines]
>            for (int cc=0; cc< 640*480; ++cc )
>                pix [cc]=(int)(Math.random ()*255);

There is a problem with your pixel values. They are always in the range
0x00000000 ... 0x000000FF.
Because you are implicitly using the default RGBColorModel this means:
The blue component varies. The red, green, and -most importantly- the alpha
components are 0.
Hence your image is totally transparent!
Use for example instead:
             pix [cc]=0xFF000000 + (int)(Math.random ()*255);
This will give a blue/black sparkling image.

>            ImageProducer ip = new MemoryImageSource ( 640,480,pix,0,640 );
>            image = createImage (ip);
Here you should call:
             repaint();
so that your paint method gets called after your image changed.
Also: Consider making a pause here in order to lower the CPU-load:
             try { Thread.sleep(1000); }
             catch(InterruptedException e) {}

>        }
>    }
[quoted text clipped - 10 lines]
> }
>
Signature

"TFritsch$t-online:de".replace(':','.').replace('$','@')



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.