hi everyone , i am trying to access image files in java and then want to modify those bits present in the image . is there any standard package or utility which would help me to do that ...?

i would be glad if you could enlighten me with other methods ..

Dear,

I am submitting a code. I hope this will help you.

package appex;
import java.awt.*;
import java.awt.image.*;
import java.applet.*;

public class App12 extends Applet{
	Image oldImage,newImage,subImage;
	ImageProducer filtered,cropped;
	
	public void init(){
		oldImage=getImage(getDocumentBase(),"long.jpg");
		filtered=new FilteredImageSource(oldImage.getSource(),new GrayFilter());
		cropped=new FilteredImageSource(oldImage.getSource(),new CropImageFilter(400,400,40,40));
		newImage=createImage(filtered);
		subImage=createImage(cropped);
	}
	public void paint(Graphics g){
		if(newImage!=null)
			g.drawImage(newImage,0,0,this);
		g.clearRect(20,20,140,140);
		if(subImage!=null)
			g.drawImage(subImage,30,30,120,120,this);
		} 
 	public static class GrayFilter extends RGBImageFilter{
 		public GrayFilter(){
 			canFilterIndexColorModel=true;
 		}
 		public int filterRGB(int x,int y,int rgb){
 			int alpha,r,g,b;
 			int gray;
 			alpha=rgb & (0xFF << 24);
 			r=(rgb >> 16) & 0xFF;
 			g=(rgb >> 8) & 0xFF;
 			b=(rgb >>0) & 0xFF;
 			gray=(r+g+b)/3;
 			return alpha | gray<<16 | gray<< 8 | gray;
 	    }
    }	
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.