Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Image EncryptText(Bitmap img, string text)
- {
- // Size of image :
- int height = img.Height;
- int width = img.Width;
- // Length of string :
- int len = text.Length;
- // Image Response :
- Bitmap response = img;
- // Check if there is the place to incode text
- bool validArguments = (height * width >= len * 1.5 );
- if (validArguments)
- {
- Console.WriteLine("Start encrypt text ...");
- // Create a liste of 4bit Code of string
- int lenBuffer = 2 * len + 2;
- int[] buffer = new int[lenBuffer];
- for (int i = 0; i < len ; i++)
- {
- buffer[2*i] = text[i] / 16;
- buffer[2*i + 1] = text[i] % 16;
- }
- // Encode the text in the image
- int itt = 0;
- int selectColor = 0;
- while (itt < lenBuffer)
- {
- Color oldPixel = img.GetPixel(itt % width, itt / width);
- int r = oldPixel.R;
- int g = oldPixel.G;
- int b = oldPixel.B;
- if(selectColor == 0)
- {
- r = ((oldPixel.R / 16) * 16) + buffer[itt];
- }
- else if (selectColor == 1)
- {
- g = ((oldPixel.G / 16) * 16) + buffer[itt];
- }
- else if (selectColor == 2)
- {
- b = ((oldPixel.B / 16) * 16) + buffer[itt];
- }
- Color newPixel = Color.FromArgb(oldPixel.A, r, g, b);
- response.SetPixel(itt % width, itt / width, newPixel);
- selectColor++;
- if(selectColor%3 == 0)
- {
- selectColor = 0;
- itt++;
- }
- }
- }
- Console.WriteLine("Done Encrypt text");
- return response;
- }
Advertisement
Add Comment
Please, Sign In to add comment