Example #1
0
        /// <summary>
        /// will merge a group of images into one
        /// </summary>
        /// <param name="imageBytes"></param>
        /// <param name="imageNames"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="index"></param>
        public void MergeGroup(List <byte[]> imageBytes, List <string> imageNames, int start, int end, int index)
        {
            if (LogHelper.CanDebug())
            {
                LogHelper.Begin("ImageJoiner.MergeGroup");
            }
            try
            {
                List <BitmapImage> bmps = new List <BitmapImage>();
                double             maxWidth = 0, maxHeight = 0, position = 0;

                for (int i = start; i <= end; i++)
                {
                    MemoryStream ms      = new MemoryStream(imageBytes[i]);
                    BitmapImage  myImage = new BitmapImage();
                    myImage.BeginInit();
                    myImage.StreamSource = ms;
                    myImage.CacheOption  = BitmapCacheOption.None;
                    myImage.EndInit();

                    bmps.Add(myImage);
                    maxWidth   = Math.Max(myImage.Width, maxWidth);
                    maxHeight += myImage.Height;
                }

                RenderTargetBitmap temp = new RenderTargetBitmap((int)maxWidth, (int)maxHeight, 96d, 96d, PixelFormats.Pbgra32);

                DrawingVisual dv = new DrawingVisual();
                using (DrawingContext ctx = dv.RenderOpen())
                {
                    foreach (BitmapImage bi in bmps)
                    {
                        ctx.DrawImage(bi, new System.Windows.Rect(0, position, bi.Width, bi.Height));
                        position += bi.Height;
                    }
                    ctx.Close();
                }

                temp.Render(dv);

                NewImageNames.Add(string.Format("{0:0000}.jpg", index));
                NewImageBytes.Add(StreamToImage.BufferFromImage(temp));

                bmps.Clear();
            }
            catch (Exception err)
            {
                LogHelper.Manage("ImageJoiner.MergeGroup", err);
            }
            finally
            {
                LogHelper.End("ImageJoiner.MergeGroup");
            }
        }
Example #2
0
        public bool Read(string inputFileorFolder, string outputFolder, List <byte[]> imageBytes, List <string> imageNames, ContractParameters settings, ProgressDelegate progress)
        {
            if (LogHelper.CanDebug())
            {
                LogHelper.Begin("ImageFileReader.Read");
            }
            try
            {
                string[] files = Directory.GetFiles(inputFileorFolder, "*.*", SearchOption.TopDirectoryOnly);

                foreach (string filename in files)
                {
                    if (DocumentFactory.Instance.ImageExtension.Contains(Path.GetExtension(filename).ToUpper()))
                    {
                        BitmapImage myImage = new BitmapImage();
                        myImage.BeginInit();
                        myImage.UriSource   = new Uri(filename, UriKind.RelativeOrAbsolute);
                        myImage.CacheOption = BitmapCacheOption.OnLoad;
                        myImage.EndInit();

                        imageBytes.Add(StreamToImage.BufferFromImage(myImage));
                        imageNames.Add(Path.GetFileName(filename));
                    }
                }
                string msg = CultureManager.Instance.GetLocalization("ByCode", "Convert.ImageFound", "{0} images founded...");
                progress(string.Format(msg, imageBytes.Count));
            }
            catch (Exception err)
            {
                LogHelper.Manage("ImageFileReader:Read", err);
                settings.Result = false;
                return(false);
            }
            finally
            {
                LogHelper.End("ImageFileReader.Read");
            }
            return(true);
        }