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

Need help getting a picture to flip in Java. How do I do it?

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 10
Thread images: 3

File: 80s_Robot_Tab_Coke.jpg (320KB, 1310x996px) Image search: [Google]
80s_Robot_Tab_Coke.jpg
320KB, 1310x996px
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 (43KB, 400x321px) Image search: [Google]
image.jpg
43KB, 400x321px
>>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 posts: 10
Thread images: 3


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

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.