Converting Bitmap

Started by
1 comment, last by TeSsL 14 years, 6 months ago
If an image was converted into ImageMap, how do i convert it back to bitmap? public override ImageMap ConvertToImageMap (IPixelConverter pconv) { ImageMap res = new ImageMap (Width, Height); for (int y = 0 ; y < Height ; ++y) { for (int x = 0 ; x < Width ; ++x) { Color col = bm.GetPixel (x, y); res[x, y] = ((col.r + col.g + col.b) / (255.0 * 3.0)); } } return (res); }
Advertisement
The quick answer is that you can't...

The code you showed is taking the average color (Red + Green + Blue / 3) and setting the imagemap to that value... Therefore, there is no way to get those separate color components back out of the image map.

So basically... Save the original image.

-Alamar
But because the scaling of the images are done in ImageMap format. Then what about doing this in Bitmap?

public ImageMap ScaleDouble ()
{
// Doubling an image with x/y dimensions less or equal than 2 will
// result in an image with just (2, 2) dims, so its useless.
if (xDim <= 2 || yDim <= 2)
return (null);

ImageMap res = new ImageMap (xDim * 2 - 2, yDim * 2 - 2);

// fill four pixels per step, except for the last line/col, which will
// be omitted
for (int y = 0 ; y < (yDim - 1) ; ++y) {
for (int x = 0 ; x < (xDim - 1) ; ++x) {
// pixel layout:
// A B
// C D

res[2 * x + 0, 2 * y + 0] = this[x, y];

res[2 * x + 1, 2 * y + 0] =
(this[x, y] + this[x + 1, y]) / 2.0;

res[2 * x + 0, 2 * y + 1] =
(this[x, y] + this[x, y + 1]) / 2.0;

res[2 * x + 1, 2 * y + 1] = (this[x, y] + this[x + 1, y] +
this[x, y + 1] + this[x + 1, y + 1]) / 4.0;
}
}

return (res);
}

This topic is closed to new replies.

Advertisement