Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void ImageNormalizeColours(string input, string output)
- {
- System.Drawing.Bitmap inputbm = new System.Drawing.Bitmap(input);
- int h = 0;
- for (int image_height = 0; image_height < inputbm.Height; image_height++)
- {
- for (int image_width = 0; image_width < inputbm.Width; image_width++)
- {
- System.Drawing.Color pixel_colour = inputbm.GetPixel(image_width, image_height);
- if (pixel_colour.R > h) h = pixel_colour.R;
- if (pixel_colour.G > h) h = pixel_colour.G;
- if (pixel_colour.B > h) h = pixel_colour.B;
- }
- }
- for (int image_height = 0; image_height < inputbm.Height; image_height++)
- {
- for (int image_width = 0; image_width < inputbm.Width; image_width++)
- {
- System.Drawing.Color pixel_colour = inputbm.GetPixel(image_width, image_height);
- int r = 255 / h * pixel_colour.R;
- int g = 255 / h * pixel_colour.G;
- int b = 255 / h * pixel_colour.B;
- pixel_colour = System.Drawing.Color.FromArgb(r, g, b);
- inputbm.SetPixel(image_width, image_height, pixel_colour);
- }
- }
- inputbm.Save(output);
- }
- public static void TwoLSBSteganographyInserter(string inputImageFilename, System.Drawing.Bitmap imageToHide, string outputImageFilename)
- {
- System.Drawing.Bitmap input = new System.Drawing.Bitmap(inputImageFilename);
- for (int image_height = 0; image_height < imageToHide.Height; image_height++)
- {
- for (int image_width = 0; image_width < imageToHide.Width; image_width++)
- {
- System.Drawing.Color pixel_colour = imageToHide.GetPixel(image_width, image_height);
- int pixel_byte_r = pixel_colour.R;
- int pixel_byte_g = pixel_colour.G;
- int pixel_byte_b = pixel_colour.B;
- int small_byte_r = SteganographyCompressColourPart(pixel_byte_r, 255, 4) - 1;
- string binary_r = ByteToBinary(small_byte_r).Substring(6, 2);
- int small_byte_g = SteganographyCompressColourPart(pixel_byte_g, 255, 4) - 1;
- string binary_g = ByteToBinary(small_byte_g).Substring(6, 2);
- int small_byte_b = SteganographyCompressColourPart(pixel_byte_b, 255, 4) - 1;
- string binary_b = ByteToBinary(small_byte_b).Substring(6, 2);
- System.Drawing.Color input_pixel_colour = input.GetPixel(image_width, image_height);
- int input_pixel_byte_r = input_pixel_colour.R;
- int input_pixel_byte_g = input_pixel_colour.G;
- int input_pixel_byte_b = input_pixel_colour.B;
- string input_pixel_binary_r = Generic.ByteToBinary(input_pixel_byte_r);
- string input_pixel_binary_g = Generic.ByteToBinary(input_pixel_byte_g);
- string input_pixel_binary_b = Generic.ByteToBinary(input_pixel_byte_b);
- input_pixel_binary_r = input_pixel_binary_r.Substring(0, 6) + binary_r;
- input_pixel_binary_g = input_pixel_binary_g.Substring(0, 6) + binary_g;
- input_pixel_binary_b = input_pixel_binary_b.Substring(0, 6) + binary_b;
- input_pixel_byte_r = BinaryToByte(input_pixel_binary_r);
- input_pixel_byte_g = BinaryToByte(input_pixel_binary_g);
- input_pixel_byte_b = BinaryToByte(input_pixel_binary_b);
- input_pixel_colour = System.Drawing.Color.FromArgb(input_pixel_byte_r, input_pixel_byte_g, input_pixel_byte_b);
- input.SetPixel(image_width, image_height, input_pixel_colour);
- }
- }
- input.Save(outputImageFilename);
- }
- public static void TwoLSBSteganographyExtractor(string input)
- {
- string output = input + ".out." + input.Substring(input.Length - 3, 3);
- TwoLSBSteganographyExtractor(input, output);
- }
- public static void TwoLSBSteganographyExtractor(string input, string output)
- {
- System.Drawing.Bitmap image_bitmap = Generic.CreateNonIndexedImage(new System.Drawing.Bitmap(input));
- for (int image_height = 0; image_height < image_bitmap.Height; image_height++)
- {
- for (int image_width = 0; image_width < image_bitmap.Width; image_width++)
- {
- System.Drawing.Color pixel_colour = image_bitmap.GetPixel(image_width, image_height);
- int pixel_byte_r = pixel_colour.R;
- int pixel_byte_g = pixel_colour.G;
- int pixel_byte_b = pixel_colour.B;
- string pixel_binary_r = Generic.ByteToBinary(pixel_byte_r);
- string pixel_binary_g = Generic.ByteToBinary(pixel_byte_g);
- string pixel_binary_b = Generic.ByteToBinary(pixel_byte_b);
- pixel_binary_r = "000000" + pixel_binary_r.Substring(6, 2);
- pixel_binary_g = "000000" + pixel_binary_g.Substring(6, 2);
- pixel_binary_b = "000000" + pixel_binary_b.Substring(6, 2);
- pixel_byte_r = Generic.BinaryToByte(pixel_binary_r);
- pixel_byte_g = Generic.BinaryToByte(pixel_binary_g);
- pixel_byte_b = Generic.BinaryToByte(pixel_binary_b);
- pixel_colour = System.Drawing.Color.FromArgb(pixel_byte_r, pixel_byte_g, pixel_byte_b);
- image_bitmap.SetPixel(image_width, image_height, pixel_colour);
- }
- }
- image_bitmap.Save(output);
- }
- public static System.Drawing.Bitmap CreateNonIndexedImage(System.Drawing.Image src)
- {
- System.Drawing.Bitmap newBmp = new System.Drawing.Bitmap(src.Width, src.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
- using (System.Drawing.Graphics gfx = System.Drawing.Graphics.FromImage(newBmp))
- {
- gfx.DrawImage(src, 0, 0);
- }
- return newBmp;
- }
- public static string ByteToBinary(int b)
- {
- return Convert.ToString(b, 2).PadLeft(8, '0');
- }
- public static int BinaryToByte(string binary)
- {
- int r = Convert.ToInt32(binary, 2);
- return r;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement