O
Omatase
I am trying to code functionality that will trim transparent or white
pixels from the sides of an image. I already have cropping code that
works well but I can't find any code to analyze the pixels one at a
time to determine how much to crop.
Here is some code I found using CopyPixels, but I can't find any
information about how to use the returned pixels.
for (int i = 0; i < image.Height; i++)
{
Int32Rect currentSample = new Int32Rect(0, i, (int)image.Width,
1);
byte[] pixels = new byte[4];
int stride = (image.PixelWidth * image.Format.BitsPerPixel + 7) /
8;
image.CopyPixels(new Int32Rect((int)i, (int)1, 1, 1), pixels,
stride, 0);
}
I think I'm telling it to grab the first pixel in the image with this
code, but there isn't really any good info on using CopyPixels out
there. And if I'm correct, that I'm only grabbing the first pixel,
then it's more confusing as to why my pixel array has 4 bytes in it. I
am assuming that means it's a 32 bit color and is just being
represented that way but I don't know for sure.
If anyone can shed some light on this CopyPixel method or on an easier
way to accomplish what I'm trying to do, please help, thanks.
pixels from the sides of an image. I already have cropping code that
works well but I can't find any code to analyze the pixels one at a
time to determine how much to crop.
Here is some code I found using CopyPixels, but I can't find any
information about how to use the returned pixels.
for (int i = 0; i < image.Height; i++)
{
Int32Rect currentSample = new Int32Rect(0, i, (int)image.Width,
1);
byte[] pixels = new byte[4];
int stride = (image.PixelWidth * image.Format.BitsPerPixel + 7) /
8;
image.CopyPixels(new Int32Rect((int)i, (int)1, 1, 1), pixels,
stride, 0);
}
I think I'm telling it to grab the first pixel in the image with this
code, but there isn't really any good info on using CopyPixels out
there. And if I'm correct, that I'm only grabbing the first pixel,
then it's more confusing as to why my pixel array has 4 bytes in it. I
am assuming that means it's a 32 bit color and is just being
represented that way but I don't know for sure.
If anyone can shed some light on this CopyPixel method or on an easier
way to accomplish what I'm trying to do, please help, thanks.