示例#1
0
        /// <summary>
        /// Loads image from a file.
        /// </summary>
        /// <param name="fileName">Name of file with image.</param>
        /// <returns><see cref="CodedImage"/> instance with pixels data initialized from loaded file.</returns>
        protected override CodedImage LoadImageCore(string fileName)
        {
            var bitmap       = new Bitmap(fileName);
            var indexedImage = IndexedImageExtensions.FromBitmap(bitmap);
            var codedImage   = CodedImage.FromIndexedImage(indexedImage);

            return(codedImage);
        }
示例#2
0
        public void TestFromIndexedImage()
        {
            var indexedImage = new IndexedImage {
                Size = new Size(2, 3)
            };
            var codedImage = CodedImage.FromIndexedImage(indexedImage);

            Assert.AreEqual(indexedImage.Size, codedImage.Size);

            int[] indexedPixels, codedPixels;
            using (indexedImage.LockPixels(out indexedPixels))
                using (codedImage.LockPixels(out codedPixels))
                {
                    Assert.AreSame(indexedPixels, codedPixels, "Should use same pixels array");
                }
        }
示例#3
0
        void buttonSave_Click(object sender, EventArgs e)
        {
            var bitmap = pictureBox1.Image as Bitmap;

            if (bitmap == null)
            {
                return;
            }

            using (var saveDialog = new SaveFileDialog {
                Filter = "SAE scheme (*.sa4)|*.sa4|PNG image (*.png)|*.png|JPG image (*.jpg)|*.jpg"
            })
            {
                if (saveDialog.ShowDialog(this) == DialogResult.OK)
                {
                    switch (saveDialog.FilterIndex)
                    {
                    case 1:
                        var image = CodedImage.FromIndexedImage(IndexedImageExtensions.FromBitmap(bitmap));
                        using (var stream = new FileStream(saveDialog.FileName, FileMode.Create))
                        {
                            image.SaveToStream(stream);
                        }
                        break;

                    case 2:
                        bitmap.Save(saveDialog.FileName, ImageFormat.Png);
                        break;

                    case 3:
                        bitmap.Save(saveDialog.FileName, ImageFormat.Jpeg);
                        break;

                    default:
                        bitmap.Save(saveDialog.FileName);
                        break;
                    }
                }
            }
        }