Example #1
0
        /// <summary>
        /// 再裁剪
        /// </summary>
        /// <param name="image"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        private static Image Cutting(Image image, int width, int height, CuttingMethod cuttingMethod = CuttingMethod.LeftTop, int?x = null, int?y = null)
        {
            Bitmap m_hovertreeBmp = new Bitmap(width, height);
            //从Bitmap创建一个System.Drawing.Graphics
            Graphics m_HvtGr = Graphics.FromImage(m_hovertreeBmp);

            //设置
            m_HvtGr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            //下面这个也设成高质量
            m_HvtGr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            //下面这个设成High
            m_HvtGr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

            int m_width, m_height;

            if (image.Width * height > image.Height * width)
            {
                m_height = image.Height;
                m_width  = (image.Height * width) / height;
            }
            else
            {
                m_width  = image.Width;
                m_height = (image.Width * height) / width;
            }
            //原始图像需要裁剪的区域
            Rectangle srcDestination = GetRectangle(cuttingMethod, image.Width, image.Height, width, height, x, y);

            m_HvtGr.DrawImage(image, new Rectangle(0, 0, width, height), srcDestination, GraphicsUnit.Pixel);

            return(m_hovertreeBmp);
        }
Example #2
0
        /// <summary>
        /// 为图片生成缩略图
        /// </summary>
        /// <param name="phyPath">原图片的路径</param>
        /// <param name="width">缩略图宽</param>
        /// <param name="height">缩略图高</param>
        /// <param name="cuttingMethod">裁剪方式</param>
        /// <param name="x">自定义裁剪方式时,x坐标</param>
        /// <param name="y">自定义裁剪方式时,y坐标</param>
        /// <returns></returns>
        public static Image GetHvtThumbnail(Image image, int width, int height, CuttingMethod cuttingMethod = CuttingMethod.LeftTop, int?x = null, int?y = null)
        {
            var img  = Shrink(image, width, height);
            var img2 = Cutting(img, width, height, cuttingMethod, x, y);

            return(img2);
        }
Example #3
0
        public bool Index2ndResolution(string[] args)
        {
            if (args.Length < 2)
            {
                Herald.Announce(Herald.MessageType.Error, string.Format("Invalid arguments."));
                return(false);
            }

            int           binCount      = 0;
            CuttingMethod cuttingMethod = CuttingMethod.ZeroThresholding;

            switch (args[1].ToLower())
            {
            case "zt":
            case "zerothresholding":
                cuttingMethod = CuttingMethod.ZeroThresholding;
                break;

            case "uq":
            case "uniformscalarquantization":
                cuttingMethod = CuttingMethod.UniformScalarQuantization;
                if (args.Length != 3)
                {
                    Herald.Announce(Herald.MessageType.Error, string.Format("Invalid arguments."));
                    return(false);
                }
                if (!int.TryParse(args[2], out binCount))
                {
                    Herald.Announce(Herald.MessageType.Error, string.Format("Invalid arguments."));
                    return(false);
                }
                break;

            case "nuq":
            case "nonuniformscalarquantization":
                cuttingMethod = CuttingMethod.NonUniformScalarQuantization;
                if (args.Length != 3)
                {
                    Herald.Announce(Herald.MessageType.Error, string.Format("Invalid arguments."));
                    return(false);
                }
                if (!int.TryParse(args[2], out binCount))
                {
                    Herald.Announce(Herald.MessageType.Error, string.Format("Invalid arguments."));
                    return(false);
                }
                break;

            default:
                Herald.Announce(Herald.MessageType.Error, string.Format("Invalid arguments."));
                return(false);
            }

            Herald.AnnounceExeReport("2RIndex", di4B.SecondResolutionIndex(cuttingMethod, binCount, _maxDegreeOfParallelism), speedUnit: Herald.SpeedUnit.blockPerSecond);
            return(true);
        }
Example #4
0
 internal BatchIndex2R(BPlusTree <C, B> di41R, BPlusTree <BlockKey <C>, BlockValue> di42R, C left, C right, CuttingMethod cuttingMethod, int levels, ConcurrentDictionary <C, int> addedBlocks)
 {
     _di41R         = di41R;
     _di42R         = di42R;
     _left          = left;
     _right         = right;
     _addedBlocks   = addedBlocks;
     _cuttingMethod = cuttingMethod;
     _levels        = levels;
     _bCounter      = new BlockCounter();
 }
Example #5
0
        private static Rectangle GetRectangle(CuttingMethod cuttingMethod, int m_width, int m_height, int width, int height, int?x, int?y)
        {
            int _x = 0;
            int _y = 0;

            switch (cuttingMethod)
            {
            case CuttingMethod.LeftTop:
                _x = 0;
                _y = 0;
                break;

            case CuttingMethod.LeftBottom:
                _x = 0;
                _y = m_height - height;
                break;

            case CuttingMethod.Center:
                _x = (m_width - width) / 2;
                _y = (m_height - height) / 2;
                break;

            case CuttingMethod.Customize:
                if (!x.HasValue || !y.HasValue)
                {
                    throw new UserFriendlyException("自定义裁剪模式必须设置裁剪坐标。");
                }
                _x = x.Value;
                _y = y.Value;
                break;
            }
            if (_x + width > m_width)
            {
                _x = m_width - width;
            }
            if (_y + height > m_height)
            {
                _y = m_height - height;
            }
            _x = _x < 0 ? 0 : _x;
            _y = _y < 0 ? 0 : _y;
            //_x = -_x;
            //_y = -_y;
            return(new Rectangle(_x, _y, width, height));
        }
Example #6
0
File: Di4.cs Project: olgatei/Di4
        public void SecondResolutionIndex(CuttingMethod cuttingMethod, int binCount, int nThreads)
        {
            // TODO: change first resolution options here to be readonly and readonly lock.

            var addedBlocks = new ConcurrentDictionary <C, int>();

            //Partition<C>[] partitions = Partition_1RInc(nThreads);

            KeyValuePair <C, B> firstElement;

            _di4_incIdx.TryGetFirst(out firstElement);

            KeyValuePair <C, B> lastElement;

            _di4_incIdx.TryGetLast(out lastElement);

            nThreads = 1;

            using (WorkQueue work = new WorkQueue(nThreads))
            {
                for (int i = 0; i < nThreads; i++)
                {
                    work.Enqueue(
                        new BatchIndex2R <C, I, M>(
                            _di4_incIdx,
                            _di4_2R,
                            firstElement.Key, //partitions[i].left,
                            lastElement.Key,  //partitions[i].right,
                            cuttingMethod,
                            binCount,
                            addedBlocks).Run);
                }

                work.Complete(true, -1);
            }

            int counted = 0;

            foreach (var item in addedBlocks)
            {
                counted += item.Value;
            }
            _indexesCardinality.AddOrUpdate(_keyCardinality2R, counted);
        }
Example #7
0
        internal ExecutionReport SecondResolutionIndex(CuttingMethod cuttingMethod, int binCount, MaxDegreeOfParallelism maxDegreeOfParallelism)
        {
            int blockCount = 0;

            _stpWtch.Restart();
            Parallel.ForEach(chrs,
                             new ParallelOptions {
                MaxDegreeOfParallelism = maxDegreeOfParallelism.chrDegree
            },
                             chr =>
            {
                foreach (var sDi4 in chr.Value)
                {
                    sDi4.Value.SecondResolutionIndex(cuttingMethod, binCount, maxDegreeOfParallelism.di4Degree);
                    blockCount += sDi4.Value.blockCount;
                    sDi4.Value.Commit();
                }
            });
            _stpWtch.Stop();

            return(new ExecutionReport(blockCount, _stpWtch.Elapsed)); // TODO: check if blockCount += reduces speed or not
        }
Example #8
0
File: Di4B.cs Project: VJalili/Di4
 public ExecutionReport SecondResolutionIndex(CuttingMethod cuttingMethod, int binCount, MaxDegreeOfParallelism maxDegreeOfParallelism)
 {
     return(genome.SecondResolutionIndex(cuttingMethod, binCount, maxDegreeOfParallelism));
 }
Example #9
0
        /// <summary>
        /// 获取图片
        /// </summary>
        /// <param name="fileName">文件名</param>
        /// <param name="w">目标宽度</param>
        /// <param name="h">目标高度</param>
        /// <param name="cm">裁剪方式</param>
        /// <param name="x">自定义裁剪方式时,x坐标</param>
        /// <param name="y">自定义裁剪方式时,y坐标</param>
        /// <param name="rf">旋转和翻转</param>
        /// <returns></returns>
        public async Task <FileResult> GetPictureHvtThumbnailByPath(string fileName, int?w = null, int?h = null, CuttingMethod cm = CuttingMethod.LeftTop, int?x = null, int?y = null, RotateFlipType?rf = null)
        {
            var path = Path.Combine(GetImagesFolder(), fileName);

            if (!System.IO.File.Exists(path))
            {
                return(null);
            }


            if (!w.HasValue && !h.HasValue && !x.HasValue && !y.HasValue && !rf.HasValue)
            {
                return(File(path, MimeTypeNames.ImageJpeg));
            }

            var pathHvt = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path) + $"_w{w}_h{h}_cm{cm}_x{x}_y{y}_rf{rf}{Path.GetExtension(path)}");

            //  检查是否存在,存在就读
            if (System.IO.File.Exists(pathHvt))
            {
                return(File(pathHvt, MimeTypeNames.ImageJpeg));
            }

            //  不存在就重新生成(缩小、裁剪)
            Image image = new Bitmap(path);

            if (w.HasValue && !h.HasValue)
            {
                h = image.Height * w.Value / image.Width;
            }
            if (h.HasValue && !w.HasValue)
            {
                w = image.Width * h.Value / image.Height;
            }
            var hvtImg =
                (w.HasValue && h.HasValue)
                    ? ImageManager.GetHvtThumbnail(image, w.Value, h.Value, cm, x, y)
                    : image;// 没有设宽高,就取原图。

            if (rf.HasValue)
            {
                hvtImg = ImageManager.RotateFlip(hvtImg, rf.Value);
            }

            MemoryStream ms = new MemoryStream();

            hvtImg.Save(ms, ImageFormat.Jpeg);
            var fileData = ms.ToArray();

            //  保存缓存
            SaveImage(fileData, pathHvt);

            return(File(fileData, MimeTypeNames.ImageJpeg));
        }