Пример #1
0
        public void TestManagedRenderer()
        {
            using (var context = new ExecutionContext())
                using (var source = new Bitmap(50, 50, PixelFormat.Format32bppArgb))
                    using (var canvas = new Bitmap(20, 10, PixelFormat.Format32bppArgb)){
                        var sourceOptions = new BitmapOptions();
                        sourceOptions.AllowSpaceReuse = false;
                        sourceOptions.AlphaMeaningful = true;
                        sourceOptions.Bitmap          = source;
                        sourceOptions.Crop            = new Rectangle(5, 5, 45, 45);

                        var canvasOptions = new BitmapOptions();
                        canvasOptions.Compositing = BitmapCompositingMode.Blend_with_self;
                        canvasOptions.Crop        = new Rectangle(5, 5, 15, 5);
                        canvasOptions.Bitmap      = canvas;

                        var renderOptions = new RenderOptions();

                        renderOptions.FlipVertical   = true;
                        renderOptions.FlipHorizontal = true;
                        renderOptions.Filter         = 2;

                        var renderer = new ManagedRenderer(context, sourceOptions, canvasOptions, renderOptions, null);

                        renderer.Render();
                    }
        }
Пример #2
0
        protected static BitmapProperties1 NewDescription(float dpiX, float dpiY, PixelFormat format, AlphaMode alphaMode,
                                                          BitmapOptions bitmapOptions, ColorContext colorContext)
        {
            var pixelFormat = new SharpDX.Direct2D1.PixelFormat(format, alphaMode);

            return(new BitmapProperties1(pixelFormat, dpiX, dpiY, bitmapOptions, colorContext));
        }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BitmapProperties1"/> class.
 /// </summary>
 /// <param name="pixelFormat">The pixel format.</param>
 /// <param name="dpiX">The dpi X.</param>
 /// <param name="dpiY">The dpi Y.</param>
 /// <param name="bitmapOptions">The bitmap options.</param>
 /// <param name="colorContext">The color context.</param>
 public BitmapProperties1(PixelFormat pixelFormat, float dpiX, float dpiY, BitmapOptions bitmapOptions, ColorContext colorContext)
 {
     PixelFormat = pixelFormat;
     DpiX = dpiX;
     DpiY = dpiY;
     BitmapOptions = bitmapOptions;
     ColorContext = colorContext;
 }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BitmapProperties1"/> class.
 /// </summary>
 /// <param name="pixelFormat">The pixel format.</param>
 /// <param name="dpiX">The dpi X.</param>
 /// <param name="dpiY">The dpi Y.</param>
 /// <param name="bitmapOptions">The bitmap options.</param>
 /// <param name="colorContext">The color context.</param>
 public BitmapProperties1(PixelFormat pixelFormat, float dpiX, float dpiY, BitmapOptions bitmapOptions, ColorContext colorContext)
 {
     PixelFormat   = pixelFormat;
     DpiX          = dpiX;
     DpiY          = dpiY;
     BitmapOptions = bitmapOptions;
     ColorContext  = colorContext;
 }
Пример #5
0
            /// <summary>
            /// Creates the description.
            /// </summary>
            /// <param name="dpiX">The dpi x.</param>
            /// <param name="dpiY">The dpi y.</param>
            /// <param name="format">The format.</param>
            /// <param name="alphaMode">The alpha mode.</param>
            /// <param name="options">The options.</param>
            /// <param name="colorContext">The color context.</param>
            /// <returns></returns>
            public static BitmapProperties1 CreateDescription(float dpiX, float dpiY, Format format,
                                                              global::SharpDX.Direct2D1.AlphaMode alphaMode = global::SharpDX.Direct2D1.AlphaMode.Premultiplied,
                                                              BitmapOptions options = BitmapOptions.Target | BitmapOptions.CannotDraw, ColorContext colorContext = null)
            {
                // Make sure that the texture to create is a render target
                options |= BitmapOptions.Target;
                var description = NewDescription(dpiX, dpiY, new PixelFormat(format, alphaMode), options, colorContext);

                return(description);
            }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BitmapProperties1"/> class.
 /// </summary>
 /// <param name="pixelFormat">The pixel format.</param>
 /// <param name="dpiX">The dpi X.</param>
 /// <param name="dpiY">The dpi Y.</param>
 /// <param name="bitmapOptions">The bitmap options.</param>
 public BitmapProperties1(PixelFormat pixelFormat, float dpiX, float dpiY, BitmapOptions bitmapOptions) : this(pixelFormat, dpiX, dpiY, bitmapOptions, null)
 {
 }
