Switch to full style
General Java code examples
Post a reply

make Noise on Image

Tue Nov 11, 2008 5:43 pm

make Noise on Image in java
Code:
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.util.Random;
import javax.swing.*;

public class 
NoiseImage extends JComponent implements Runnable {
  
byte[] b;
  
BufferedImage bufferedImage;
  
Random ran;

  public 
void init() {
    
int wid getSize().widthht getSize().height;
    
int length = ((wid 5) * ht) / 7;
    
= new byte[length];
    
DataBuffer dataBuffer = new DataBufferByte(blength);
    
WritableRaster raster Raster.createPackedRaster(dataBufferwidht1null);
    
ColorModel colorModel = new IndexColorModel(12, new byte[] { 
      (
byte0, (byte250} ,  new byte[]  {(byte0,  (byte250 },  new byte[]  {      (byte0, (byte250 });
    
bufferedImage = new BufferedImage(colorModelrasterfalsenull);
    
ran = new Random();
    new 
Thread(this).start();
  }
    public 
void run() {
    while (
true) {
      
ran.nextBytes(b);
      
repaint();
      try {
        
Thread.sleep(80);
      } catch (
Exception e) { 
      }
    }
  }
  public 
void paint(Graphics graphics) {
    if (
bufferedImage == null)
    
init();
    
graphics.drawImage(bufferedImage00this);
  }
  public static 
void main(String[] args) {
    
JFrame frame = new JFrame();
    
frame.add(new NoiseImage());
    
frame.setSize(250250);
    
frame.setVisible(true);
  }



Attachments
noiseImage.gif
Image will be displayed as:
noiseImage.gif (8.99 KiB) Viewed 7516 times

Post a reply
  Related Posts  to : make Noise on Image
 Image-Viewer-Image Processing-Filters-Noise-enhancements     -  
 Image Noise Filter in Java     -  
 Move image in front of a background image     -  
 different between cfa image and gray level image     -  
 make a banner     -  
 PNG image to the image you generated     -  
 Make a call using java     -  
 How make a report using IReport on JSP?     -  
 how to make ArrayList ThreadSafe     -  
 make abstract class     -  

Topic Tags

Java Image