private void Resize(int destWidth, int destHeight, RasterImage image)
        {
            RasterImageResize resize = new RasterImageResize();

            // Add Event Handler
            resize.Resize += new EventHandler <RasterImageResizeEventArgs>(Resize);

            byte[] buffer = new byte[image.BytesPerLine];

            resize.Start(
                image,
                destWidth,
                destHeight,
                image.BitsPerPixel,
                image.Order,
                image.DitheringMethod,
                RasterSizeFlags.None,
                image.GetPalette());

            image.Access();
            // get the rows for the resized image, one by one
            for (int row = 0; row < image.Height; row++)
            {
                resize.ResizeBuffer(row, 0, buffer, 0, image.BytesPerLine);
                image.SetRow(row, buffer, 0, image.BytesPerLine);
            }
            image.Release();
            resize.Stop();
        }
Ejemplo n.º 2
0
        public void ReceiveProc(long pData, int lWidth, int lHeight, int lBitCount, int lSize, int bTopDown)
        {
            if (!_owner.IsDisposed && !_owner.Disposing)
            {
                try
                {
                    if (_width != lWidth || _height != lHeight || _bitCount != lBitCount || _topDown != bTopDown)
                    {
                        if (_image != null)
                        {
                            _image.Dispose();
                        }

                        _image = new RasterImage(RasterMemoryFlags.Conventional,
                                                 lWidth,
                                                 lHeight,
                                                 lBitCount,
                                                 RasterByteOrder.Bgr,
                                                 bTopDown == 1 ? RasterViewPerspective.TopLeft : RasterViewPerspective.BottomLeft,
                                                 null,
                                                 null,
                                                 lSize);

                        _width    = lWidth;
                        _height   = lHeight;
                        _bitCount = lBitCount;
                        _topDown  = bTopDown;
                    }

                    _image.Access();
                    _image.SetRow(0, new IntPtr(pData), lSize);
                    _image.Release();

                    Form1 form = _owner as Form1;
                    if (form != null)
                    {
                        GuideRect = CreditCardScanner.GetGuideFrame(_owner.ClientRectangle.Width, _owner.ClientRectangle.Height, form.CaptureCtrl.Width, form.CaptureCtrl.Height);
                        _owner.Invalidate();
                    }

                    if (!_isRecognized && _threading == false)
                    {
                        byte[] data = new byte[lSize];
                        System.Runtime.InteropServices.Marshal.Copy(new IntPtr(pData), data, 0, lSize);
                        Task processFrame = Task.Factory.StartNew(() => ProcessFrame(data, lWidth, lHeight, bTopDown, lBitCount));
                    }

                    if (_isRecognized == true)
                    {
                        MessageBox.Show(_recognizedCardNumber);
                        _recognizedCardNumber = "";
                        _isRecognized         = false;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Ejemplo n.º 3
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();
        }
        public void CompressImage(string SourceFileName, string DestFileName)
        {
            RasterCodecs codecs           = new RasterCodecs();
            RasterImage  sourceImage      = codecs.Load(SourceFileName);
            RasterImage  destinationImage = new RasterImage(
                RasterMemoryFlags.Conventional,
                sourceImage.Width,
                sourceImage.Height,
                sourceImage.BitsPerPixel,
                sourceImage.Order,
                sourceImage.ViewPerspective,
                sourceImage.GetPalette(),
                IntPtr.Zero,
                0);

            sourceImage.Access();
            destinationImage.Access();

            byte[] buffer = new byte[sourceImage.BytesPerLine];

            for (int y = 0; y < sourceImage.Height; y++)
            {
                sourceImage.GetRow(y, buffer, 0, buffer.Length);
                destinationImage.SetRow(y, buffer, 0, buffer.Length);
            }

            destinationImage.Release();
            sourceImage.Release();

            // We do not need the source image anymore
            sourceImage.Dispose();

            // save the destination image
            codecs.Save(destinationImage, DestFileName, RasterImageFormat.Tif, 24);

            // perform image processing on the image

            //FlipCommand flipCmd = new FlipCommand();
            //flipCmd.Horizontal = false;
            //flipCmd.Run(destinationImage);

            //// save it
            //codecs.Save(destinationImage, destFileName2, RasterImageFormat.Bmp, 24);

            // Clean up
            destinationImage.Dispose();
            codecs.Dispose();
            codecs.Dispose();
        }
Ejemplo n.º 5
0
 private static void SetImageBytes(RasterImage image, byte[] imageBytes)
 {
     image.Access();
     try
     {
         int bytesPerLine = image.Width * (image.BitsPerPixel == 24 ? 3 : 4);
         for (var line = 0; line < image.Height; line++)
         {
             image.SetRow(line, imageBytes, line * bytesPerLine, bytesPerLine);
         }
     }
     finally
     {
         image.Release();
     }
 }
Ejemplo n.º 6
0
        private static byte[] AllocateImageBytes(RasterImage image)
        {
            int height       = image.Height;
            int bytesPerLine = image.Width * (image.BitsPerPixel == 24 ? 3 : 4);
            var imageBuffer  = new byte[bytesPerLine * height];

            image.Access();
            try
            {
                for (var y = 0; y < height; y++)
                {
                    image.GetRow(y, imageBuffer, y * bytesPerLine, bytesPerLine);
                }
            }
            finally
            {
                image.Release();
            }

            return(imageBuffer);
        }