Exemple #1
0
        private void Destimage_Loaded(object sender, RoutedEventArgs e)
        {
            CutImageClass cuter      = new CutImageClass(new System.Drawing.Bitmap("pic1.jpg"), new System.Drawing.Rectangle(0, 0, 364, 240), 215);
            var           GenerImage = cuter
                                       .MakeThumbnail(364, 240)     //可选,压缩当前结果
                                       .MakeVisualAttentionBitmap() //建议,制作显著图
                                       .MakeCutBitmap()             //制作切图
                                       .OutputCurrentDestImage();   //输出

            MemoryStream ms2 = new MemoryStream();

            ms2.Seek(0, SeekOrigin.Begin);
            GenerImage.Save(ms2, ImageFormat.Jpeg);
            GenerImage.Dispose();
            BitmapImage FinBitImage = new BitmapImage();

            FinBitImage.BeginInit();
            ms2.Seek(0, SeekOrigin.Begin);
            FinBitImage.CacheOption  = BitmapCacheOption.OnLoad;
            FinBitImage.StreamSource = ms2;
            FinBitImage.EndInit();
            FinBitImage.Freeze();
            ms2.Dispose();

            destimage.Source = FinBitImage;
        }
Exemple #2
0
        /// <summary>
        /// 获取显著图片
        /// </summary>
        /// <param name="filepath">图片文件流</param>
        /// <param name="prewidth">预处理后的宽</param>
        /// <param name="preheight">预处理后的高</param>
        /// <param name="premode">预处理时的压缩方式</param>
        /// <param name="pretype">预处理图片后的类型</param>
        /// <param name="R">最终切割大小</param>
        /// <param name="Tolerance">切割阙值(切图时判断是否连续的亮度边界,越大越严格)</param>
        /// <returns></returns>
        public Bitmap GetSRDFromStream(Stream InImageStream,
                                       double prewidth, double preheight, string premode, string pretype,
                                       Rectangle R,
                                       int Tolerance = 200)
        {
            if (R == null)
            {
                R = new System.Drawing.Rectangle(0, 0, 256, 256);
            }
            MemoryStream ms_out    = new MemoryStream();
            Bitmap       Srcbitmap = new Bitmap(InImageStream);

            //压缩尺寸以加快速度
            BasicMethodClass.MakeThumbnail(Srcbitmap, ms_out, Math.Min(prewidth, Srcbitmap.Width), Math.Min(preheight, Srcbitmap.Height), premode, pretype);
            if (InImageStream == null)
            {
                throw new Exception("not expectation result");
            }
            if (ms_out == null)
            {
                return(null);
            }
            var vdcSrcBitmap = new Bitmap(ms_out);

            ms_out.Dispose();

            var vdcmap = VisualAttentionDetectionClass.SalientRegionDetectionBasedOnFT(vdcSrcBitmap);

            if (R.Width > Srcbitmap.Width || R.Height > Srcbitmap.Height)
            {//格式化输出图片尺寸
                ms_out = new MemoryStream();
                BasicMethodClass.MakeThumbnail(Srcbitmap, ms_out, R.Width, R.Height, premode, pretype);
                Srcbitmap.Dispose();
                Srcbitmap = new Bitmap(ms_out);
                ms_out.Dispose();
            }
            CutImageClass cuter      = new CutImageClass(vdcmap, R, Tolerance);
            var           GenerImage = cuter.GCSsimp_getLightPointFromSource(Srcbitmap);

            vdcSrcBitmap.Dispose();
            vdcmap.Dispose();
            Srcbitmap.Dispose();

            return(GenerImage);
        }
Exemple #3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string patch = dirpatchTextBox.Text;

            if (!Directory.Exists(patch))
            {
                patch = Environment.CurrentDirectory + @"\Image\";
            }
            string[] Imagefiles = Directory.GetFiles(patch).Where(x => x.EndsWith(".jpg", true, null) ||
                                                                  x.EndsWith(".png", true, null) || x.EndsWith(".bmp", true, null)).ToArray();
            ObservableCollection <Thkindofimage> images = new ObservableCollection <Thkindofimage>();

            ImageListBox.ItemsSource = images;
            Thread t1 = new Thread((ThreadStart) delegate
            {
                foreach (var item in Imagefiles)
                {
                    var srcBitmap = new Bitmap(item);
                    #region 测试FT后的区域选取函数
                    //准备切图类
                    CutImageClass cuter = new CutImageClass(srcBitmap, new System.Drawing.Rectangle(0, 0, 364, 240), 215);
                    cuter.MakeThumbnail(364, 240);
                    cuter.MakeVisualAttentionBitmap();
                    var areaImage = cuter.OutputAreaBitmap();
                    cuter.MakeCutBitmap();
                    var GenerImage = new Bitmap(cuter.CurDestBitmap);
                    #endregion

                    #region 准备视图数据
                    MemoryStream ms = new MemoryStream();
                    if (areaImage == null)
                    {
                        continue;
                    }
                    areaImage.Save(ms, ImageFormat.Jpeg);
                    areaImage.Dispose();
                    BitmapImage AreaBitImage = new BitmapImage();
                    AreaBitImage.BeginInit();
                    ms.Seek(0, SeekOrigin.Begin);
                    AreaBitImage.CacheOption  = BitmapCacheOption.OnLoad;
                    AreaBitImage.StreamSource = ms;
                    AreaBitImage.EndInit();
                    AreaBitImage.Freeze();
                    ms.Dispose();
                    MemoryStream ms2 = new MemoryStream();
                    ms2.Seek(0, SeekOrigin.Begin);
                    if (GenerImage == null)
                    {
                        continue;
                    }
                    GenerImage.Save(ms2, ImageFormat.Jpeg);
                    GenerImage.Dispose();
                    BitmapImage FinBitImage = new BitmapImage();
                    FinBitImage.BeginInit();
                    ms2.Seek(0, SeekOrigin.Begin);
                    FinBitImage.CacheOption  = BitmapCacheOption.OnLoad;
                    FinBitImage.StreamSource = ms2;
                    FinBitImage.EndInit();
                    FinBitImage.Freeze();
                    ms2.Dispose();

                    Dispatcher.Invoke(delegate
                    {
                        images.Add(new Thkindofimage
                        {
                            source = new BitmapImage(new Uri(item)),
                            area   = AreaBitImage,
                            fin    = FinBitImage,
                        });
                    });
                    //GC.Collect(0,GCCollectionMode.Forced);
                }
            });

            #endregion
            t1.Start();
        }