[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Need help getting a picture to flip in Java. How do I do it?
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /wsr/ - Worksafe Requests

Thread replies: 10
Thread images: 3
File: 80s_Robot_Tab_Coke.jpg (320 KB, 1310x996) Image search: [Google]
80s_Robot_Tab_Coke.jpg
320 KB, 1310x996
Need help getting a picture to flip in Java. How do I do it? Here's my code

* Horizontal flip method
* In this method, I've given you the basic structure of how things will look. There are a few incomplete assignments inside of the method. It is your job to figure out how to complete those assignments!
* This method works almost like the horizontal mirroring method you saw in your text book (pg 135), but instead of mirroring on the middle of the image, we want to flip it all the way.
* Hint: Why do we need tempColor in this case? I encourage you to reflect on this question if you find your method not working the way it should!**/
public void flipHorizontal()
{
Color tempColor;

//FILL THESE OUT AND THEN UNCOMMENT THEM!
int limit1 = this.getHeight();
int limit2 = this.getWidth();
Pixel leftPixel = null;
Pixel rightPixel = null;


for(int i = 0; i < limit1; i++)
{
for(int j = 0; j < limit2; j++)
{
leftPixel = getPixel(i,j);
rightPixel = getPixel(limit2 - 1 - i,j);
rightPixel.setColor(leftPixel.getColor());
//FILL THIS OUT AND THEN UNCOMMENT IT!
//tempColor =
//After you store away your pixel colors...call setColor() here on the appropriate pixels and flip the picture!

}
}

Shit's definitely not working.
>>
>>46712
>Shit's definitely not working.
What did you do with tempColor?

If you're still confused:
Imagine you have strings stored in variables a and b. How would you swap the values?
>>
>>46714
I didn't do anything with tempColor, and I'm honestly not even sure why it's there.

do I have to set tempcolor as variable a, then set a to b, then b to tempcolor?
>>
>>46720
Yeah. Get yourself a rubber duck, son.
>>
>>46721
I'm getting this error when I try to run my code calling flipHorizontal.
>>
>>46734
Nevermind, I fixed this by using a different picture. Now I'm just having an issue of swapping the shit. I don't get it. Here's what I have:

tempColor = leftPixel.getColor();
tempColor2 = rightPixel.getColor();
leftPixel.setColor(tempColor2);
rightPixel.setColor(tempColor);

I've got no ideas.
>>
>>46753
If I leave one of them out, whatever side of the image is supposed to be flipped will flip (if I leave in right pixel it changes to the left side of the image), but if I leave them both in they just cancel each other out.

Bumping one last time for hope.
>>
bumpin this
>>
File: image.jpg (43 KB, 400x321) Image search: [Google]
image.jpg
43 KB, 400x321
>>46794
Okay, anon.

Imagine you have a glass of Grape Kool-Aid and a mug of Cherry Kool-Aid.

You decide the Cherry Kool-Aid needs to be in the glass, and the Grape in the mug.

So you pour the glass of Grape into the mug, and then you pour the mug of.... wait, that doesn't work.

You pour the mug of Cherry into the glass, then you pour the glass of.... wait, that doesn't work either.

Guess you'll need an extra glass.

tldr:
Object o; o=p1; p1=p2; p2=o;
>>
>>47208
tempColor = leftPixel.getColor();
leftPixel.setColor(rightPixel.getColor());
rightPixel.setColor(tempColor);

Isn't tempColor my third container in this case? But when I put in that code it just cancels each other out and nothing happens.
Thread replies: 10
Thread images: 3

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.