Hey guys im working with a program that does manipulations to simple images( in PPM format). Im trying to crops an image by a rectangle thats (x1,y1),(x2,y2). The image is 38 by 39, but I started the 2-d at [0][0]. When I crop the entire image x1=0; y1=38; x2=37; y2=0. It works fine, it just makes a cope of the original image.
Here is the code.
after that it calls a function to load the date into a file....Code:void graphics::crop(int x1,int y1,int x2, int y2) { int i,j; xsize=((x2-x1)+1); ysize=((y1-y2)+1); cout<<xsize<<endl; cout<<ysize<<endl; for(i=0;i<xsize;i++) { for(j=0;j<ysize;j++) { plot[i][j].red = plot[x1+i][y2+j].red; plot[i][j].green= plot[x1+i][y2+j].green; plot[i][j].blue = plot[x1+i][y2+j].blue; } } }
If I try to crop a smaller part of the image it becomes blured. Any ideas?Code:void graphics::storePPM() { int i,j; //cout<<"in store"<<endl; ofstream outFile; outFile.open("output.PPM"); if (outFile.fail()) { cout << "Unable to open output file" << endl; } outFile<<"P3"<<endl; outFile<<"# This file was made using graphics program by Chris Donlan"<<endl; outFile<<xsize<<" "<<ysize<<endl; for(i=0;i<xsize;i++) { for(j=0;j<ysize;j++) { outFile<<plot[i][j].red<<endl;; outFile<<plot[i][j].green<<endl; outFile<<plot[i][j].blue<<endl; } } outFile<<"\r"; }
Thanks
Chris



LinkBack URL
About LinkBacks


