Dithering

Résolu
superismali Messages postés 38 Date d'inscription mercredi 1 décembre 2004 Statut Membre Dernière intervention 8 janvier 2007 - 23 mars 2006 à 09:25
superismali Messages postés 38 Date d'inscription mercredi 1 décembre 2004 Statut Membre Dernière intervention 8 janvier 2007 - 23 mars 2006 à 09:47
Bonjour tout le monde,
j'ai trouvé ce code
public static void Dithering(Bitmap bitmap)
{
int width = bitmap.Width;
int height = bitmap.Height;

//le pattern à appliquer (il était à l'origine destiné à des niveaux de gris de 64)
byte[][] pattern = new byte[][]{ new byte[]{0,32,8,40,34,2,10,42},
new byte[]{48,16,56,24,50,18,58,26},
new byte[]{12,44,4,36,14,46,6,38},
new byte[]{60,28,52,20,62,30,54,22},
new byte[]{3,35,11,43,1,33,9,41},
new byte[]{51,19,59,27,49,17,57,25},
new byte[]{15,47,7,39,13,45,5,37},
new byte[]{63,31,55,23,61,29,53,21}};

unsafe
{
BitmapData bmpData = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

byte* newPixel = (byte*)(void*)bmpData.Scan0;
int offset = width % 4;

for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
//on récupére le niveau de gris sur 255
byte pixel = (byte)(.3 * newPixel[0] + .59 * newPixel[1] + .11 * newPixel[2]);
//on compare le pixel (réduit à 64 niveaux) au pattern (en fonction de sa position
//par rapport à l'image
if ((pixel>>2)>pattern[x&7][y&7])
newPixel[0]=newPixel[1]=newPixel[2]=255;
else
newPixel[0]=newPixel[1]=newPixel[2]=0;

newPixel+=3;
}
newPixel += offset;
}
bitmap.UnlockBits(bmpData);
}
}

à l'adresse: http://www.csharpfr.com/code.aspx?ID=30132
elle est trés utile pour moi, mais j'arrive pas à la faire fonctionner.
Et j'ai tjrs ce message d'erreur: " Unsafe code may only appear if compiling with /unsafe"
Qui peu m'expliquer comment détourner ce pb.
Merci et bonne prog ;)

Superismali

1 réponse

superismali Messages postés 38 Date d'inscription mercredi 1 décembre 2004 Statut Membre Dernière intervention 8 janvier 2007
23 mars 2006 à 09:47
Merci pour le code
j'ai trouvé comment le faire fonctionner

Superismali
3
Rejoignez-nous