Click here to Skip to main content
15,892,161 members
Articles / Multimedia / GDI+

Steganography 12 - Regions with different data density

Rate me:
Please Sign up or sign in to vote.
4.81/5 (26 votes)
12 Jul 2006CPOL6 min read 114.1K   2.5K   61  
Define regions inside an image to keep smooth colours free from hidden data.
/* This class has been written by
 * Corinna John (Hannover, Germany)
 * cj@binary-universe.net
 * 
 * You may do with this code whatever you like,
 * except selling it or claiming any rights/ownership.
 * 
 * Please send me a little feedback about what you're
 * using this code for and what changes you'd like to
 * see in later versions. (And please excuse my bad english.)
 * 
 * WARNING: This is experimental code.
 * Some bugs and flaws have been left in there,
 * to keep the code readable to people who want
 * to understand the algorithm.
 * Please do not expect "Release Quality".
 * */

#region Using directives

using System;
using System.Collections;
using System.Drawing;
using System.Drawing.Drawing2D;

#endregion

namespace SteganoRegion
{
    public class RegionInfo
    {
        private Region region;
        private Point[] points;
        private ArrayList pixels = new ArrayList();
        private Size imageSize;
        private int capacity = 1;
        private byte countUsedBitsPerPixel = 1;

        public Region Region
        {
            get { return region; }
        }

        public Point[] Points
        {
            get { return points; }
        }

        public int Capacity
        {
            get { return capacity; }
            set { capacity = value; }
        }

        public byte CountUsedBitsPerPixel
        {
            get { return countUsedBitsPerPixel; }
            set { countUsedBitsPerPixel = value; }
        }

        public long CountPixels
        {
            get { return pixels.Count; }
        }

        public ArrayList PixelIndices
        {
            get { return pixels; }
        }

        public decimal PercentOfImage
        {
            get
            {
                return (100 * (decimal)pixels.Count / (imageSize.Width * imageSize.Height));
            }
        }

        public RegionInfo(GraphicsPath path, Point[] points, Size imageSize)
        {
            this.region = new Region(path);
            this.points = points;
            this.imageSize = imageSize;
            UpdateCountPixels();
        }

        public RegionInfo(Region region, int capacity, byte bitsPerPixel, Size imageSize)
        {
            this.region = region;
            this.capacity = capacity;
            this.countUsedBitsPerPixel = bitsPerPixel;
            this.imageSize = imageSize;
            UpdateCountPixels();
        }

        public void AddPoints(Point[] addPoints)
        {
            Point[] newPoints = new Point[points.Length + addPoints.Length];
            points.CopyTo(newPoints, 0);
            addPoints.CopyTo(newPoints, points.Length);
            points = newPoints;
        }

        /*public void UpdateCountPixels(GraphicsPath path)
        {
            pixels.Clear();
            RectangleF box = path.GetBounds();
            for (int y = (int)box.Top; y < box.Bottom; y++)
            {
                for (int x = (int)box.Left; x < box.Right; x++)
                {
                    if (path.IsVisible(x, y))
                    {
                        pixels.Add(GetPixelIndex(x, y)); //new Point(x,y));
                    }
                }
            }
            pixels.Sort();
        }*/

        public void UpdateCountPixels()
        {
            pixels.Clear();
            for (int y = 0; y < imageSize.Height; y++)
            {
                for (int x = 0; x < imageSize.Width; x++)
                {
                    if (region.IsVisible(x, y))
                    {
                        pixels.Add(GetPixelIndex(x, y)); //new Point(x,y));
                    }
                }
            }
            pixels.Sort();
        }

        /*public void UpdateCountPixels(Graphics graphics)
        {
            pixels.Clear();
            RectangleF box = region.GetBounds(graphics);
            for (int y = (int)box.Top; y < box.Bottom; y++)
            {
                for (int x = (int)box.Left; x < box.Right; x++)
                {
                    if (region.IsVisible(x, y))
                    {
                        pixels.Add(GetPixelIndex(x, y)); //new Point(x,y));
                    }
                }
            }
            pixels.Sort();
        }*/

        private int GetPixelIndex(int x, int y)
        {
            return x + (y * imageSize.Width);
        }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Germany Germany
Corinna lives in Hanover/Germany and works as a C# developer.

Comments and Discussions