0

i am using this function, but after rotation my barcode engine can't find barcodes in the image, i am using angle-value less than 1 .

public static Bitmap RotateImage(Bitmap b, float angle)
        {
            //create a new empty bitmap to hold rotated image
            Bitmap returnBitmap = new Bitmap(b.Width, b.Height);
            //make a graphics object from the empty bitmap
            using (Graphics g = Graphics.FromImage(returnBitmap))
            {
                //move rotation point to center of image
                g.TranslateTransform((float)b.Width / 2, (float)b.Height / 2);
                //rotate
                g.RotateTransform(angle);
                //move image back
                g.TranslateTransform(-(float)b.Width / 2, -(float)b.Height / 2);
                //draw passed in image onto graphics object
                g.DrawImage(b, new Point(0, 0));
            }
            return returnBitmap;
        }
mordechai
  • 829
  • 1
  • 7
  • 23
  • 1
    There is likely a very dramatic loss in image quality with this style of rotation, you will need to find a higher quality rotation algorithm or style – TheGeneral Oct 21 '18 at 11:11
  • 1
    The actual result depends much on the quality of the original image. If the orignal bitmap has a base resolution (72 or 96 dpi) or the barcode lines are *blurred*, the resulting quality will be borderline useless. No matter what `PixelOffset` or `SmoothingMode` you use (which, btw, you're not using here). You'll have to test it with an original resolution of 300dpi. You'll probably need a sharpening filter. Anyway, try first with `g.SmoothingMode = SmoothingMode.HighQuality; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.InterpolationMode = InterpolationMode.HighQualityBicubic;` – Jimi Oct 21 '18 at 14:14
  • You may need to apply a contrast filer. Easy with ColorMatrix. But you also need sufficient resolution to start with. Once the lines are straight you can try to scale them down again. Whether anti-aliasing will help or hurt greatly depends on the size of the image.. – TaW Oct 21 '18 at 14:57
  • You may want to have a look at [this](https://stackoverflow.com/questions/34116706/how-to-repair-dimmed-image-of-book-page/34121073?s=2|51.8896#34121073).. – TaW Oct 21 '18 at 20:26
  • thanks to all, i tried using ImageProcessor Package and the result is excellent – mordechai Oct 30 '18 at 10:33

0 Answers0