예제 #1
0
        async void LoadImage(object sender, RoutedEventArgs e)
        {
            var picker = new FileOpenPicker();

            picker.FileTypeFilter.Add(".ico");
            picker.FileTypeFilter.Add(".bmp");
            picker.FileTypeFilter.Add(".gif");
            picker.FileTypeFilter.Add(".png");
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".jxr");
            picker.FileTypeFilter.Add(".tif");
            picker.FileTypeFilter.Add(".tiff");

            StorageFile file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                try
                {
                    await _bitmap.LoadAsync(file, new FormatConverter(PixelFormat.Format32bppPBGRA));

                    ClearSavedCopy();
                    _savedCopy = _bitmap.Transform();

                    CreateImageSource();
                }
                catch (Exception ex)
                {
                    LoadDefaultImage();
                    MessageDialog md = new MessageDialog(Strings.ImageFormatNotSupportedException + ex.Message, "");
                    await md.ShowAsync();
                }
            }
        }
예제 #2
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;
        }