示例#1
0
        public static void BGRtoRGB(Bitmap image)
        {
            Rectangle rect = new Rectangle(0, 0, image.Width, image.Height);

            if (image.PixelFormat == PixelFormat.Format32bppArgb)
            {
                BitmapData data = image.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
                GraphicUtils.ABGRtoARGB(data.Scan0, data.Stride, image.Width, image.Height);
                image.UnlockBits(data);
            }
            else
            {
                BitmapData data = image.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
                GraphicUtils.BGRtoRGB(data.Scan0, data.Stride, image.Width, image.Height);
                image.UnlockBits(data);
            }
        }
示例#2
0
 public T Load()
 {
     if (!_loaded)
     {
         if (typeof(T) == typeof(Bitmap) && _id.GetType() == typeof(string))
         {
             log.Info("New bitmap added to asset manager: {0}", _id);
             // TODO stream should closed on unload (but kept open for the lifetime of the Bitmap)
             Bitmap image = new Bitmap(_assets.OpenStream((string)_id));
             foreach (IBitmapFilter filter in _assets.GetFilters((string)_id))
             {
                 image = filter.Filter(image);
             }
             if (!Array.Exists(image.FrameDimensionsList, e => e == FrameDimension.Time.Guid))
             {
                 // Only convert for still image; animate ones are converted when played
                 GraphicUtils.BGRtoRGB(image);
             }
             _value  = (T)Convert.ChangeType(image, typeof(T));
             _loaded = true;
         }
         else if (typeof(T) == typeof(Font) && _id.GetType() == typeof(FontDef))
         {
             var fontDef = (FontDef)_id;
             log.Info("New font added to asset manager: {0}", fontDef);
             var font = new Font(_assets, fontDef, fontDef.FillBrightness, fontDef.OutlineBrightness);
             _value  = (T)Convert.ChangeType(font, typeof(T));
             _loaded = true;
         }
         else
         {
             throw new InvalidOperationException(string.Format("Unsupported asset type {0}", typeof(T)));
         }
     }
     return(_value);
 }