示例#1
0
        public static Bitmap LoadTGA(Stream stream)
        {
            Bitmap bit;
            var    sett = new ImageMagick.MagickReadSettings()
            {
                Format = ImageMagick.MagickFormat.Tga
            };

            using (var image = new ImageMagick.MagickImage(stream.ToByteArray(), sett))
                bit = image.ToBitmap();

            return(bit);
        }
        private static void FileLoad(string fileName)
        {
            labelItems.Clear();
            using (var images = new ImageMagick.MagickImageCollection())
            {
                var settings = new ImageMagick.MagickReadSettings();
                settings.Density = new ImageMagick.Density(density, density);

                images.Read(fileName, settings);

                // split
                int page = 1;
                foreach (var image in images)
                {
                    int width  = (int)(image.Width / rowCount);
                    int height = (int)(image.Height / columnCount);

                    int number = 0;
                    foreach (var labelImage in image.CropToTiles(width, height))
                    {
                        number++;
                        if (labelImage.TotalColors == 1)
                        {
                            continue;
                        }

                        var encoder = new System.Windows.Media.Imaging.JpegBitmapEncoder();
                        encoder.QualityLevel = 100;

                        using (MemoryStream stream = new MemoryStream())
                        {
                            encoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(labelImage.ToBitmapSource()));
                            encoder.Save(stream);
                            stream.Position = 0;

                            var label = DYMO.Label.Framework.Label.Open(
                                Application.GetResourceStream(
                                    new Uri("BarcodeAsImage.label", UriKind.RelativeOrAbsolute)).Stream);

                            label.SetImagePngData("Image", stream);

                            var labelItem = new LabelItem(labelImage, label);
                            AddLabelItem(page, number, labelItem);
                        }
                    }
                    page++;
                }
            }
        }