コード例 #1
0
        public static List <ImageFormat> GetSupportedEncodingImageFormats()
        {
            List <ImageFormat> decodeFormats = BitmapDecoder.GetDecoderInformationEnumerator()
                                               .Select(e => new ImageFormat(e))
                                               .ToList();

            List <ImageFormat> encodeFormats = BitmapEncoder.GetEncoderInformationEnumerator()
                                               .Select(e => new ImageFormat(e))
                                               .ToList();

            if (SupportedEncodeFileTypes == null)
            {
                SupportedEncodeFileTypes = encodeFormats.SelectMany(f => f.CodecInfo.FileExtensions)
                                           .Distinct()
                                           .ToList();

                SupportedDecodeFileTypes = decodeFormats.SelectMany(f => f.CodecInfo.FileExtensions)
                                           .Distinct()
                                           .Select(e => e.ToLower())
                                           .ToHashSet();
            }

            /* Creates a list of output formats (for store listings) */
#if DEBUG
            string fo = string.Join(Environment.NewLine, SupportedDecodeFileTypes);
#endif

            return(encodeFormats);
        }
コード例 #2
0
        async Task LoadFileFromOpenPicker()
        {
            // Create FileOpenPicker
            FileOpenPicker picker = new FileOpenPicker();

            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;

            // Initialize with filename extensions
            IReadOnlyList <BitmapCodecInformation> codecInfos =
                BitmapDecoder.GetDecoderInformationEnumerator();

            foreach (BitmapCodecInformation codecInfo in codecInfos)
            {
                foreach (string extension in codecInfo.FileExtensions)
                {
                    picker.FileTypeFilter.Add(extension);
                }
            }

            // Get the selected file
            StorageFile storageFile = await picker.PickSingleFileAsync();

            if (storageFile == null)
            {
                return;
            }

            string exception = null;

            try
            {
                await LoadBitmapFromFile(storageFile);
            }
            catch (Exception exc)
            {
                exception = exc.Message;
            }

            if (exception != null)
            {
                MessageDialog msgdlg =
                    new MessageDialog("The image file could not be loaded. " +
                                      "The system reports an error of: " + exception,
                                      "Finger Paint");
                await msgdlg.ShowAsync();

                return;
            }

            appSettings.LoadedFilePath  = storageFile.Path;
            appSettings.LoadedFilename  = storageFile.Name;
            appSettings.IsImageModified = false;
        }
コード例 #3
0
        /// <summary>
        /// Retrieves all of the file extensions supported by the bitmap codecs on the system,
        /// and inserts them into the provided fileTypeFilter parameter.
        /// </summary>
        /// <param name="fileTypeFilter">FileOpenPicker.FileTypeFilter member</param>
        public static void FillDecoderExtensions(IList <string> fileTypeFilter)
        {
            IReadOnlyList <BitmapCodecInformation> codecInfoList =
                BitmapDecoder.GetDecoderInformationEnumerator();

            foreach (BitmapCodecInformation decoderInfo in codecInfoList)
            {
                // Each bitmap codec contains a list of file extensions it supports; add each
                // list item to fileTypeFilter.
                foreach (string extension in decoderInfo.FileExtensions)
                {
                    fileTypeFilter.Add(extension);
                }
            }
        }
