D'abord, vous devez utiliser WritableBitmap
pour obtenir la collecte de pixels: WriteableBitmap bmp = new WriteableBitmap(bitmapImageObj);
. Chaque pixel est représenté sous la forme d'un entier de 32 bits. J'ai fait la structure, qui aide juste à diviser l'entier en quatre octets (ARGB).
struct BitmapPixel
{
public byte A;
public byte R;
public byte G;
public byte B;
public BitmapPixel(int pixel)
: this(BitConverter.GetBytes(pixel))
{
}
public BitmapPixel(byte[] pixel)
: this(pixel[3], pixel[2], pixel[1], pixel[0])
{
}
public BitmapPixel(byte a, byte r, byte g, byte b)
{
this.A = a;
this.R = r;
this.G = g;
this.B = b;
}
public int ToInt32()
{
byte[] pixel = new byte[4] { this.B, this.G, this.R, this.A };
return BitConverter.ToInt32(pixel, 0);
}
}
Voici un exemple de la façon dont il pourrait être utilisé pour changer la valeur rouge:
BitmapPixel pixel = new BitmapPixel(bmp.Pixels[0]);
pixel.R = 255;
bmp.Pixels[0] = pixel.ToInt32();
Je voudrais aussi mentionner que WriteableBitmap.Pixels sont en Prémultiplié format RGB. This article expliquera ce que cela signifie. Et voici comment la rémunération fait en utilisant la structure pixel binaire:
public static void CompensateRGB(int[] pixels)
{
for (int i = 0; i < pixels.Length; i++)
{
BitmapPixel pixel = new BitmapPixel(pixels[i]);
if (pixel.A == 255 || pixel.A == 0)
continue;
if (pixel.R == 0 && pixel.G == 0 && pixel.B == 0)
{
// color is unrecoverable, get rid of this
// pixel by making it transparent
pixel.A = 0;
}
else
{
double factor = 255.0/pixel.A;
pixel.A = 255;
pixel.R = (byte)(pixel.R * factor);
pixel.G = (byte)(pixel.G * factor);
pixel.B = (byte)(pixel.B * factor);
}
pixels[i] = pixel.ToInt32();
}
}
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapimage_methods.aspx Il est sur MSDN , mais oui, il ne semble pas être disponible dans Silverlight. – Rafe
Le lien que vous avez fourni est pour .NET 3.5, pas Silverlight. Vous pouvez trouver la documentation MSDN pour la classe Silvermap BitmapImage ici: http://msdn.microsoft.com/fr-fr/library/system.windows.media.imaging.bitmapimage(VS.96).aspx – markti