Esempio n. 1
0
        public void LoadGifPicture(string filename)
        {
            Bitmap bmp = (Bitmap)Bitmap.FromFile(filename);

            if (reverse_colours)
            {
                byte[] img = new byte[bmp.Width * bmp.Height * 3];
                BitmapArrayConversions.updatebitmap(bmp, img);
                BitmapArrayConversions.RGB_BGR(img);
                BitmapArrayConversions.updatebitmap_unsafe(img, bmp);
            }
            LoadGifPicture(bmp);
        }
Esempio n. 2
0
        /// <summary>
        /// add some text to the given image
        /// </summary>
        /// <param name="img">colour image into which to insert th text</param>
        /// <param name="img_width">width of the image</param>
        /// <param name="img_height">height of the image</param>
        /// <param name="text">text to be added</param>
        /// <param name="font">font style</param>
        /// <param name="font_size">font size</param>
        /// <param name="r">red</param>
        /// <param name="g">green</param>
        /// <param name="b">blue</param>
        /// <param name="position_x">x coordinate at which to insert the text</param>
        /// <param name="position_y">y coordinate at which to insert the text</param>
        public static void AddText(byte[] img, int img_width, int img_height,
                                   String text,
                                   String font, int font_size,
                                   int r, int g, int b,
                                   float position_x, float position_y)
        {
            Bitmap screen_bmp = new Bitmap(img_width, img_height,
                                           System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            // insert the existing image into the bitmap
            BitmapArrayConversions.updatebitmap_unsafe(img, screen_bmp);

            Font       drawFont  = new Font(font, font_size);
            SolidBrush drawBrush = new SolidBrush(Color.FromArgb(r, g, b));

            Graphics grph = Graphics.FromImage(screen_bmp);

            grph.DrawString(text, drawFont, drawBrush, position_x, position_y);
            grph.Dispose();

            // extract the bitmap data
            BitmapArrayConversions.updatebitmap(screen_bmp, img);
        }
Esempio n. 3
0
        public static void CreateFromStereoPair(
            string left_image,
            string right_image,
            string gif_filename,
            int delay_mS,
            float offset_x,
            float offset_y,
            float scale,
            ref string left_image_filename,
            ref string right_image_filename)
        {
            int n = 0;

            left_image_filename  = left_image;
            right_image_filename = right_image;

            if (scale < 1)
            {
                Bitmap bmp0 = (Bitmap)Bitmap.FromFile(left_image);
                byte[] img0 = new byte[bmp0.Width * bmp0.Height * 3];
                BitmapArrayConversions.updatebitmap(bmp0, img0);
                byte[] img0_scaled = new byte[bmp0.Width * bmp0.Height * 3];
                int    cy0         = bmp0.Height / 2;
                int    cx0         = bmp0.Width / 2;
                n = 0;
                for (int y = 0; y < bmp0.Height; y++)
                {
                    int yy = cy0 + (int)((y - cy0) * scale);
                    for (int x = 0; x < bmp0.Width; x++, n += 3)
                    {
                        int xx = cx0 + (int)((x - cx0) * scale);
                        int n2 = ((yy * bmp0.Width) + xx) * 3;
                        if ((n2 > -1) && (n2 < img0.Length - 3))
                        {
                            img0_scaled[n]     = img0[n2];
                            img0_scaled[n + 1] = img0[n2 + 1];
                            img0_scaled[n + 2] = img0[n2 + 2];
                        }
                    }
                }
                scale = 1;
                bmp0  = new Bitmap(bmp0.Width, bmp0.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                BitmapArrayConversions.updatebitmap_unsafe(img0_scaled, bmp0);
                left_image_filename = left_image.Substring(0, right_image.Length - 4) + "2.bmp";
                bmp0.Save(left_image_filename, System.Drawing.Imaging.ImageFormat.Bmp);
            }

            Bitmap bmp = (Bitmap)Bitmap.FromFile(right_image);

            byte[] img = new byte[bmp.Width * bmp.Height * 3];
            BitmapArrayConversions.updatebitmap(bmp, img);
            byte[] img_offset = new byte[bmp.Width * bmp.Height * 3];
            n = 0;
            int cy = bmp.Height / 2;
            int cx = bmp.Width / 2;

            scale = 1.0f / scale;
            for (int y = 0; y < bmp.Height; y++)
            {
                int yy = cy + (int)((y - cy) * scale);
                for (int x = 0; x < bmp.Width; x++, n += 3)
                {
                    int xx = cx + (int)((x - cx) * scale);
                    int n2 = (((int)(yy + offset_y) * bmp.Width) + (int)(xx + offset_x)) * 3;
                    if ((n2 > -1) && (n2 < img.Length - 3))
                    {
                        img_offset[n]     = img[n2];
                        img_offset[n + 1] = img[n2 + 1];
                        img_offset[n + 2] = img[n2 + 2];
                    }
                }
            }
            bmp = new Bitmap(bmp.Width, bmp.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            BitmapArrayConversions.updatebitmap_unsafe(img_offset, bmp);
            right_image_filename = right_image.Substring(0, right_image.Length - 4) + "2.bmp";
            bmp.Save(right_image_filename, System.Drawing.Imaging.ImageFormat.Bmp);

            List <string> images = new List <string>();

            images.Add(left_image_filename);
            images.Add(right_image_filename);
            CreateAnimatedGif(images, delay_mS, gif_filename);
        }
Esempio n. 4
0
        public static void CreateFromStereoPair(
            string left_image,
            string right_image,
            string gif_filename,
            int delay_mS,
            float offset_x,
            float offset_y,
            float scale,
            float rotation_degrees,
            bool reverse_colours,
            ref string left_image_filename,
            ref string right_image_filename)
        {
            int n = 0;

            left_image_filename  = left_image;
            right_image_filename = right_image;

            if (scale < 1)
            {
                Bitmap bmp0 = (Bitmap)Bitmap.FromFile(left_image);
                byte[] img0 = new byte[bmp0.Width * bmp0.Height * 3];
                BitmapArrayConversions.updatebitmap(bmp0, img0);
                if (reverse_colours)
                {
                    BitmapArrayConversions.RGB_BGR(img0);
                }
                int[]  lookup0     = new int[bmp0.Width * bmp0.Height * 3];
                byte[] img0_scaled = new byte[bmp0.Width * bmp0.Height * 3];
                CreateScaledImageLookupColour(scale, lookup0, bmp0.Width, bmp0.Height, 0, 0, 0);
                for (int i = 0; i < img0_scaled.Length; i++)
                {
                    img0_scaled[i] = img0[lookup0[i]];
                }
                scale = 1;
                bmp0  = new Bitmap(bmp0.Width, bmp0.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                BitmapArrayConversions.updatebitmap_unsafe(img0_scaled, bmp0);
                left_image_filename = left_image.Substring(0, right_image.Length - 4) + "2.bmp";
                bmp0.Save(left_image_filename, System.Drawing.Imaging.ImageFormat.Bmp);
            }

            Bitmap bmp = (Bitmap)Bitmap.FromFile(right_image);

            byte[] img = new byte[bmp.Width * bmp.Height * 3];
            BitmapArrayConversions.updatebitmap(bmp, img);
            if (reverse_colours)
            {
                BitmapArrayConversions.RGB_BGR(img);
            }
            byte[] img_offset = new byte[bmp.Width * bmp.Height * 3];
            int[]  lookup1    = new int[bmp.Width * bmp.Height * 3];
            scale = 1.0f / scale;
            CreateScaledImageLookupColour(scale, lookup1, bmp.Width, bmp.Height, (int)offset_x, (int)offset_y, rotation_degrees);
            for (int i = 0; i < img_offset.Length; i++)
            {
                img_offset[i] = img[lookup1[i]];
            }
            bmp = new Bitmap(bmp.Width, bmp.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            if (reverse_colours)
            {
                BitmapArrayConversions.RGB_BGR(img_offset);
            }
            BitmapArrayConversions.updatebitmap_unsafe(img_offset, bmp);
            right_image_filename = right_image.Substring(0, right_image.Length - 4) + "2.bmp";
            bmp.Save(right_image_filename, System.Drawing.Imaging.ImageFormat.Bmp);

            List <string> images = new List <string>();

            images.Add(left_image_filename);
            images.Add(right_image_filename);
            CreateAnimatedGif(images, delay_mS, gif_filename, reverse_colours);
        }