コード例 #4
0
        async void OnOpenAppBarButtonClick(object sender, RoutedEventArgs args)
        {
            // Create FileOpenPicker
            FileOpenPicker picker = new FileOpenPicker();

            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;

            // Initialize with filename extensions
            IReadOnlyList <BitmapCodecInformation> codecInfos =
                BitmapDecoder.GetDecoderInformationEnumerator();

            foreach (BitmapCodecInformation codecInfo in codecInfos)
            {
                foreach (string extension in codecInfo.FileExtensions)
                {
                    picker.FileTypeFilter.Add(extension);
                }
            }

            // Get the selected file
            StorageFile storageFile = await picker.PickSingleFileAsync();

            if (storageFile == null)
            {
                return;
            }

            // Open the stream and create a decoder
            BitmapDecoder decoder = null;

            using (IRandomAccessStreamWithContentType stream = await storageFile.OpenReadAsync())
            {
                string exception = null;

                try
                {
                    decoder = await BitmapDecoder.CreateAsync(stream);
                }
                catch (Exception exc)
                {
                    exception = exc.Message;
                }

                if (exception != null)
                {
                    MessageDialog msgdlg =
                        new MessageDialog("That particular image file could not be loaded. " +
                                          "The system reports on error of: " + exception);
                    await msgdlg.ShowAsync();

                    return;
                }

                // Get the first frame
                BitmapFrame bitmapFrame = await decoder.GetFrameAsync(0);

                // Set information title
                txtblk.Text = String.Format("{0}: {1} x {2} {3} {4} x {5} DPI",
                                            storageFile.Name,
                                            bitmapFrame.PixelWidth, bitmapFrame.PixelHeight,
                                            bitmapFrame.BitmapPixelFormat,
                                            bitmapFrame.DpiX, bitmapFrame.DpiY);
                // Save the resolution
                dpiX = bitmapFrame.DpiX;
                dpiY = bitmapFrame.DpiY;

                // Get the pixels
                PixelDataProvider dataProvider =
                    await bitmapFrame.GetPixelDataAsync(BitmapPixelFormat.Bgra8,
                                                        BitmapAlphaMode.Premultiplied,
                                                        new BitmapTransform(),
                                                        ExifOrientationMode.RespectExifOrientation,
                                                        ColorManagementMode.ColorManageToSRgb);

                byte[] pixels = dataProvider.DetachPixelData();

                // Create WriteableBitmap and set the pixels
                WriteableBitmap bitmap = new WriteableBitmap((int)bitmapFrame.PixelWidth,
                                                             (int)bitmapFrame.PixelHeight);

                using (Stream pixelStream = bitmap.PixelBuffer.AsStream())
                {
                    await pixelStream.WriteAsync(pixels, 0, pixels.Length);
                }

                // Invalidate the WriteableBitmap and set as Image source
                bitmap.Invalidate();
                image.Source = bitmap;
            }

            // Enable the other buttons
            saveAsButton.IsEnabled      = true;
            rotateLeftButton.IsEnabled  = true;
            rotateRightButton.IsEnabled = true;
        }
コード例 #5
0
        /// <inheritdoc />
        public IVpaid GetPlayer(ICreativeSource creativeSource)
        {
            if (!IsEnabled || creativeSource.MimeType == null)
            {
                return(null);
            }
            var skippableOffset = creativeSource.SkippableOffset ?? SkippableOffset;

            if (creativeSource.Type == CreativeSourceType.Linear)
            {
                if (creativeSource.ApiFramework == "VPAID")
                {
                    //switch (creativeSource.MimeType)
                    //{
                    //    case "application/x-javascript":
                    //        return new VpaidJavaScriptAdPlayer(skippableOffset, creativeSource.Duration, creativeSource.ClickUrl) { Style = VpaidWebAdPlayerStyle };
                    //}
                }
                else
                {
#if SILVERLIGHT
                    if (SupportedVideoMimeTypes.Contains(creativeSource.MimeType.ToLowerInvariant()))
#else
                    if (SupportedVideoMimeTypes.Contains(creativeSource.MimeType.ToLowerInvariant()) || CanPlayCodec(creativeSource.Codec))
#endif
                    {
                        return(new VpaidVideoAdPlayer(skippableOffset, creativeSource.Duration, creativeSource.ClickUrl)
                        {
                            Style = VpaidVideoAdPlayerStyle,
#if NETFX_CORE
                            AudioCategory = MediaPlayer.AudioCategory
#endif
                        });
                    }
                }
            }
            else if (creativeSource.Type == CreativeSourceType.NonLinear)
            {
                switch (creativeSource.MediaSourceType)
                {
                case MediaSourceEnum.Static:
#if SILVERLIGHT
                    if (creativeSource.MimeType.ToLowerInvariant().StartsWith("image/"))
#else
                    if (BitmapDecoder.GetDecoderInformationEnumerator().SelectMany(d => d.MimeTypes).Select(m => m.ToLowerInvariant()).Contains(creativeSource.MimeType.ToLowerInvariant()))
#endif
                    {
                        return(new VpaidImageAdPlayer(skippableOffset, creativeSource.Duration, creativeSource.ClickUrl)
                        {
                            Style = VpaidImageAdPlayerStyle
                        });
                    }
                    else
                    {
                        return(null);
                    }

                case MediaSourceEnum.IFrame:
                    return(new VpaidIFrameAdPlayer(skippableOffset, creativeSource.Duration, creativeSource.ClickUrl, creativeSource.Dimensions)
                    {
                        Style = VpaidWebAdPlayerStyle
                    });

                case MediaSourceEnum.HTML:
                    return(new VpaidHtmlAdPlayer(skippableOffset, creativeSource.Duration, creativeSource.ClickUrl, creativeSource.Dimensions)
                    {
                        Style = VpaidWebAdPlayerStyle
                    });
                }
            }
            return(null);
        }