SetPixel equivalence sur WPF
Salut tout le monde,
bon voila je suis sur WPF et j'aimerais reproduire une methode que j'ai eu a faire sur du Windows Forms voici le code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| private void Button(object sender, EventArgs e)
{
int i, j;
Bitmap bmp = new Bitmap(255, 255);
for (i = 0; i < 255; i++)
{
for (j = 0; j < 255; j++)
{
bmp.SetPixel(j, i, Color.FromArgb(255-j, 0, j));
}
}
Graphics g = pictureBox6.CreateGraphics();
g.DrawImage(bmp, 0, 0);
g.Dispose();
} |
j'ai essaye avec cette methode ci :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
private void button(object sender, RoutedEventArgs e)
{
PixelFormat pf = PixelFormats.Bgra32;
int _width = 20;
int _height = 20;
byte[] pixelData = new byte[_width*_height];
for (int y = 0; y < _height; ++y )
{
int yIndex = y * _width;
for (int x = 0; x < _width; x++)
{
pixelData[x + yIndex] = (byte)(x + y);
}
}
BitmapSource bmp = BitmapSource.Create(_width, _height, 300, 300, pf, null, pixelData, _width);
image1.Source = bmp;
} |
Mais ca ne me donnes pas le resultat escompte... Y aurais til une maniere de refaire le premier Code[winforms] aussi sur WPF?
y a til une maniere d'ecrire
Code:
SetPixel(j, i, Color.FromArgb(255-j, 0, j));
sous WPF??
Merci