•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 456,472 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,778 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 341 | Replies: 1
![]() |
•
•
Join Date: Oct 2008
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
I.ve problem with java image processing.I've to convert 2d array into image.I'm using the loadPixels function, but it doesen't work.The Image is never shown on the label.
Please help, here is the code of the loadPixels function:
Any help would be greatly appreciated.
Thanks,
Nina
Please help, here is the code of the loadPixels function:
public static void loadPixels(JLabel label, int[][] pixels) {
// 1. convert to 1-d array
int width = pixels.length;
int height = pixels[0].length;
int i=0; // index into new pixarray
int[] pixarray = new int[width*height];
for (int y=0; y<height; y++)
for (int x=0; x<width; x++)
// these are stored y-major!
pixarray[i++] = pixels[x][y];
// 2. convert 1-d array into Image*/
MemoryImageSource source = new MemoryImageSource(width,height,pixarray,0,width);
imageto=label.createImage(source); // imageto is declared in the top of the class as "private static Image"
// 3. store Image in the JLabel
ImageIcon imic=new ImageIcon(imageto);
//imic=image;
label.setIcon(imic);
} Any help would be greatly appreciated.
Thanks,
Nina
Last edited by Nina* : Oct 1st, 2008 at 8:29 am.
It may simply be a matter of incorrectly specifying the pixel values, because when I use this code (from the example in the MemoryImageSource API) in place of your loop to fill 'pixarray' from the pixels param, it works just fine.
for (int y = 0; y < height; y++) {
int red = (y * 255) / (height - 1);
for (int x = 0; x < width; x++) {
int blue = (x * 255) / (width - 1);
pixarray[i++] = (255 << 24) | (red << 16) | blue;
}
}![]() |
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Using an array in Javascript (JavaScript / DHTML / AJAX)
- display image from databse (MySQL)
- Image Array Issue..... Any ideas??? (Java)
- Image in database (PHP)
- how to display one image per day from an array? (JSP)
- php mysql image again PLEASE HELP (PHP)
- Php Mysql Image Question (PHP)
- Code for Image Processing (C)
Other Threads in the Java Forum
- Previous Thread: coding in java...need help
- Next Thread: Logic circuit builder



Linear Mode