コード例 #1
0
        /// <summary>
        /// サムネイル作成
        /// </summary>
        /// <param name="thumbnailhash">既存のサムネイルを、baseImageFilePathで生成しなおしたい場合、
        /// 既存のサムネイル情報を示すキーを指定します。それ以外は、NULLを指定します。</param>
        /// <param name="baseImageFilePath">サムネイル生成元の画像ファイルパス</param>
        /// <returns></returns>
        public string BuildThumbnail(string thumbnailhash, string baseImageFilePath)
        {
            if (thumbnailhash != null)
            {
                mLogger.Info("サムネイル({ThumbnailHash})の作成を開始します", thumbnailhash);
            }
            else
            {
                mLogger.Info("サムネイル({baseImageFilePath})の作成を開始します", baseImageFilePath);
            }

            string _ThumbnailKey = null;

            Byte[] imageByte = null;

            imageByte = LoadImageBytes(baseImageFilePath);

            if (imageByte == null)
            {
                throw new ApplicationException();               // 画像ファイルを取得できなかった。
            }
            var resizedImage1 = CreateImage(imageByte, 300, 0); // 生成するサムネイル画像の大きさは「300」(TODO?)

            // サムネイル種類別にすべてのサムネイルを生成する
            foreach (ThumbnailType thmbType in Enum.GetValues(typeof(ThumbnailType)))
            {
                ThumbnailInfoAttribute[] infos = (ThumbnailInfoAttribute[])thmbType.GetType().GetField(thmbType.ToString()).GetCustomAttributes(typeof(ThumbnailInfoAttribute), false);
                if (infos.Length > 0)
                {
                    var @attr = infos[0];

                    var resizedImage = CreateImage(imageByte, @attr.Width, @attr.Height); // 生成するサムネイル画像の大きさは「300」(TODO?)
                    using (Image <Rgba32> image = Image.Load(imageByte)) {
                        image.Mutate(x => x.Resize(@attr.Width, @attr.Height));

                        var invoker = new ThumbnailEncodingInvoker(thumbnailhash, image, thmbType, thumbnailRepository);
                        invoker.Do();

                        _ThumbnailKey = invoker.ThumbnailKey;
                        thumbnailhash = _ThumbnailKey;
                    }
                }
            }
            //thumbnailRepository.Save ();

            return(_ThumbnailKey);
        }
コード例 #2
0
        /// <summary>
        /// サムネイル作成
        /// </summary>
        /// <param name="thumbnailhash">既存のサムネイルを、baseImageFilePathで生成しなおしたい場合、
        /// 既存のサムネイル情報を示すキーを指定します。それ以外は、NULLを指定します。</param>
        /// <param name="baseImageFilePath">サムネイル生成元の画像ファイルパス</param>
        /// <returns></returns>
        public string BuildThumbnail(string thumbnailhash, string baseImageFilePath)
        {
            LOG.Debug("サムネイルの作成を開始します");
            string _ThumbnailKey = null;

            Byte[] imageByte = null;
            {
                imageByte = LoadImageBytes(baseImageFilePath);

                if (imageByte == null)
                {
                    throw new ApplicationException();                                    // 画像ファイルを取得できなかった。
                }
                // サムネイル種類別にすべてのサムネイルを生成する
                foreach (ThumbnailType thmbType in Enum.GetValues(typeof(ThumbnailType)))
                {
                    ThumbnailInfoAttribute[] infos = (ThumbnailInfoAttribute[])thmbType.GetType().GetField(thmbType.ToString()).GetCustomAttributes(typeof(ThumbnailInfoAttribute), false);
                    if (infos.Length > 0)
                    {
                        var @attr = infos[0];

                        var resizedImage = CreateImage(imageByte, @attr.Width, @attr.Height);                         // 生成するサムネイル画像の大きさは「300」(TODO?)

                        var invoker            = new ThumbnailEncodingInvoker(thumbnailhash, resizedImage, thmbType);
                        var encodingBackground = new BackgroundWorker();
                        encodingBackground.DoWork += invoker.Do;
                        encodingBackground.RunWorkerAsync();

                        // スレッドの処理が完了するまで待機
                        while (encodingBackground.IsBusy)
                        {
                            //await Task.Delay(10);
                            System.Threading.Thread.Sleep(1);
                        }

                        _ThumbnailKey              = invoker.ThumbnailKey;
                        thumbnailhash              = _ThumbnailKey;
                        encodingBackground.DoWork -= invoker.Do;
                    }
                }
            }
            LOG.Debug("サムネイルの作成を完了します");
            return(_ThumbnailKey);
        }