Yes I have to use C++.
Pixels are the elements of array.
I am not able to shrink.
Would u please tell me the suitable code or algorithm to shrink the image.
You can interpolate the pixels, which is a fancy word that means "take the average of Rs over a block, the average of Gs over the block, and the average of Bs over a block"
That is, if you had 9 pixels, and wanted to convert those to 1 pixel, you would just average the color components. This gives you a 3 to 1 reduction in size.
that is a decent method.
But it isnt what you asked :)
Your problem is:
if(array[row][col] % 2 != 0)
I think you wanted
if(row%2 == 0 && col%2==0)
{
keep the pixel
}
and the loops shouldn't divide by 2.
basically you need to loop over ALL the pixels, and only keep half of them. So the loops go over everything, and the keep logic tosses out every other one in both dimensions... right?
also have no idea what you have here, but a typical image is at least 3 bytes / pixel. If this is greyscale, or you have wrappers that I don't understand, it may be fine.... if it is colors and that loop is over bytes, it is wrong.