Пример #7
0
        static int Main(string[] args)
        {
            bool             showHeader = false;
            NextBmpConverter converter  = null;


            if (!args.Any())
            {
                PrintUsage();
                return(ErrorCode);
            }

            var options = new BitmapOptions();

            foreach (var arg in args)
            {
                if (arg.StartsWith('-'))
                {
                    switch (arg)
                    {
                    case "-floor":
                        if (options.RoundingMode == RoundingMode.Unknown)
                        {
                            options.RoundingMode = RoundingMode.Floor;
                        }
                        else
                        {
                            WriteError($"Invalid option: {arg}");
                            PrintUsage();
                            return(ErrorCode);
                        }
                        break;

                    case "-ceil":
                        if (options.RoundingMode == RoundingMode.Unknown)
                        {
                            options.RoundingMode = RoundingMode.Ceil;
                        }
                        else
                        {
                            WriteError($"Invalid option: {arg}");
                            PrintUsage();
                            return(ErrorCode);
                        }

                        break;

                    case "-round":
                        if (options.RoundingMode == RoundingMode.Unknown)
                        {
                            options.RoundingMode = RoundingMode.Round;
                        }
                        else
                        {
                            WriteError($"Invalid option: {arg}");
                            PrintUsage();
                            return(ErrorCode);
                        }

                        break;

                    case "-min-palette":
                    {
                        options.MinimizePalette = true;

                        break;
                    }

                    case "-std-palette":
                    {
                        options.UseStdPalette = true;

                        break;
                    }

                    case "-help":
                    {
                        PrintUsage();
                        return(ErrorCode);
                    }

                    case "-show-header":
                    {
                        showHeader = true;
                        break;
                    }

                    default:
                        WriteError($"Invalid option: {arg}");
                        PrintUsage();
                        return(ErrorCode);
                    }
                }
                else
                {
                    if (options.InFileName == null)
                    {
                        options.InFileName = arg;
                    }
                    else if (options.OutFileName == null)
                    {
                        options.OutFileName = arg;
                    }
                    else
                    {
                        WriteError("Too many arguments");
                        PrintUsage();
                        return(ErrorCode);
                    }
                }
            }

            try
            {
                converter = new NextBmpConverter(options);
                converter.ProcessImage();
            }
            catch (Exception ex)
            {
                WriteError($"Error: {ex.Message}");
                PrintUsage();
                return(ErrorCode);
            }
            finally
            {
                if (showHeader && converter != null)
                {
                    Console.WriteLine($"Header Type:                       {System.Text.Encoding.Default.GetString(converter.InBitmap.Header.Type)}");
                    Console.WriteLine($"Header FileSize:                   {converter.InBitmap.Header.FileSize}");
                    Console.WriteLine($"Header Reserved1:                  {converter.InBitmap.Header.Reserved1}");
                    Console.WriteLine($"Header Reserved2:                  {converter.InBitmap.Header.Reserved2}");
                    Console.WriteLine($"Header ImageDataOffset:            {converter.InBitmap.Header.ImageDataOffset}");
                    Console.WriteLine($"InformationHeader Planes:          {converter.InBitmap.InformationHeader.Planes}");
                    Console.WriteLine($"InformationHeader BitsPerPixel:    {converter.InBitmap.InformationHeader.BitsPerPixel}");
                    Console.WriteLine($"InformationHeader CompressionType: {converter.InBitmap.InformationHeader.CompressionType}");
                    Console.WriteLine($"InformationHeader ImageSize:       {converter.InBitmap.InformationHeader.ImageSize}");
                    Console.WriteLine($"InformationHeader XResolution:     {converter.InBitmap.InformationHeader.XResolution}");
                    Console.WriteLine($"InformationHeader YResolution:     {converter.InBitmap.InformationHeader.YResolution}");
                    Console.WriteLine($"InformationHeader NumberOfColors:  {converter.InBitmap.InformationHeader.NumberOfColors}");
                    Console.WriteLine($"InformationHeader ImportantColors: {converter.InBitmap.InformationHeader.ImportantColors}");
                }
            }

            return(OkCode);
        }
Пример #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BitmapProperties1"/> class.
 /// </summary>
 /// <param name="pixelFormat">The pixel format.</param>
 /// <param name="dpiX">The dpi X.</param>
 /// <param name="dpiY">The dpi Y.</param>
 /// <param name="bitmapOptions">The bitmap options.</param>
 public BitmapProperties1(PixelFormat pixelFormat, float dpiX, float dpiY, BitmapOptions bitmapOptions) : this(pixelFormat, dpiX, dpiY, bitmapOptions, null)
 {
 }
Пример #9
0
 /// <summary>
 /// News the description.
 /// </summary>
 /// <param name="dpiX">The dpi x.</param>
 /// <param name="dpiY">The dpi y.</param>
 /// <param name="format">The format.</param>
 /// <param name="bitmapOptions">The bitmap options.</param>
 /// <param name="colorContext">The color context.</param>
 /// <returns></returns>
 protected static BitmapProperties1 NewDescription(float dpiX, float dpiY, PixelFormat format,
                                                   BitmapOptions bitmapOptions, ColorContext colorContext)
 {
     return(new BitmapProperties1(format, dpiX, dpiY, bitmapOptions, colorContext));
 }
Пример #10
0
 public NextBmpConverter(BitmapOptions bmpOptions)
 {
     _bmpOptions = bmpOptions;
 }
Пример #11
0
 public DisposableBitmap()
 {
     _options = new BitmapOptions();
 }