Ejemplo n.º 1
0
        private static Direct2D.Bitmap LoadFromFile(string filename, Direct2D.RenderTarget Direct2DTarget)
        {
            var factory = new WIC.ImagingFactory();
            // Decode image
            var decoder     = new WIC.BitmapDecoder(factory, filename, WIC.DecodeOptions.CacheOnLoad);
            var frameDecode = decoder.GetFrame(0);
            var source      = new WIC.BitmapSource(frameDecode.NativePointer);
            var fc          = new WIC.FormatConverter(factory);

            fc.Initialize(
                source,
                SharpDX.WIC.PixelFormat.Format32bppPBGRA,
                SharpDX.WIC.BitmapDitherType.None,
                null,
                0.0f,
                SharpDX.WIC.BitmapPaletteType.Custom
                );
            double dpX = 96.0f;
            double dpY = 96.0f;

            fc.GetResolution(out dpX, out dpY);
            Direct2D.BitmapProperties props = new Direct2D.BitmapProperties(
                new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied));
            WIC.Bitmap bmp = new WIC.Bitmap(factory, fc, WIC.BitmapCreateCacheOption.CacheOnLoad);
            // Формируем изображения
            var Direct2DBitmap = SharpDX.Direct2D1.Bitmap.FromWicBitmap(Direct2DTarget, fc, props);

            // Cleanup
            factory.Dispose();
            decoder.Dispose();
            source.Dispose();
            fc.Dispose();
            return(Direct2DBitmap);
        }
Ejemplo n.º 2
0
        private static void DrawSmallRaw(Person person, WIC.ImagingFactory wic, D2D.Factory d2dFactory,
                                         WIC.FormatConverter converter)
        {
            var whRate       = 1.0f * converter.Size.Width / converter.Size.Height;
            var smallRawSize = new Vector2(whRate * ImageDefines.SmallRawY, ImageDefines.SmallRawY);
            var scale        = ImageDefines.SmallRawY / converter.Size.Height;

            using (var wicBitmap = new WIC.Bitmap(wic,
                                                  (int)smallRawSize.X, (int)smallRawSize.Y,
                                                  WIC.PixelFormat.Format32bppPBGRA,
                                                  WIC.BitmapCreateCacheOption.CacheOnDemand))
                using (var target = new D2D.WicRenderTarget(d2dFactory,
                                                            wicBitmap, new D2D.RenderTargetProperties()))
                    using (var bmp = D2D.Bitmap.FromWicBitmap(target, converter))
                        using (var bmpBrush = new D2D.BitmapBrush(target, bmp))
                        {
                            target.BeginDraw();
                            target.Transform = Matrix3x2.Scaling(scale, scale);
                            target.DrawBitmap(bmp, 1.0f, D2D.BitmapInterpolationMode.Linear);
                            target.EndDraw();

                            using (var file = File.Create(person.SmallRawImage))
                            {
                                WicTools.SaveD2DBitmap(wic, wicBitmap, file);
                            }
                        }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BitmapEncoder"/> class.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="containerFormatGuid">The container format GUID. List from <see cref="ContainerFormatGuids"/> </param>
 /// <param name="stream">A stream to use as the output of this bitmap encoder.</param>
 /// <unmanaged>HRESULT IWICImagingFactory::CreateEncoder([In] const GUID&amp; guidContainerFormat,[In, Optional] const GUID* pguidVendor,[Out] IWICBitmapEncoder** ppIEncoder)</unmanaged>	
 public BitmapEncoder(ImagingFactory factory, Guid containerFormatGuid, System.IO.Stream stream = null)
 {
     this.factory = factory;
     factory.CreateEncoder(containerFormatGuid, null, this);
     if (stream != null)
         Initialize(stream);
 }
Ejemplo n.º 4
0
        public static D2D.Bitmap LoadBitmap(D2D.RenderTarget renderTarget, string imagePath)
        {
            FileInfo fi = new FileInfo(imagePath);

            if (!fi.Exists)
            {
                var    ext    = fi.Extension;
                string newExt = "";
                if (ext == ".jpg")
                {
                    newExt = ".png";
                }
                else if (ext == ".png")
                {
                    newExt = ".jpg";
                }
                string newName = fi.FullName.Remove(fi.FullName.Length - 4, 4);
                imagePath = newName + newExt;
            }

            D2D.Bitmap bmp;
            if (Cached.ContainsKey(imagePath))
            {
                bmp = Cached[imagePath];
                if (bmp.IsDisposed)
                {
                    Cached.TryRemove(imagePath, out _);
                }
                else
                {
                    return(bmp);
                }
            }

            WIC.ImagingFactory    imagingFactory = new WIC.ImagingFactory();
            DXIO.NativeFileStream fileStream     = new DXIO.NativeFileStream(imagePath,
                                                                             DXIO.NativeFileMode.Open, DXIO.NativeFileAccess.Read);

            WIC.BitmapDecoder bitmapDecoder =
                new WIC.BitmapDecoder(imagingFactory, fileStream, WIC.DecodeOptions.CacheOnDemand);
            WIC.BitmapFrameDecode frame = bitmapDecoder.GetFrame(0);

            WIC.FormatConverter converter = new WIC.FormatConverter(imagingFactory);
            converter.Initialize(frame, WIC.PixelFormat.Format32bppPRGBA);

            var bitmapProperties =
                new D2D.BitmapProperties(new D2D.PixelFormat(Format.R8G8B8A8_UNorm, D2D.AlphaMode.Premultiplied));

            //Size2 size = new Size2(frame.Size.Width, frame.Size.Height);

            bmp = D2D.Bitmap.FromWicBitmap(renderTarget, converter, bitmapProperties);

            if (!Cached.ContainsKey(imagePath))
            {
                Cached.TryAdd(imagePath, bmp);
                //LogUtil.LogInfo("Created cache.");
            }

            return(bmp);
        }
Ejemplo n.º 5
0
        public ShaderResourceView LoadBitmapShaderResource(System.Drawing.Bitmap btm)
        {
            ShaderResourceView res = null;

            try {
                var ms = new MemoryStream();
                btm.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                ms.Position = 0;

                var factory       = new SharpDX.WIC.ImagingFactory();
                var bitmapDecoder = new BitmapDecoder(factory, ms, DecodeOptions.CacheOnDemand);
                var result        = new FormatConverter(factory);

                result.Initialize(bitmapDecoder.GetFrame(0), PixelFormat.Format32bppPRGBA, BitmapDitherType.None,
                                  null, 0.0, BitmapPaletteType.Custom);

                using (var texture = CreateTexture2DFromBitmap(device, result)) {
                    var srvDesc = new ShaderResourceViewDescription()
                    {
                        Format    = texture.Description.Format,
                        Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D,
                    };
                    srvDesc.Texture2D.MostDetailedMip = 0;
                    srvDesc.Texture2D.MipLevels       = -1;

                    res = new ShaderResourceView(device, texture, srvDesc);
                    device.ImmediateContext.GenerateMips(res);
                }
                // TextureResource = ShaderResourceView.FromFile(device, fileName);
            } catch (Exception ex) {
                System.Diagnostics.Trace.WriteLine($"TexturedLoader {ex.Message}");
            }
            return(res);
        }
Ejemplo n.º 6
0
 internal static ColorContext[] GetColorContexts(ColorContextsProvider getColorContexts, ImagingFactory imagingFactory)
 {
     ColorContext[] colorContexts;
     Result result = TryGetColorContexts(getColorContexts, imagingFactory, out colorContexts);
     result.CheckError();
     return colorContexts;
 }
        public Direct2DFactories()
        {
            WICFactory = new WIC.ImagingFactory();
            DWFactory  = new DW.Factory();

            var d3DDevice = new D3D11.Device(
                D3D.DriverType.Hardware,
                D3D11.DeviceCreationFlags.BgraSupport
#if DEBUG
                | D3D11.DeviceCreationFlags.Debug
#endif
                ,
                D3D.FeatureLevel.Level_11_1,
                D3D.FeatureLevel.Level_11_0,
                D3D.FeatureLevel.Level_10_1,
                D3D.FeatureLevel.Level_10_0,
                D3D.FeatureLevel.Level_9_3,
                D3D.FeatureLevel.Level_9_2,
                D3D.FeatureLevel.Level_9_1
                );

            var dxgiDevice = ComObject.As <SharpDX.DXGI.Device> (d3DDevice.NativePointer);
            var d2DDevice  = new D2D1.Device(dxgiDevice);

            D2DFactory = d2DDevice.Factory;
            //_d2DDeviceContext = new D2D1.DeviceContext (d2DDevice, D2D1.DeviceContextOptions.None);
            //var dpi = DisplayDpi;
            //_d2DDeviceContext.DotsPerInch = new Size2F (dpi, dpi);
        }
Ejemplo n.º 8
0
        internal static Result TryGetColorContexts(ColorContextsProvider getColorContexts, ImagingFactory imagingFactory, out ColorContext[] colorContexts)
        {
            colorContexts = null;

            int count;
            Result result = getColorContexts(0, null, out count);

            if (result.Success)
            {
                colorContexts = new ColorContext[count];

                if (count > 0)
                {
                    // http://msdn.microsoft.com/en-us/library/windows/desktop/ee690135(v=vs.85).aspx
                    // The ppIColorContexts array must be filled with valid data: each IWICColorContext* in the array must 
                    // have been created using IWICImagingFactory::CreateColorContext.

                    for (int i = 0; i < count; i++)
                        colorContexts[i] = new ColorContext(imagingFactory);
                    int actualCount;
                    getColorContexts(count, colorContexts, out actualCount);
                    Debug.Assert(count == actualCount);
                }
            }

            return result;
        }
Ejemplo n.º 9
0
        public Direct2DFactories()
        {
            WICFactory = new WIC.ImagingFactory ();
            DWFactory = new DW.Factory ();

            var d3DDevice = new D3D11.Device (
                D3D.DriverType.Hardware,
                D3D11.DeviceCreationFlags.BgraSupport
            #if DEBUG
             | D3D11.DeviceCreationFlags.Debug
            #endif
            ,
                D3D.FeatureLevel.Level_11_1,
                D3D.FeatureLevel.Level_11_0,
                D3D.FeatureLevel.Level_10_1,
                D3D.FeatureLevel.Level_10_0,
                D3D.FeatureLevel.Level_9_3,
                D3D.FeatureLevel.Level_9_2,
                D3D.FeatureLevel.Level_9_1
                );

            var dxgiDevice = ComObject.As<SharpDX.DXGI.Device> (d3DDevice.NativePointer);
            var d2DDevice = new D2D1.Device (dxgiDevice);
            D2DFactory = d2DDevice.Factory;
            //_d2DDeviceContext = new D2D1.DeviceContext (d2DDevice, D2D1.DeviceContextOptions.None);
            //var dpi = DisplayDpi;
            //_d2DDeviceContext.DotsPerInch = new Size2F (dpi, dpi);
        }
Ejemplo n.º 10
0
 private D2D(Direct2D.Factory d2dFactory, Direct2D.RenderTarget d2dRenderTarget)
 {
     this.d2dFactory      = d2dFactory;
     this.d2dRenderTarget = d2dRenderTarget;
     this.wicFactory      = new WIC.ImagingFactory();
     this.dwFactory       = new DW.Factory();
 }
Ejemplo n.º 11
0
 public static void CreateIndependentResource()
 {
     d2d1factory  = new Direct2D1.Factory();
     imageFactory = new WIC.ImagingFactory();
     writeFactory = new DirectWrite.Factory();
     Ready        = true;
 }
Ejemplo n.º 12
0
        public static void LoadSource(Stream str, UIImage img)
        {
            Wic.ImagingFactory fac = ThreadResource.GetWicFactory();
            var d = new Wic.BitmapDecoder(fac, str, Wic.DecodeOptions.CacheOnLoad);

            if (img.data != null)
            {
                ClearResource(img);
            }
            img.data    = str;
            img.Decoder = d;
            var frame = d.GetFrame(0);

            img.FrameDecoder = frame;
            var fconv = new Wic.FormatConverter(fac);

            fconv.Initialize(frame, Wic.PixelFormat.Format32bppPRGBA);
            img.Bitmap         = fconv;
            img.Mapsize.Left   = 0;
            img.Mapsize.Top    = 0;
            img.Mapsize.Right  = img.Bitmap.Size.Width;
            img.Mapsize.Bottom = img.Bitmap.Size.Height;
            lock (DX_Core.D2D)
                img.d2dmap = D2D1.Bitmap.FromWicBitmap(DX_Core.D2D.d2dContext, img.Bitmap);
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Initializes instance members of the <see cref="GifRecorder"/> class.
 /// </summary>
 public GifRecorder()
 {
     GifRepeatCount = 0;
     _imagingFactory = new ImagingFactory();
     _frames = new List<BitmapFrame>();
     MaxFramePerSecond = 8;
     _desktopManager = new DesktopManager();
 }
Ejemplo n.º 14
0
 public static void Initialize() {
     lock (SyncObject) {
         if (!_isInitailized) {
             _factory = new ImagingFactory();
             _isInitailized = true;
         }
     }
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WICStream"/> class from a <see cref="IStream"/>.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="stream">The stream.</param>
 /// <msdn-id>ee719789</msdn-id>	
 /// <unmanaged>HRESULT IWICStream::InitializeFromIStream([In, Optional] IStream* pIStream)</unmanaged>	
 /// <unmanaged-short>IWICStream::InitializeFromIStream</unmanaged-short>	
 public WICStream(ImagingFactory factory, Stream stream)
     : base(IntPtr.Zero)
 {
     factory.CreateStream(this);
     streamProxy = new ComStreamProxy(stream);
     var istreamPtr = ComStreamShadow.ToIntPtr(streamProxy);
     InitializeFromIStream_(istreamPtr);
 }
Ejemplo n.º 16
0
        public BitmapImpl(ImagingFactory factory, string fileName)
        {
            this.factory = factory;

            using (BitmapDecoder decoder = new BitmapDecoder(factory, fileName, DecodeOptions.CacheOnDemand))
            {
                this.WicImpl = new Bitmap(factory, decoder.GetFrame(0), BitmapCreateCacheOption.CacheOnDemand);
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BitmapImpl"/> class.
        /// </summary>
        /// <param name="factory">The WIC imaging factory to use.</param>
        /// <param name="stream">The stream to read the bitmap from.</param>
        public BitmapImpl(ImagingFactory factory, Stream stream)
        {
            _factory = factory;

            using (BitmapDecoder decoder = new BitmapDecoder(factory, stream, DecodeOptions.CacheOnLoad))
            {
                WicImpl = new Bitmap(factory, decoder.GetFrame(0), BitmapCreateCacheOption.CacheOnLoad);
            }
        }
Ejemplo n.º 18
0
        internal static ColorContext[] TryGetColorContexts(ColorContextsProvider getColorContexts, ImagingFactory imagingFactory)
        {
            ColorContext[] colorContexts;
            Result result = TryGetColorContexts(getColorContexts, imagingFactory, out colorContexts);

            if (ResultCode.UnsupportedOperation != result)
                result.CheckError();

            return colorContexts;
        }
Ejemplo n.º 19
0
        public CCLabel_Renderer81()
        {
            var d2dFactory = CreateD2DFactory();

            var newDevice = CreateDevice();

            CreateRenderingResources(newDevice, d2dFactory);

            FactoryImaging = new SharpDX.WIC.ImagingFactory();
        }
Ejemplo n.º 20
0
 public BitmapImpl(ImagingFactory factory, int width, int height)
 {
     this.factory = factory;
     this.WicImpl = new Bitmap(
         factory,
         width,
         height,
         PixelFormat.Format32bppPBGRA,
         BitmapCreateCacheOption.CacheOnLoad);
 }
        public CCLabel_Renderer81()
        {
            var d2dFactory = CreateD2DFactory();

            var newDevice = CreateDevice();

            CreateRenderingResources(newDevice, d2dFactory);

            FactoryImaging = new SharpDX.WIC.ImagingFactory();
        }
Ejemplo n.º 22
0
        public static BitmapSource CreateWicBitmap(Stream str)
        {
            BitmapSource bs = new BitmapSource();

            Wic.ImagingFactory fac = ThreadResource.GetWicFactory();
            bs.Decoder      = new Wic.BitmapDecoder(fac, str, Wic.DecodeOptions.CacheOnLoad);
            bs.FrameDecoder = bs.Decoder.GetFrame(0);
            bs.Converter    = new Wic.FormatConverter(fac);
            bs.Converter.Initialize(bs.FrameDecoder, Wic.PixelFormat.Format32bppPRGBA);
            return(bs);
        }
Ejemplo n.º 23
0
        public PngImageResource(WIC.ImagingFactory imagingFactory, string path)
        {
            using (var decoder = new WIC.PngBitmapDecoder(imagingFactory))
            {
                using (var inputStream = new WIC.WICStream(imagingFactory, path, NativeFileAccess.Read))
                    decoder.Initialize(inputStream, WIC.DecodeOptions.CacheOnLoad);

                FormatConverter = new WIC.FormatConverter(imagingFactory);
                FormatConverter.Initialize(decoder.GetFrame(0), WIC.PixelFormat.Format32bppPRGBA);
            }
        }
Ejemplo n.º 24
0
        private static void LoadBitmaps()
        {
            var fac = new SharpDX.WIC.ImagingFactory();
            var target = GraphicsWindow.Instance.RenderTarget2D;
            var stream = new NativeFileStream(Application.StartupPath + "\\Images\\Ship 1.png", NativeFileMode.Open, NativeFileAccess.Read);
            var decoder = new BitmapDecoder(fac, stream, DecodeOptions.CacheOnDemand);
            var frame = decoder.GetFrame(0);
            var converter = new FormatConverter(fac);
            converter.Initialize(frame, SharpDX.WIC.PixelFormat.Format32bppPRGBA);

            BitShip1 = Bitmap1.FromWicBitmap(GraphicsWindow.Instance.RenderTarget2D, converter);
        }
Ejemplo n.º 25
0
        public static byte[] LoadImage(string fileName, bool premultiplied, out int width, out int height)
        {
            WIC.ImagingFactory factory = new WIC.ImagingFactory();

            SharpDX.IO.NativeFileStream stream  = new SharpDX.IO.NativeFileStream(fileName, SharpDX.IO.NativeFileMode.Open, SharpDX.IO.NativeFileAccess.Read);
            WIC.BitmapDecoder           decoder = new WIC.BitmapDecoder(factory, stream, WIC.DecodeOptions.CacheOnDemand);
            WIC.BitmapFrameDecode       frame   = decoder.GetFrame(0);
            width  = frame.Size.Width;
            height = frame.Size.Height;
            byte[] data = new byte[width * height * 4];
            frame.CopyPixels(data, width * 4);
            return(data);
        }
Ejemplo n.º 26
0
        public static D2D.Bitmap LoadBitmap(this D2D.RenderTarget renderTarget, string imagePath)
        {
            lock (LockObj)
            {
                Sw.Start();
                D2D.Bitmap bmp;
                if (Cached.ContainsKey(imagePath))
                {
                    Cached[imagePath].Time = DateTime.Now;
                    bmp = Cached[imagePath].Bitmap;

                    Sw.Stop();
                    LogUtil.LogInfo($"Cache: {Sw.ElapsedMilliseconds}ms.");
                }
                else
                {
                    WIC.ImagingFactory    imagingFactory = new WIC.ImagingFactory();
                    DXIO.NativeFileStream fileStream     = new DXIO.NativeFileStream(imagePath,
                                                                                     DXIO.NativeFileMode.Open, DXIO.NativeFileAccess.Read);

                    WIC.BitmapDecoder     bitmapDecoder = new WIC.BitmapDecoder(imagingFactory, fileStream, WIC.DecodeOptions.CacheOnDemand);
                    WIC.BitmapFrameDecode frame         = bitmapDecoder.GetFrame(0);

                    WIC.FormatConverter converter = new WIC.FormatConverter(imagingFactory);
                    converter.Initialize(frame, WIC.PixelFormat.Format32bppPRGBA);

                    var bitmapProperties =
                        new D2D.BitmapProperties(new D2D.PixelFormat(Format.R8G8B8A8_UNorm, D2D.AlphaMode.Premultiplied));
                    //Size2 size = new Size2(frame.Size.Width, frame.Size.Height);

                    bmp = D2D.Bitmap.FromWicBitmap(renderTarget, converter, bitmapProperties);

                    Sw.Stop();
                    LogUtil.LogInfo($"Load: {Sw.ElapsedMilliseconds}ms.");
                }

                if (!Cached.ContainsKey(imagePath) && Sw.ElapsedMilliseconds > 50)
                {
                    Cached.TryAdd(imagePath, new CacheInfo(DateTime.Now, bmp));
                    LogUtil.LogInfo("Created cache.");
                    if (Cached.Count > 50)
                    {
                        Cached.TryRemove(Cached.OrderByDescending(c => c.Value.Time).First().Key, out _);
                        LogUtil.LogInfo("Removed unused cache.");
                    }
                }
                Sw.Reset();

                return(bmp);
            }
        }
Ejemplo n.º 27
0
        public static D2D.Bitmap LoadFromFile(D2D.RenderTarget renderTarget, string filePath)
        {
            WIC.ImagingFactory    imagingFactory = new WIC.ImagingFactory();
            DXIO.NativeFileStream fileStream     = new DXIO.NativeFileStream(filePath,
                                                                             DXIO.NativeFileMode.Open, DXIO.NativeFileAccess.Read);

            WIC.BitmapDecoder     bitmapDecoder = new WIC.BitmapDecoder(imagingFactory, fileStream, WIC.DecodeOptions.CacheOnDemand);
            WIC.BitmapFrameDecode frame         = bitmapDecoder.GetFrame(0);

            WIC.FormatConverter converter = new WIC.FormatConverter(imagingFactory);
            converter.Initialize(frame, WIC.PixelFormat.Format32bppPRGBA);

            return(D2D.Bitmap.FromWicBitmap(RenderForm.RenderTarget, converter));
        }
Ejemplo n.º 28
0
 public static WIC.FormatConverter CreateWicImage(WIC.ImagingFactory wic, string filename)
 {
     using (var decoder = new WIC.JpegBitmapDecoder(wic))
         using (var decodeStream = new WIC.WICStream(wic, filename, NativeFileAccess.Read))
         {
             decoder.Initialize(decodeStream, WIC.DecodeOptions.CacheOnDemand);
             using (var decodeFrame = decoder.GetFrame(0))
             {
                 var converter = new WIC.FormatConverter(wic);
                 converter.Initialize(decodeFrame, WIC.PixelFormat.Format32bppPBGRA);
                 return(converter);
             }
         }
 }
Ejemplo n.º 29
0
        private static Direct2D1.Bitmap1 CreateD2dBitmap(
            WIC.ImagingFactory imagingFactory,
            string filename,
            Direct2D1.DeviceContext renderTarget)
        {
            var decoder = new WIC.BitmapDecoder(imagingFactory, filename, WIC.DecodeOptions.CacheOnLoad);

            WIC.BitmapFrameDecode frame = decoder.GetFrame(0);

            var image = new WIC.FormatConverter(imagingFactory);

            image.Initialize(frame, WIC.PixelFormat.Format32bppPBGRA);
            return(Direct2D1.Bitmap1.FromWicBitmap(renderTarget, image));
        }
Ejemplo n.º 30
0
        private static void Main()
        {
            var wicFactory = new ImagingFactory();
            var d2dFactory = new SharpDX.Direct2D1.Factory();

            string filename = "output.jpg";
            const int width = 512;
            const int height = 512;

            var rectangleGeometry = new RoundedRectangleGeometry(d2dFactory, new RoundedRectangle() { RadiusX = 32, RadiusY = 32, Rect = new RectangleF(128, 128, width - 128, height-128) });

            var wicBitmap = new Bitmap(wicFactory, width, height, SharpDX.WIC.PixelFormat.Format32bppBGR, BitmapCreateCacheOption.CacheOnLoad);

            var renderTargetProperties = new RenderTargetProperties(RenderTargetType.Default, new PixelFormat(Format.Unknown, AlphaMode.Unknown), 0, 0, RenderTargetUsage.None, FeatureLevel.Level_DEFAULT);

            var d2dRenderTarget = new WicRenderTarget(d2dFactory, wicBitmap, renderTargetProperties);

            var solidColorBrush = new SolidColorBrush(d2dRenderTarget, Color.White);

            d2dRenderTarget.BeginDraw();
            d2dRenderTarget.Clear(Color.Black);
            d2dRenderTarget.FillGeometry(rectangleGeometry, solidColorBrush, null);
            d2dRenderTarget.EndDraw();

            if (File.Exists(filename))
                File.Delete(filename);

            var stream = new WICStream(wicFactory, filename, NativeFileAccess.Write);
            // Initialize a Jpeg encoder with this stream
            var encoder = new JpegBitmapEncoder(wicFactory);
            encoder.Initialize(stream);

            // Create a Frame encoder
            var bitmapFrameEncode = new BitmapFrameEncode(encoder);
            bitmapFrameEncode.Initialize();
            bitmapFrameEncode.SetSize(width, height);
            var pixelFormatGuid = SharpDX.WIC.PixelFormat.FormatDontCare;
            bitmapFrameEncode.SetPixelFormat(ref pixelFormatGuid);
            bitmapFrameEncode.WriteSource(wicBitmap);

            bitmapFrameEncode.Commit();
            encoder.Commit();

            bitmapFrameEncode.Dispose();
            encoder.Dispose();
            stream.Dispose();

            System.Diagnostics.Process.Start(Path.GetFullPath(Path.Combine(Environment.CurrentDirectory,filename)));
        }
Ejemplo n.º 31
0
 private static void DoImageProcessWIC()
 {
     using (var wic = new WIC.ImagingFactory())
         using (var d2dFactory = new D2D.Factory(D2D.FactoryType.MultiThreaded))
         {
             var db = new LotteryDatabase("state.json");
             Parallel.ForEach(db.GetAllPerson(), person =>
             {
                 using (var converter = WicTools.CreateWicImage(wic, person.RawImage))
                 {
                     DrawPsd(person, wic, d2dFactory, converter);
                     //DrawSmallRaw(person, wic, d2dFactory, converter);
                 }
             });
         }
 }
Ejemplo n.º 32
0
        private void InitializeTextures()
        {
            // Setup standard sampler
            samplerState = new D3D11.SamplerState(d3dDevice, new D3D11.SamplerStateDescription()
            {
                AddressU = D3D11.TextureAddressMode.Wrap,
                AddressV = D3D11.TextureAddressMode.Wrap,
                AddressW = D3D11.TextureAddressMode.Wrap,
                Filter   = D3D11.Filter.MinMagMipLinear
            });

            imagingFactory = new SharpDX.WIC.ImagingFactory();

            // Load textures. For now just one test texture
            textureView = LoadTexture("texture.png");
        }
Ejemplo n.º 33
0
 public RenderTargetBitmapImpl(
     ImagingFactory imagingFactory, 
     Factory d2dFactory,
     int width, 
     int height)
     : base(imagingFactory, width, height)
 {
     this.target = new WicRenderTarget(
         d2dFactory,
         this.WicImpl,
         new RenderTargetProperties
         {
             DpiX = 96,
             DpiY = 96,
         });
 }
Ejemplo n.º 34
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        private void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                if (Factory != null)
                {
                    Factory.Dispose();
                }
            }

            Factory   = null;
            _disposed = true;
        }
Ejemplo n.º 35
0
        public RenderTargetBitmapImpl(
            ImagingFactory imagingFactory,
            Factory d2dFactory,
            int width,
            int height)
            : base(imagingFactory, width, height)
        {
            var props = new RenderTargetProperties
            {
                DpiX = 96,
                DpiY = 96,
            };

            _target = new WicRenderTarget(
                d2dFactory,
                WicImpl,
                props);
        }
Ejemplo n.º 36
0
        public static void SaveD2DBitmap(WIC.ImagingFactory wic, WIC.Bitmap wicBitmap, Stream outputStream)
        {
            using (var encoder = new WIC.BitmapEncoder(wic, WIC.ContainerFormatGuids.Png))
            {
                encoder.Initialize(outputStream);
                using (var frame = new WIC.BitmapFrameEncode(encoder))
                {
                    frame.Initialize();
                    frame.SetSize(wicBitmap.Size.Width, wicBitmap.Size.Height);

                    var pixelFormat = wicBitmap.PixelFormat;
                    frame.SetPixelFormat(ref pixelFormat);
                    frame.WriteSource(wicBitmap);

                    frame.Commit();
                    encoder.Commit();
                }
            }
        }
Ejemplo n.º 37
0
        //private string CreateFont(string fontName, float fontSize, CCRawList<char> charset)
        private Font CreateFont(string fontName, float fontSize)
        {
            Font _currentFont;

            if (Factory2D == null)
            {
                Factory2D      = new SharpDX.Direct2D1.Factory();
                FactoryDWrite  = new SharpDX.DirectWrite.Factory();
                FactoryImaging = new SharpDX.WIC.ImagingFactory();

                dpi      = Factory2D.DesktopDpi;
                dpiScale = dpi.Height / 72f;
            }

            _currentFontCollection = FactoryDWrite.GetSystemFontCollection(true);

            if (_defaultFont == null)
            {
                _defaultFont = GenericSanSerif();
            }

            FontFamily fontFamily = GetFontFamily(fontName);


            if (!_fontFamilyCache.TryGetValue(fontName, out fontFamily))
            {
                var ext = Path.GetExtension(fontName);

                _currentFont = _defaultFont;

                _currentFont = GetFont(fontName, fontSize);

                _fontFamilyCache.Add(fontName, _currentFont.FontFamily);
                CCLog.Log("{0} not found.  Defaulting to {1}.", fontName, _currentFont.FontFamily.FamilyNames.GetString(0));
            }
            else
            {
                _currentFont = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);
            }

            return(_currentFont);
        }
Ejemplo n.º 38
0
        Bitmap1 createD2DBitmap(string filePath, _d2d.DeviceContext deviceContext)
        {
            var imagingFactory = new _wic.ImagingFactory();

            var fileStream = new NativeFileStream(
                filePath,
                NativeFileMode.Open,
                NativeFileAccess.Read);

            var bitmapDecoder = new _wic.BitmapDecoder(imagingFactory, fileStream, _wic.DecodeOptions.CacheOnDemand);
            var frame         = bitmapDecoder.GetFrame(0);

            var converter = new _wic.FormatConverter(imagingFactory);

            converter.Initialize(frame, SharpDX.WIC.PixelFormat.Format32bppPRGBA);

            var newBitmap = SharpDX.Direct2D1.Bitmap1.FromWicBitmap(deviceContext, converter);

            return(newBitmap);
        }
        public Direct2D1RenderTargetBitmap(
            Factory d2dFactory, 
            ImagingFactory wicFactory,
            SharpDX.WIC.Bitmap bitmap)
            : base(wicFactory, bitmap)
        {
            double dpiX;
            double dpiY;

            this.d2dFactory = d2dFactory;
            bitmap.GetResolution(out dpiX, out dpiY);

            this.target = new WicRenderTarget(
                d2dFactory,
                bitmap,
                new RenderTargetProperties
                {
                    DpiX = (float)dpiX,
                    DpiY = (float)dpiY,
                });
        }
Ejemplo n.º 40
0
        private static void DrawPsd(Person person, WIC.ImagingFactory wic, D2D.Factory d2dFactory,
                                    WIC.FormatConverter converter)
        {
            using (var wicBitmap = new WIC.Bitmap(wic,
                                                  (int)ImageDefines.Size, (int)ImageDefines.Size,
                                                  WIC.PixelFormat.Format32bppPBGRA,
                                                  WIC.BitmapCreateCacheOption.CacheOnDemand))
                using (var target = new D2D.WicRenderTarget(d2dFactory,
                                                            wicBitmap, new D2D.RenderTargetProperties()))
                    using (var color = new D2D.SolidColorBrush(target, SexColor[person.Sex]))
                        using (var bmp = D2D.Bitmap.FromWicBitmap(target, converter))
                            using (var bmpBrush = new D2D.BitmapBrush(target, bmp))
                            {
                                target.BeginDraw();
                                var offset = (ImageDefines.Size - ImageDefines.RealSize) / 2;
                                bmpBrush.Transform = Matrix3x2.Scaling(
                                    ImageDefines.RealSize / bmp.Size.Width,
                                    ImageDefines.RealSize / (bmp.Size.Height - 497.0f))
                                                     * Matrix3x2.Translation(offset, offset);
                                target.FillEllipse(new D2D.Ellipse(
                                                       new Vector2(ImageDefines.Size / 2.0f, ImageDefines.Size / 2.0f),
                                                       ImageDefines.RealSize / 2.0f,
                                                       ImageDefines.RealSize / 2.0f),
                                                   bmpBrush);
                                target.DrawEllipse(new D2D.Ellipse(
                                                       new Vector2(ImageDefines.Size / 2.0f, ImageDefines.Size / 2.0f),
                                                       ImageDefines.RealSize / 2.0f,
                                                       ImageDefines.RealSize / 2.0f),
                                                   color, ImageDefines.LineWidth);
                                target.EndDraw();

                                using (var file = File.Create(person.PsdImage))
                                {
                                    WicTools.SaveD2DBitmap(wic, wicBitmap, file);
                                }
                            }
        }
Ejemplo n.º 41
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BitmapDecoder"/> class from a <see cref="IStream"/>.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="streamRef">The stream ref.</param>
 /// <param name="guidVendorRef">The GUID vendor ref.</param>
 /// <param name="metadataOptions">The metadata options.</param>
 /// <unmanaged>HRESULT IWICImagingFactory::CreateDecoderFromStream([In, Optional] IStream* pIStream,[In, Optional] const GUID* pguidVendor,[In] WICDecodeOptions metadataOptions,[Out, Fast] IWICBitmapDecoder** ppIDecoder)</unmanaged>
 public BitmapDecoder(ImagingFactory factory, IStream streamRef, System.Guid guidVendorRef, SharpDX.WIC.DecodeOptions metadataOptions)
 {
     factory.CreateDecoderFromStream_(ComStream.ToIntPtr(streamRef), guidVendorRef, metadataOptions, this);
 }
        //private string CreateFont(string fontName, float fontSize, CCRawList<char> charset)
        private Font CreateFont(string fontName, float fontSize)
        {
            Font _currentFont;

            if (Factory2D == null)
            {
                Factory2D = new SharpDX.Direct2D1.Factory();
                FactoryDWrite = new SharpDX.DirectWrite.Factory();
                FactoryImaging = new SharpDX.WIC.ImagingFactory();

                dpi = Factory2D.DesktopDpi;
                dpiScale = dpi.Height / 72f;

            }

            _currentFontCollection = FactoryDWrite.GetSystemFontCollection(true);

            if (_defaultFont == null)
            {
                _defaultFont = GenericSanSerif();
            }

            FontFamily fontFamily = GetFontFamily(fontName);


            FontCollection fontCollection;

            if (!_fontCollectionCache.TryGetValue(fontName, out fontCollection))
            {
                var ext = Path.GetExtension(fontName);

                if (!String.IsNullOrEmpty(ext) && ext.ToLower() == ".ttf")
                {
                    try
                    {
                        var fileFontLoader = new FileFontLoader(FactoryDWrite, fontName);
                        var fileFontCollection = new FontCollection(FactoryDWrite, fileFontLoader, fileFontLoader.Key);
                        _currentFontCollection = fileFontCollection;
                        fontFamily = _currentFontCollection.GetFontFamily(0);
                        var ffn = fontFamily.FamilyNames;
                        _currentFont = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);

                        _fontCollectionCache.Add(fontName, fileFontCollection);
                        _currentFontCollection = fileFontCollection;
                    }
                    catch
                    {
                        _currentFont = GetFont(fontName, fontSize);
                        CCLog.Log("{0} not found.  Defaulting to {1}.", fontName, _currentFont.FontFamily.FamilyNames.GetString(0));
                    }
                }
                else
                {
                    _currentFont = GetFont(fontName, fontSize);
                }

            }
            else
            {
                fontFamily = fontCollection.GetFontFamily(0);

                _currentFont = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);
                _currentFontCollection = fontCollection;
            }

            return _currentFont;
        }
Ejemplo n.º 43
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ColorTransform"/> class.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <unmanaged>HRESULT IWICImagingFactory::CreateColorTransformer([Out, Fast] IWICColorTransform** ppIWICColorTransform)</unmanaged>	
 public ColorTransform(ImagingFactory factory)
     : base(IntPtr.Zero)
 {
     factory.CreateColorTransformer(this);
 }
Ejemplo n.º 44
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GifBitmapDecoder"/> class.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="guidVendorRef">The GUID vendor ref.</param>
 public GifBitmapDecoder(ImagingFactory factory, Guid guidVendorRef)
     : base(factory, ContainerFormatGuids.Gif, guidVendorRef)
 {
 }
Ejemplo n.º 45
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BmpBitmapDecoder"/> class.
 /// </summary>
 /// <param name="factory">The factory.</param>
 public BmpBitmapDecoder(ImagingFactory factory)
     : base(factory, ContainerFormatGuids.Bmp)
 {
 }
Ejemplo n.º 46
0
        //private string CreateFont(string fontName, float fontSize, CCRawList<char> charset)
        private Font CreateFont(string fontName, float fontSize)
        {
            Font _currentFont;

            if (Factory2D == null)
            {
                Factory2D      = new SharpDX.Direct2D1.Factory();
                FactoryDWrite  = new SharpDX.DirectWrite.Factory();
                FactoryImaging = new SharpDX.WIC.ImagingFactory();

                dpi      = Factory2D.DesktopDpi;
                dpiScale = dpi.Height / 72f;
            }

            _currentFontCollection = FactoryDWrite.GetSystemFontCollection(true);

            if (_defaultFont == null)
            {
                _defaultFont = GenericSanSerif();
            }

            FontFamily fontFamily = GetFontFamily(fontName);


            FontCollection fontCollection;

            if (!_fontCollectionCache.TryGetValue(fontName, out fontCollection))
            {
                var ext = Path.GetExtension(fontName);

                if (!String.IsNullOrEmpty(ext) && ext.ToLower() == ".ttf")
                {
                    try
                    {
                        var fileFontLoader     = new FileFontLoader(FactoryDWrite, fontName);
                        var fileFontCollection = new FontCollection(FactoryDWrite, fileFontLoader, fileFontLoader.Key);
                        _currentFontCollection = fileFontCollection;
                        fontFamily             = _currentFontCollection.GetFontFamily(0);
                        var ffn = fontFamily.FamilyNames;
                        _currentFont = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);

                        _fontCollectionCache.Add(fontName, fileFontCollection);
                        _currentFontCollection = fileFontCollection;
                    }
                    catch
                    {
                        _currentFont = GetFont(fontName, fontSize);
                        CCLog.Log("{0} not found.  Defaulting to {1}.", fontName, _currentFont.FontFamily.FamilyNames.GetString(0));
                    }
                }
                else
                {
                    _currentFont = GetFont(fontName, fontSize);
                }
            }
            else
            {
                fontFamily = fontCollection.GetFontFamily(0);

                _currentFont           = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);
                _currentFontCollection = fontCollection;
            }

            return(_currentFont);
        }
Ejemplo n.º 47
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GifBitmapEncoder"/> class.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="guidVendorRef">The GUID vendor ref.</param>
 /// <param name="stream">The output stream.</param>
 public GifBitmapEncoder(ImagingFactory factory, Guid guidVendorRef, WICStream stream = null)
     : base(factory, ContainerFormatGuids.Gif, guidVendorRef, stream)
 {
 }
Ejemplo n.º 48
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BitmapDecoder"/> class from a <see cref="IStream"/>.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="streamRef">The stream ref.</param>
 /// <param name="metadataOptions">The metadata options.</param>
 /// <unmanaged>HRESULT IWICImagingFactory::CreateDecoderFromStream([In, Optional] IStream* pIStream,[In, Optional] const GUID* pguidVendor,[In] WICDecodeOptions metadataOptions,[Out, Fast] IWICBitmapDecoder** ppIDecoder)</unmanaged>
 public BitmapDecoder(ImagingFactory factory, Stream streamRef, SharpDX.WIC.DecodeOptions metadataOptions)
 {
     internalWICStream = new WICStream(factory, streamRef);
     factory.CreateDecoderFromStream_(ComStream.ToIntPtr(internalWICStream), null, metadataOptions, this);
 }
Ejemplo n.º 49
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GifBitmapEncoder"/> class.
 /// </summary>
 /// <param name="factory">The factory.</param>
 public GifBitmapEncoder(ImagingFactory factory)
     : base(factory, ContainerFormatGuids.Gif)
 {
 }
Ejemplo n.º 50
0
     /// <summary>
     /// Initializes a new instance of the <see cref="BitmapDecoder"/> class.
     /// </summary>
     /// <param name="factory">The factory.</param>
     /// <param name="containerFormatGuid">The container format GUID.</param>
     /// <param name="guidVendorRef">The GUID vendor ref.</param>
     /// <unmanaged>HRESULT IWICImagingFactory::CreateDecoder([In] const GUID&amp; guidContainerFormat,[In, Optional] const GUID* pguidVendor,[Out, Fast] IWICBitmapDecoder** ppIDecoder)</unmanaged>	
     public BitmapDecoder(ImagingFactory factory, Guid containerFormatGuid, System.Guid guidVendorRef)
     {
         factory.CreateDecoder(containerFormatGuid, guidVendorRef, this);        
 
     }
Ejemplo n.º 51
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BitmapDecoder"/> class from a guid. <see cref="BitmapDecoderGuids"/> for a list of default supported decoder.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="containerFormatGuid">The container format GUID.</param>
 /// <unmanaged>HRESULT IWICImagingFactory::CreateDecoder([In] const GUID&amp; guidContainerFormat,[In, Optional] const GUID* pguidVendor,[Out, Fast] IWICBitmapDecoder** ppIDecoder)</unmanaged>	
 public BitmapDecoder(ImagingFactory factory, Guid containerFormatGuid)
 {
     factory.CreateDecoder(containerFormatGuid, null, this);
 }
Ejemplo n.º 52
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BitmapDecoder"/> class from a filestream.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="fileStream">The filename.</param>
 /// <param name="guidVendorRef">The GUID vendor ref.</param>
 /// <param name="metadataOptions">The metadata options.</param>
 /// <unmanaged>HRESULT IWICImagingFactory::CreateDecoderFromFileHandle([In] unsigned int hFile,[In, Optional] const GUID* pguidVendor,[In] WICDecodeOptions metadataOptions,[Out, Fast] IWICBitmapDecoder** ppIDecoder)</unmanaged>	
 public BitmapDecoder(ImagingFactory factory, FileStream fileStream, System.Guid guidVendorRef, SharpDX.WIC.DecodeOptions metadataOptions)
 {
     factory.CreateDecoderFromFileHandle(fileStream.SafeFileHandle.DangerousGetHandle(), guidVendorRef, metadataOptions, this);
 }
Ejemplo n.º 53
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BitmapDecoder"/> class from a file.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="filename">The filename.</param>
 /// <param name="guidVendorRef">The GUID vendor ref.</param>
 /// <param name="desiredAccess">The desired access.</param>
 /// <param name="metadataOptions">The metadata options.</param>
 /// <unmanaged>HRESULT IWICImagingFactory::CreateDecoderFromFilename([In] const wchar_t* wzFilename,[In, Optional] const GUID* pguidVendor,[In] unsigned int dwDesiredAccess,[In] WICDecodeOptions metadataOptions,[Out, Fast] IWICBitmapDecoder** ppIDecoder)</unmanaged>
 public BitmapDecoder(ImagingFactory factory, string filename, System.Guid? guidVendorRef, NativeFileAccess desiredAccess, SharpDX.WIC.DecodeOptions metadataOptions)
 {
     factory.CreateDecoderFromFilename(filename, guidVendorRef, (int)desiredAccess, metadataOptions, this);
 }
Ejemplo n.º 54
0
 public static void CreateIndependentResource()
 {
     Factory2D    = new Direct2D1.Factory();
     imageFactory = new WIC.ImagingFactory();
     writeFactory = new DirectWrite.Factory();
 }
Ejemplo n.º 55
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GifBitmapEncoder"/> class.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="stream">The output stream.</param>
 public GifBitmapEncoder(ImagingFactory factory, Stream stream = null)
     : base(factory, ContainerFormatGuids.Gif, stream)
 {
 }
Ejemplo n.º 56
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BmpBitmapDecoder"/> class.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="guidVendorRef">The GUID vendor ref.</param>
 public BmpBitmapDecoder(ImagingFactory factory, Guid guidVendorRef)
     : base(factory, ContainerFormatGuids.Bmp, guidVendorRef)
 {
 }
Ejemplo n.º 57
0
        private string CreateFont(string fontName, float fontSize, CCRawList <char> charset)
        {
            if (Factory2D == null)
            {
                Factory2D      = new SharpDX.Direct2D1.Factory();
                FactoryDWrite  = new SharpDX.DirectWrite.Factory();
                FactoryImaging = new SharpDX.WIC.ImagingFactory();

                dpi      = Factory2D.DesktopDpi;
                dpiScale = dpi.Height / 72f;
            }

            if (_defaultFont == null)
            {
                _defaultFont = GenericSanSerif();
                //_defaultDIP = ConvertPointSizeToDIP(_defaultFontSizeEm);
            }

            FontFamily fontFamily = GetFontFamily(fontName);


            if (!_fontFamilyCache.TryGetValue(fontName, out fontFamily))
            {
                var ext = Path.GetExtension(fontName);

                _currentFont = _defaultFont;

                if (!String.IsNullOrEmpty(ext) && ext.ToLower() == ".ttf")
                {
                    //var appPath = AppDomain.CurrentDomain.BaseDirectory;
                    //var contentPath = Path.Combine(appPath, CCApplication.SharedApplication.Content.RootDirectory);
                    //var fontPath = Path.Combine(contentPath, fontName);

                    //if (File.Exists(fontPath))
                    //{
                    // try
                    //{
                    //var fontFileReference = new FontCollection(
                    //_loadedFonts.AddFontFile(fontPath);

                    //        //fontFamily = _loadedFonts.Families[_loadedFonts.Families.Length - 1];

                    //        //_currentFont = new Font(fontFamily, fontSize);
                    //    }
                    //    catch
                    //    {
                    //        _currentFont = _defaultFont;
                    //    }
                    //}
                    //else
                    //{
                    _currentFont       = _defaultFont;
                    _currentFontSizeEm = fontSize;
                    _currentDIP        = ConvertPointSizeToDIP(fontSize);
                    //}
                }
                else
                {
                    _currentFont       = GetFont(fontName, fontSize);
                    _currentFontSizeEm = fontSize;
                    _currentDIP        = ConvertPointSizeToDIP(fontSize);
                }

                _fontFamilyCache.Add(fontName, _currentFont.FontFamily);
            }
            else
            {
                _currentFont       = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);
                _currentFontSizeEm = fontSize;
                _currentDIP        = ConvertPointSizeToDIP(fontSize);
            }
            fontName   = _currentFont.FontFamily.FamilyNames.GetString(0);
            textFormat = new TextFormat(FactoryDWrite, fontName, _currentDIP);

            GetKerningInfo(charset);

            return(_currentFont.ToString());
        }
Ejemplo n.º 58
0
        private string CreateFont(string fontName, float fontSize, CCRawList<char> charset)
        {

            if (Factory2D == null)
            {
                Factory2D = new SharpDX.Direct2D1.Factory();
                FactoryDWrite = new SharpDX.DirectWrite.Factory();
                FactoryImaging = new SharpDX.WIC.ImagingFactory();
                
                dpi = Factory2D.DesktopDpi;
                dpiScale = dpi.Height / 72f;
            }

            if (_defaultFont == null)
            {
                _defaultFont = GenericSanSerif();
                //_defaultDIP = ConvertPointSizeToDIP(_defaultFontSizeEm);
            }

            FontFamily fontFamily = GetFontFamily(fontName);


            if (!_fontFamilyCache.TryGetValue(fontName, out fontFamily))
            {
                var ext = Path.GetExtension(fontName);

                _currentFont = _defaultFont;

                if (!String.IsNullOrEmpty(ext) && ext.ToLower() == ".ttf")
                {
                    //var appPath = AppDomain.CurrentDomain.BaseDirectory;
                    //var contentPath = Path.Combine(appPath, CCApplication.SharedApplication.Content.RootDirectory);
                    //var fontPath = Path.Combine(contentPath, fontName);

                    //if (File.Exists(fontPath))
                    //{
                       // try
                        //{
                            //var fontFileReference = new FontCollection(
                            //_loadedFonts.AddFontFile(fontPath);

                    //        //fontFamily = _loadedFonts.Families[_loadedFonts.Families.Length - 1];

                    //        //_currentFont = new Font(fontFamily, fontSize);
                    //    }
                    //    catch
                    //    {
                    //        _currentFont = _defaultFont;
                    //    }
                    //}
                    //else
                    //{
                        _currentFont = _defaultFont;
                        _currentFontSizeEm = fontSize;
                        _currentDIP = ConvertPointSizeToDIP(fontSize);
                    //}
                }
                else
                {
                    _currentFont = GetFont(fontName, fontSize);
                    _currentFontSizeEm = fontSize;
                    _currentDIP = ConvertPointSizeToDIP(fontSize);
                }

                _fontFamilyCache.Add(fontName, _currentFont.FontFamily);
            }
            else
            {
                _currentFont = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);
                _currentFontSizeEm = fontSize;
                _currentDIP = ConvertPointSizeToDIP(fontSize);
            }
            fontName = _currentFont.FontFamily.FamilyNames.GetString(0); 
            textFormat = new TextFormat(FactoryDWrite, fontName, _currentDIP);
            
            GetKerningInfo(charset);

            return _currentFont.ToString();
        }
Ejemplo n.º 59
0
 public BitmapManager(WIC.ImagingFactory imagingFactory)
 {
     _imagingFactory = imagingFactory;
 }
Ejemplo n.º 60
0
 static Tools()
 {
     _factory = new SharpDX.WIC.ImagingFactory();
 }