Results 1 to 1 of 1
Thread: Picture manipulating help
- 03-26-2011, 06:47 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 1
- Rep Power
- 0
Picture manipulating help
I was working on a project but I got stuck. I wanted to show 2 rows of picture with 3 column. But when ever I change the number for colume, it only create blank white space and no image there. The first row works fine. How can if fix this?
Below are my code
/**
test file
*/
// import statements - tells the Java Compiler what special libraries we are using
import java.awt.Color;
// Note the name of the class in the following line MUST
// match the name of the file.
public class test
{
public static void main (String[] args)
{
String filename = FileChooser.pickAFile ();
Picture original = new Picture ( filename );
Picture modified;
modified = manipulate (original);
modified.show ();
}
//method
public static Picture manipulate ( Picture p1 )
{
int repeatCount = 3;
int rowCount=2;
int width = p1.getWidth();
int height = p1.getHeight();
/* this is where it give me the problem. I can make the first row show up but not the second. it suppose to look like = , instead I have -.
if I multiply 3 * height, it create blank white space and not the picture.
*/
Picture p2 = new Picture ( (repeatCount*width) ,(int)2*height);
int xPos, yPos;
Color c1, c2, c3, c4;
for ( xPos = 0 ; xPos < width ; xPos ++ )
{
for ( yPos = 0 ; yPos < height ; yPos ++ )
{
Pixel pix1, pix2;
int modifiedX;
int modifiedY;
pix1 = p1.getPixel (xPos, yPos);
c1 = pix1.getColor ();
int index;
for ( index = 0 ; index < repeatCount ; ++index )
{
// store original information into the same position on "copy"
modifiedX = (index * width) + xPos;
pix2 = p2.getPixel (modifiedX, yPos);
if ( index == 1)
{
c2 = modifyColor2 ( c1 );
}
else if (index == 2)
{
c2 = modifyColor1 ( c1 );
}
else
{
c2 = c1;
}
pix2.setColor ( c2 );
}
}
}
return p2;
} // end of method
public static Color modifyColor1 (Color c)
{
int red, green, blue;
red = c.getRed();
green = c.getGreen();
blue = c.getBlue();
return new Color (green, blue, red);
}
public static Color modifyColor2 (Color c)
{
int red, green, blue;
red = c.getRed();
green = c.getGreen();
blue = c.getBlue();
return new Color (255 - red, 255 - green, 255 - blue);
}
} // end of class
Similar Threads
-
Manipulating BufferedImage
By ace_quorthon in forum Java 2DReplies: 1Last Post: 01-08-2011, 04:35 PM -
Manipulating URLs
By TheFlying_Boy in forum NetworkingReplies: 0Last Post: 08-03-2009, 05:01 PM -
Manipulating XML
By JosephMConcepcion in forum XMLReplies: 2Last Post: 04-26-2009, 12:01 AM -
Manipulating String Tokenizer
By Bomber_Will in forum New To JavaReplies: 2Last Post: 04-19-2009, 11:54 PM -
manipulating a string (Urgent)
By ariz in forum New To JavaReplies: 4Last Post: 03-31-2009, 05:00 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks