示例#1
0
        async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            // locate the image
            var imageUri    = new Uri("ms-appx:///Assets/GcLogo.png");
            var storageFile = await StorageFile.GetFileFromApplicationUriAsync(imageUri);

            // load the image into C1Bitmap
            _bitmap = new C1Bitmap();
            await _bitmap.LoadAsync(storageFile, new FormatConverter(PixelFormat.Format32bppPBGRA));

            // create Direct2D and DirectWrite factories
            _d2dFactory = D2D.Factory2.Create(D2D.FactoryType.SingleThreaded);
            _dwFactory  = DW.Factory.Create(DW.FactoryType.Shared);

            // create GPU resources
            CreateDeviceResources();

            // create the image source
            _imageSource = new SurfaceImageSource(_marginLT + _bitmap.PixelWidth + _marginRB, _marginLT + _bitmap.PixelHeight + _marginRB, false);

            // obtain the native interface for the image source
            _sisNative = ComObject.QueryInterface <DXGI.ISurfaceImageSourceNative>(_imageSource);
            _sisNative.SetDevice(_dxgiDevice);

            // draw the image to SurfaceImageSource
            UpdateImageSource(ImageEffect.Original);

            // associate the image source with the Image
            image.Source = _imageSource;
        }
示例#2
0
        void InitResources()
        {
            // load the image into C1Bitmap
            _bitmap = new C1Bitmap();
            Assembly asm = typeof(MainWindow).Assembly;

            using (Stream stream = asm.GetManifestResourceStream("Direct2DEffects.Resources.GcLogo.png"))
            {
                _bitmap.Load(stream, new FormatConverter(C1.WPF.Bitmap.PixelFormat.Format32bppPBGRA));
            }

            // create Direct2D and DirectWrite factories
            _d2dFactory = D2D.Factory2.Create(D2D.FactoryType.SingleThreaded);
            _dwFactory  = DW.Factory.Create(DW.FactoryType.Shared);

            // create GPU resources
            CreateDeviceResources();
        }
示例#3
0
        public MainForm()
        {
            InitializeComponent();

            // load the image into C1Bitmap
            _bitmap = new C1Bitmap();
            Assembly asm = typeof(MainForm).Assembly;

            using (Stream stream = asm.GetManifestResourceStream("Direct2DEffects.Resources.GcLogo.png"))
            {
                _bitmap.Load(stream, new FormatConverter(PixelFormat.Format32bppPBGRA));
            }

            // create Direct2D and DirectWrite factories
            _d2dFactory = D2D.Factory2.Create(D2D.FactoryType.SingleThreaded);
            _dwFactory  = DW.Factory.Create(DW.FactoryType.Shared);

            // create GPU resources
            CreateDeviceResources();

            // fill the list of available effects
            var coll = effectsCombo.Items;

            coll.Add(new EffectItem(ImageEffect.Original, "Original Image"));
            coll.Add(new EffectItem(ImageEffect.GaussianBlur, "Gaussian Blur"));
            coll.Add(new EffectItem(ImageEffect.Sharpen, "Sharpen"));
            coll.Add(new EffectItem(ImageEffect.HorizontalSmear, "Horizontal Smear"));
            coll.Add(new EffectItem(ImageEffect.Shadow, "Shadow"));
            coll.Add(new EffectItem(ImageEffect.DisplacementMap, "Displacement Map"));
            coll.Add(new EffectItem(ImageEffect.Emboss, "Emboss"));
            coll.Add(new EffectItem(ImageEffect.EdgeDetect, "Edge Detect"));
            coll.Add(new EffectItem(ImageEffect.Sepia, "Sepia"));
            effectsCombo.SelectedIndex             = 0;
            effectsCombo.SelectionChangeCommitted += effectsCombo_SelectionChangeCommitted;

            // display the original image
            UpdateImageSource(ImageEffect.Original);
        }
示例#4
0
 void CreateDeviceIndependentResources()
 {
     _d2dFactory = D2D.Factory2.Create(D2D.FactoryType.SingleThreaded);
     _wicFactory = WIC.ImagingFactory2.Create();
 }