Пример #1
0
        /// <summary>
        /// updates the given Pixbuf object from the bitmap array
        /// </summary>
        /// updates the given image object from the bitmap array
        public static Gdk.Pixbuf setBitmap(byte[] bmp, Gdk.Pixbuf pixbuffer)
        {
            if (pixbuffer != null)
            {
                Gdk.Pixdata pd = new Gdk.Pixdata();

                // extract the raw data in uncompressed format
                pd.FromPixbuf(pixbuffer, false);
                byte[] pixel = pd.Serialize();

                // set the pixel values
                for (int i = 0; i < bmp.Length; i++)
                {
                    pixel[pixdata_header + i] = (byte)bmp[i];
                }

                pd.Deserialize((uint)pixel.Length, pixel);

                // return the pixel data as a Pixbuf object in compressed format
                return(Gdk.Pixbuf.FromPixdata(pd, true));
            }
            else
            {
                EventLog.AddError("GtkBitmap/getBitmap/pixbuffer has not been initialised");
                return(null);
            }
        }
Пример #2
0
        /// <summary>
        /// returns the bitmap data from a Pixbuf object
        /// </summary>
        public static void getBitmap(Gdk.Pixbuf pixbuffer, byte[] bmp)
        {
            if (pixbuffer != null)
            {
                if (bmp != null)
                {
                    Gdk.Pixdata pd = new Gdk.Pixdata();

                    pd.FromPixbuf(pixbuffer, false);
                    byte[] pixel = pd.Serialize();

                    if (pd.Rowstride != pixbuffer.Width * 3)
                    {
                        // uneven stride length
                        long real_length = pd.Rowstride * pixbuffer.Height;
                        long n           = 0;
                        long w           = pixbuffer.Width * 3;
                        for (int y = 0; y < pixbuffer.Height; y++)
                        {
                            long n1 = (y * pixbuffer.Width) * 3;
                            for (int x = 0; x < pd.Rowstride; x++)
                            {
                                if (x < w)
                                {
                                    bmp[n1] = pixel[n];
                                }
                                n++;
                                n1++;
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < bmp.Length; i++)
                        {
                            bmp[i] = pixel[pixdata_header + i];
                        }
                    }

                    pd.Deserialize((uint)pixel.Length, pixel);
                }
                else
                {
                    EventLog.AddError("GtkBitmap/getBitmap/bmp not defined");
                }
            }
            else
            {
                EventLog.AddError("GtkBitmap/getBitmap/pixbuffer has not been initialised");
            }
        }