コード例 #1
0
        private void mnuLoadImaging_Click(object sender, EventArgs e)
        {
            SelectPictureDialog dlg = new SelectPictureDialog();

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    ImagingFactory factory = new ImagingFactoryClass();
                    IImage         img;
                    factory.CreateImageFromFile(dlg.FileName, out img);
                    IBitmapImage imgB;
                    factory.CreateBitmapFromImage(img,
                                                  (uint)pbImage.Width,
                                                  (uint)pbImage.Height,
                                                  System.Drawing.Imaging.PixelFormat.Format24bppRgb,
                                                  InterpolationHint.InterpolationHintDefault,
                                                  out imgB);
                    pbImage.Image = ImageUtils.IBitmapImageToBitmap(imgB);
                }
                catch (OutOfMemoryException)
                {
                    MessageBox.Show("Out of memory");
                }
            }
        }
コード例 #2
0
        private void loadImage(String path, int maxRes)
        {
            try
            {
                if (pictureBoxImages.Image != null)
                {
                    pictureBoxImages.Image.Dispose();
                    pictureBoxImages.Image = null;
                }
                ImagingFactory factory = new ImagingFactoryClass();
                IImage         img;
                ImageInfo      inf = new ImageInfo();
                factory.CreateImageFromFile(path, out img);

                img.GetImageInfo(out inf);
                double ratio = (double)inf.Width / (double)inf.Height;
                uint   x     = 0;
                uint   y     = 0;
                if (inf.Width > inf.Height)
                {
                    x = Math.Min(inf.Width, (uint)maxRes);
                    y = (uint)Math.Floor(x / ratio);
                }
                else
                {
                    y = Math.Min(inf.Height, (uint)maxRes);
                    x = (uint)Math.Floor(y * ratio);
                }

                IBitmapImage imgB;
                factory.CreateBitmapFromImage(img,
                                              x,
                                              y,
                                              System.Drawing.Imaging.PixelFormat.Format24bppRgb,
                                              InterpolationHint.InterpolationHintDefault,
                                              out imgB);

                Size s = new Size((int)x, (int)y);
                pictureBoxImages.Size  = s;
                pictureBoxImages.Image = ImageUtils.IBitmapImageToBitmap(imgB);
            }
            catch (OutOfMemoryException)
            {
                MessageBox.Show("Out of memory");
            }
        }
コード例 #3
0
    private void Form1_Load(object sender, EventArgs e)
    {
        IImage          fullSizeImage;
        IImagingFactory factory = new ImagingFactoryClass();

        factory.CreateImageFromFile(@"\My Documents\My Pictures\luminous opera house.jpg", out fullSizeImage);

        fullSizeImage.GetThumbnail(240, 320, out smallImage);

        using (Graphics gfx = Graphics.FromImage(bmp))
        {
            IntPtr hdc = gfx.GetHdc();
            try
            {
                smallImage.Draw(hdc, new Rectangle(0, 0, 240, 320), IntPtr.Zero);
            }
            finally
            {
                gfx.ReleaseHdc(hdc);
            }
        }
    }
コード例 #4
0
        private void loadImage(String path, int maxRes)
        {
            try
            {
                if (pictureBoxMap.Image != null)
                {
                    pictureBoxMap.Image.Dispose();
                    pictureBoxMap.Image = null;
                }
                ImagingFactory factory = new ImagingFactoryClass();
                IImage img;
                ImageInfo inf = new ImageInfo();
                factory.CreateImageFromFile(path, out img);

                img.GetImageInfo(out inf);
                double ratio = (double)inf.Width / (double)inf.Height;
                uint x=0;
                uint y=0;
                if (inf.Width > inf.Height)
                {
                    x = Math.Min(inf.Width, (uint)maxRes);
                    y = (uint)Math.Floor(x / ratio);
                }
                else
                {
                    y = Math.Min(inf.Height, (uint)maxRes);
                    x = (uint)Math.Floor(y * ratio);
                }

                IBitmapImage imgB;
                factory.CreateBitmapFromImage(img,
                    x,
                    y,
                    System.Drawing.Imaging.PixelFormat.Format24bppRgb,
                    InterpolationHint.InterpolationHintDefault,
                    out imgB);

                Size s = new Size((int)x, (int)y);
                pictureBoxMap.Size = s;
                pictureBoxMap.Image = ImageUtils.IBitmapImageToBitmap(imgB);
            }
            catch (OutOfMemoryException)
            {
                MessageBox.Show("Out of memory");
            }
        }