• Popular Now

• 13
• 14
• 27
• 9
• 9

Archived

This topic is now archived and is closed to further replies.

Image flipping

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

Recommended Posts

Hi! In my application I use this code to flip a 24-bit image vertical(upside-down): int BytesPerLine = ImageWidth*3; //Copy the data to a temporary place memcpy(TempImage, ImageData, ImageSize); //Flip the image for (UINT y = 0; y < ImageHeight; y++) memcpy(&ImageData[((ImageHeight - 1) - y) * BytesPerLine], &TempImage[y * BytesPerLine], BytesPerLine); //Free the temporary image free(TempImage); Now, if I want to flip the image horizontal instead of vertical, how would I do that? Thanks in advance.

Share on other sites
Do the same thing, but per pixel left to right. Then go to the next line down.

Share on other sites
Hmmmm, I don''t seem to get it right... I don''t think I understood what you meant. Maybe you could you post the modified code? That''d be great!

Share on other sites
Help would really be apreciated!
I just don''t seem to get it right.

Share on other sites
To lazy to read and then mod the code so...

You get the number of pixels on the x axis in the image as your starting point for coping. Begin to copy from that starting point on the original and place the pixel at 0,0 on the copy, increment the position on the x axis you copy to as you pull pixels from the original and repeat the process for each line of the image top to bottom.

Share on other sites
He means you copy the data a pixel at a time.

  //Copy the data to a temporary placememcpy(TempImage, ImageData, ImageSize);//Flip the image HORIZONTALLYfor (UINT y = 0; y < ImageHeight; y++) for (UINT x = 0; x < ImageWidth; x++) ImageData[y * BytesPerLine + (x*3)] = TempImage[y*BytesPerLine + ((ImageWidth - x)*3)];//Free the temporary imagefree(TempImage);

Thar.

Share on other sites
Ummm, I tried the code, and it almost works. It seems like only the blue colors are flipped.
Here''s an example:
wallsoft.form08.com/original.jpg --- Original image
wallsoft.form08.com/flipped.jpg --- Flipped image

Any suggestions would be apreciated, I''m killing myself over here... =)

Share on other sites
Without reading the code (Whos the laaaazy one?): Was it a 32 bit image? Maybe you flip the blue and then jump 2 bytes to flip the next blue, but never the red and green.

Share on other sites
HEHEH whoops, hehe yeah I was only flipping one byte of colour.

for a 24 bit image:
  //Copy the data to a temporary place memcpy(TempImage, ImageData, ImageSize); //Flip the image HORIZONTALLY for (UINT y = 0; y < ImageHeight; y++) for (UINT x = 0; x < ImageWidth; x++) memcpy(ImageData + y*BytesPerLine + (x*3), TempImage + y*BytesPerLine + ((ImageWidth - x)*3),3);//Free the temporary imagefree(TempImage);

if you were using a 32 bit image, you would change all the 3''s
to 4''s, a 16 bit image you would change teh 3''s to 2''s etc.

PS. I think the effect you got is WAY cool anyway