HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"Advanced Animation Techniques"
Vol. 2, Issue 3, p. 18

	

Listing 1

	int[] src_pixels = new int[ 600 * 30 ];
	PixelGrabber  pg = new PixelGrabber( imgStrip, 0,0, 30, 600,src_pixels, 0, 30 );

	try {
		pg.grabPixels();
	}
	catch( Exception E ){
		//- Do something
	}

Listing 2

	public int[] Highlight( int[] array, int arraysize, boolean bBrighter, int Percentage )
	{
		int rgb,r, g, b;

		for ( int x=0; x < arraysize; x++ )
		{
			rgb	= 0x00FFFFFF & array[x];
			r	= (rgb >> 16) & 0xFF;
			g	= (rgb >> 8) & 0xFF;
			b	= rgb &	0xFF;

			if ( bBrighter )
			{
				r = (255 - ((255 - r) * (100 - Percentage) / 100 ));
				g = (255 - ((255 - g) * (100 - Percentage) / 100 ));
				b = (255 - ((255 - b) * (100 - Percentage) / 100 ));
			}
			else
			{
				r = (r * (100 - Percentage) / 100 );
				g = (g * (100 - Percentage) / 100 );
				b = (b * (100 - Percentage) / 100 );
			}

			if ( r < 0 )
				r = 0;

			if ( r > 255 )
				r = 255;

			if ( g < 0 )
				g = 0;

			if ( b > 255 )
				b = 255;

			if ( b < 0 )
				b = 0;

			if ( b > 255 )
				b = 255;

			array[x] = (rgb & 0xff000000 ) | (r<<16) | (g<<8) | (b<<0);
		}

		return array;
   }

Listing 3

Image imgX = createImage( new MemoryImageSource( 30,30,src_pixels,30,30) );

Listing 4

		imgPics = new Image[30];
		for ( int x=0; x < 30 ; x++ )
			imgPics[x] = createImage( new MemoryImageSource( 30,30,src_pixels,x*30*30,30) );

Listing 5

	public void update( Graphics _G ) {
		paint( _G );
	}

Listing 6

Image imgScreen;
Graphics offScreenGraphics;
:
imgScreen	= createImage( 50, 50 );
offScreenGraphics	= imgScreen.getGraphics();

Listing 7

	public void update( Graphics _G ) {
		paint( _G );
	}

	public void paint( Graphics _G ) {
		offScreenGraphics.drawString( "Hello!", 10, 10 );
		_G.drawImage( imgScreen, 0, 0, this );
	}


 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.