Results 1 to 8 of 8
- 09-20-2008, 10:40 AM #1
Member
- Join Date
- Jun 2008
- Posts
- 48
- Rep Power
- 0
- 09-20-2008, 11:48 AM #2
Senior Member
- Join Date
- Aug 2008
- Posts
- 384
- Rep Power
- 5
Make a class, Pixel, holding the argb value, and position, and make a 2d array. Fill it by looping through every pixel in the image. Not gonna write the code for you. Show us what you've got first.
I die a little on the inside...
Every time I get shot.
- 09-20-2008, 01:18 PM #3
Member
- Join Date
- Sep 2008
- Posts
- 16
- Rep Power
- 0
I remember that there is a Graphic class in java which you can use to finish this task.
- 09-20-2008, 03:42 PM #4
Member
- Join Date
- Sep 2008
- Posts
- 21
- Rep Power
- 0
- 09-20-2008, 11:15 PM #5
Member
- Join Date
- Jun 2008
- Posts
- 48
- Rep Power
- 0
Here wat i tried -- >
class 1 -->
import java.awt.MediaTracker;
public class one extends Toolkit {
Toolkit tk=Toolkit.getDefaultToolkit();
imgage img;
img=th.createimage("c:/ss.jpg");
MediaTracker t= new MediaTracker(this);
t.addImage(img,2);
t.waitForID(2);
int w= img.getWidth (null);
int h= img.getHeight (null) ;
int []pixels = new int[w * h] ;
}
class 2-->
import java.awt.MediaTracker;
import java.awt.image.PixelGrabber;
public class imagetest2 extends PixelGrbber {
public static void main(String [] a) {
one n=new one();
PixelGrabber pg = new PixelGrabber (n.img ,0 ,0 , n.w , n.h , n.pixels , 0 ,n.w);
pg.grabPixels();
}
}
- 09-21-2008, 09:17 PM #6
Member
- Join Date
- Sep 2008
- Location
- Amsterdam
- Posts
- 4
- Rep Power
- 0
Class one is not a valid class. It's missing a constructor and methods. Furthermore, I wouldn't create a separate class for this functionality.
Take a look at API spec for PixelGrabber, it should help you in the right direction. While you're there, check class ImageIO for a more up to date way to load image files.
Good luck,
Michiel
- 09-22-2008, 06:45 AM #7
Member
- Join Date
- Jun 2008
- Posts
- 48
- Rep Power
- 0
I tried some But unable to get back the Image --> Applet not Initialized
/* <applet code=HistoGrab.class width=600 height=600> </applet> */
import java.applet.*;
import java.applet.Applet;
import java.awt.* ;
import java.awt.Toolkit;
import java.awt.image.* ;
public class HistoGrab extends Applet {
Dimension d;
Image img;
int iw, ih;
int pixels[];
int w, h;
int hist[] = new int[256];
int max_hist = 0;
public void init() {
d = getSize();
w = d.width;
h = d.height;
try {
Toolkit tk = Toolkit.getDefaultToolkit(); // Binds the Compontes of dyanmic Changes
img = getImage(getDocumentBase(), getParameter("c:/ss.Bitmap Image"));
// img = getImage ("c:/ss.JPEG");
MediaTracker t = new MediaTracker(this); // Keeps the Status of components
t.addImage(img, 0); // Passing image obj. & index
t.waitForID(0); // Method wait for all the images to be loaded
t.isErrorID(0); // Returns error if any in loading ID 0
iw = img.getWidth(null); // Media observer waiting for img to be Loaded & image width or -1 if not .
ih = img.getHeight(null);
pixels = new int[iw * ih];
PixelGrabber pg = new PixelGrabber(img, 0, 0, iw, ih,pixels, 0, iw);
pg.grabPixels();
for(int i:pixels)
System.out.println( pixels[i] );
} catch (InterruptedException e) { };
for (int i=0;i<iw*ih;i++ ) {
int p = pixels[i];
int r = 0xff & (p >> 16);
int g = 0xff & (p >> 8);
int b = 0xff & (p);
int y = (int) (.33 * r + .56 * g + .11 * b); // Gray Scale conversition
hist[y]++;
}
for (int i=0; i<256; i++) { // Binarization
if (hist[i] > max_hist)
max_hist = hist[i];
}
}
// public void update() {}
public void paint(Graphics g) {
g.drawImage(img, 0, 0, null);
int x = (w - 256) / 2;
int lasty = h - h * hist[0] / max_hist;
for (int i=0; i<256; i++, x++) {
int y = h - h * hist[i] / max_hist;
g.setColor(new Color(i, i, i));
g.fillRect(x, y, 1, h);
g.setColor(Color.red);
g.drawLine(x-1,lasty,x,y);
lasty = y;
}
}
}
/* public static void main(String []a) {
HistoGrab g= new HistoGrab();
}
*/
pplet not Initialized ..
- 09-22-2008, 01:32 PM #8
Member
- Join Date
- Sep 2008
- Location
- Amsterdam
- Posts
- 4
- Rep Power
- 0
1. Please put your code inside code blocks when you post; it makes it easier for us to read it.
2. You have a call to method getImage(..) but where is that method defined?
3. Never use an empty catch block, because now you don't know what's going wrong! Use ex.printStackTrace() inside your catch block, you'll get a hint where to look next...
Similar Threads
-
Modified Pixels
By monkey04 in forum Java 2DReplies: 1Last Post: 03-12-2009, 08:15 AM -
How to convert between SWT Image and AWT BufferedImage
By Java Tip in forum SWTReplies: 0Last Post: 07-02-2008, 08:06 PM -
Blurring pixels
By tim in forum New To JavaReplies: 0Last Post: 01-01-2008, 02:06 PM -
Counting Pixels
By shaungoater in forum Java 2DReplies: 5Last Post: 11-29-2007, 05:51 PM -
Deleting certain image pixels..
By Brightside in forum New To JavaReplies: 1Last Post: 05-22-2007, 09:21 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks