Beispiel #1
0
        /// <summary>
        /// Initialize the application.
        /// </summary>
        private void InitClass()
        {
            // Setup our caption
            Messager.Caption = "LEADTOOLS for .NET C# Color Conversion Demo";
            Text             = Messager.Caption;

            // Conversion type is nothing for now
            _conversionType = String.Empty;

            // Initialize the _viewer object
            _viewer           = new ImageViewer();
            _viewer.Dock      = DockStyle.Fill;
            _viewer.BackColor = Color.DarkGray;
            Controls.Add(_viewer);
            _viewer.BringToFront();

            _viewer.Zoom(ControlSizeMode.Fit, 1, _viewer.DefaultZoomOrigin);

            // initialize the raster codecs object
            _codecs = new RasterCodecs();

            try
            {
                RasterColorConverterEngine.Startup();
            }
            catch (Exception ex)
            {
                Messager.ShowError(this, ex);
            }

            LoadImage(true);
            UpdateMyControls();
        }
Beispiel #2
0
        private void InitClass(RasterImage image, ConversionColorFormat srcFormat)
        {
            _viewer           = new ImageViewer();
            _viewer.BackColor = Color.DarkGray;
            _viewer.ViewHorizontalAlignment = ControlAlignment.Near;
            _viewer.Dock = DockStyle.Fill;
            _pnlViewer.Controls.Add(_viewer);
            _viewer.BringToFront();
            _viewer.Zoom(ControlSizeMode.Fit, 1, _viewer.DefaultZoomOrigin);

            _cbFit.Checked = _viewer.SizeMode == ControlSizeMode.Fit;

            // Start up the Color conversion toolkit.
            RasterColorConverterEngine.Startup();
            RasterImage tempImage = image.Clone();

            if (tempImage.ViewPerspective != RasterViewPerspective.TopLeft)
            {
                tempImage.ChangeViewPerspective(RasterViewPerspective.TopLeft);
            }

            _width        = tempImage.Width;
            _height       = tempImage.Height;
            _bytesPerLine = tempImage.BytesPerLine;

            _orgBuffer = new byte[_bytesPerLine * _height];

            tempImage.Access();

            for (int y = 0; y < _height - 1; y++)
            {
                tempImage.GetRow(y, _orgBuffer, (y * _width * 3), _width * 3);
            }

            _viewer.Image = tempImage;

            tempImage.Release();

            _srcFormat = srcFormat;

            foreach (ConvertItem i in _convertItems)
            {
                _cbColorFormat.Items.Add(i);
                if (i.Format == ConversionColorFormat.Yuv)
                {
                    _cbColorFormat.SelectedItem = i;
                }
            }

            UpdateMyControls();
        }
Beispiel #3
0
        private void ConvertToColorSpace(ConversionColorFormat colorFormat)
        {
            if (_btnOK.Enabled)
            {
                using (WaitCursor wait = new WaitCursor())
                {
                    try
                    {
                        int bufferSize;

                        if (colorFormat == ConversionColorFormat.Cmyk)
                        {
                            bufferSize = (_bytesPerLine * _height) + ((_bytesPerLine * _height) / 3);
                        }
                        else
                        {
                            bufferSize = _bytesPerLine * _height;
                        }

                        byte[] newBuffer = new byte[bufferSize];

                        RasterColorConverterEngine.ConvertDirect(
                            _srcFormat,
                            colorFormat,
                            _orgBuffer,
                            0,
                            newBuffer,
                            0,
                            _width,
                            _height,
                            0,
                            0);

                        RasterColorConverterEngine.ConvertDirectToImage(
                            colorFormat,
                            _srcFormat,
                            newBuffer,
                            0,
                            _viewer.Image,
                            _width,
                            _height,
                            0,
                            (_bytesPerLine - _width * 3));

                        _viewer.Invalidate();

                        foreach (ConvertItem i in _convertItems)
                        {
                            if (i.Format == colorFormat)
                            {
                                MainForm.ConversionType = i.Name;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Messager.ShowError(this, ex.Message);
                    }
                }
            }
        }
Beispiel #4
0
 /// <summary>
 /// Shutting down
 /// </summary>
 private void CleanUp()
 {
     RasterColorConverterEngine.Shutdown();
 }