Advertisement Jump to content
Sign in to follow this  

image editing

This topic is 5132 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi, i'm really new at image processing and i was hoping that someone here could teach me, or lend me any JAVA or C code which will allow me to edit an image pixel by pixel. i would really appreciate all the help i can get. thank you very much. p.s. this is for my undergraduate thesis... i nid help. thanks again.

Share this post

Link to post
Share on other sites
This code reads a 32-bit RGBA .tga image, and lets you manipulate the pixels. It does not error-check the format (i e, other formats will cause undefined behavior):

#include <stdio.h>

class TgaImage {

unsigned short tgaHeader[9];
unsigned int * pixels;
unsigned int xSize;
unsigned int ySize;


TgaImage( char const * path ) {
FILE * f = fopen( path, "rb" );
fread( tgaHeader, 2, 9, f );
xSize = tgaHeader[6];
ySize = tgaHeader[7];
pixels = new unsigned int[ xSize*ySize ];
fread( pixels, 4, xSize*ySize, f );
fclose( f );
~TgaImage() {
delete[] pixels;

unsigned int pixelAt( unsigned int x, unsigned int y ) const {
return pixels[x+y*xSize];

void setPixelAt( unsigned int x, unsigned int y, unsigned int pixel ) {
pixels[x+y*xSize] = pixel;


On x86 hardware, the pixel format is 0xaarrggbb, i e 0xff000000 would be opaque black, and 0x0000ff00 would be bright green.

Disclaimer: I typed this code into the posting box from scratch.

Share this post

Link to post
Share on other sites
thanks, i wil try that. ü anyway, describing specifically what i plan to do: i actually nid a (java or c) code snippet because i will just be embedding that method into a larger system. i have just a implemented a skin color detection program and the output of that program is that it identifies each pixel as to whether it is under skin color or not. what i would like to do is to edit the same image that i used, convert all pixels that were determined to be skin into white and all the rest into black, is there any way to do that? thanks.

Share this post

Link to post
Share on other sites
Use an image processing library such as NexgenIPL (click "Products" in the navigation bar to get to the download page). Writing your own image load/save/manipulation code is time-consuming and error-prone. A library that takes care of this part will let you focus on your manipulation algorithm.

Good luck,

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!