Imaging

Hi,
Last edited on
Any help appreciated
> borderedImage(PixelGrid);
What does this do?

Is it some function in ImageHandle.h or something you're supposed to write yourself.

Do you want to add a border to an existing image (making the image wider and taller), say

PPPPP
PPPPP
PPPPP
PPPPP

becomes
BBBBBBB
BPPPPPB
BPPPPPB
BPPPPPB
BPPPPPB
BBBBBBB


Or do you want to overwrite the edge leaving the image the same width and height

PPPPP
PPPPP
PPPPP
PPPPP

becomes
BBBBB
BPPPB
BPPPB
BBBBB

Thanks for your reply. So basically I have an image 'Airplane.png' which is displayed as normal when the above program is ran.

I have only written >borderedImage(PixelGrid) as preparation for the code to add a border, so it is not in ImageHandle.h or anything. I haven't added any code yet to add a border as I don't know where to start for it.

I would like to add a border round the image 3 pixels wide, making the image taller and wider.

Thanks in advance.
(Please disregard lines 25-34 of code as I don't actually need them and forgot to remove them for original post, which basically leaves the code saying 'add a border to the image and save this new image as BorderedAirplane.png' - obviously the only part missing now is the code to actually add the border to the image.
Last edited on
Perhaps you could start with
1
2
3
4
5
6
// How wide you want the border
const int BORDER_WIDTH = 3;
// A grid able to hold existing grid with a border
unsigned PixelGridWithBorder[WIDTH+BORDER_WIDTH*2][HEIGHT+BORDER_WIDTH*2]; 
// Create the new image
borderedImage(PixelGrid,PixelGridWithBorder);


Though I suspect you've got width/height the wrong way round in the array definition.
One would normally expect unsigned PixelGrid[HEIGHT][WIDTH]; as pixels are usually stored in row order.

Where do you get HEIGHT and WIDTH from?
the sides wrap around if you set it up the right way. eg, say you wanted to do 3 pixel boarder, then you write the last 3 on a row and the next 3 of the next row are sequential in memory, so you can do them all at once rather than do like a left side loop and a right side loop. Top and bottom are sometimes doable with block memory functions, depending on how the data is set up. Lines across are full blocks; 3 lines is one continuous pointer in other words. So the whole thing can be done with 2 block memory statements for top and bottom and one loop to do both sides, if you want to compact it for efficiency and code simplification.

the above is more suitable if you want to change the edge pixels into a boarder, instead of increase the image size.
to increase its size, make a new image and flood fill it to the boarder color first.
then copy the old image, line by line with the block copy (eg memcpy) type operations at the correct starting row.
Last edited on
line 13 is nonsense to the compiler.

borderedImage(PixelGrid,PixelGridWithBorder);

if this is a class object with a constructor, it is missing a type.
if it is a function call, you can't do that outside of main (or more precisely outside of code blocks like any function).
Last edited on
Topic archived. No new replies allowed.