Пример #1
0
        public ArtCamBitmap GetImageAnalyzer(TimeMeter meter, bool shrink)
        {
            meter.Start("Image resizing");

            int ratioX = (bitmap.Rect.Width > 400) ? (bitmap.Rect.Width + 200) / 400 : 1;
            int ratioY = (bitmap.Rect.Height > 400) ? (bitmap.Rect.Height + 200) / 400 : 1;
            int width = bitmap.Rect.Width / ratioX;
            int height = bitmap.Rect.Height / ratioY;

            ArtCamBitmap convertBmp;

            if (((ratioX > 1) || (ratioY > 1)) && shrink)
            {
                convertBmp = new ArtCamBitmap(new Rectangle(0, 0, width, height), bitmap.Bitmap.PixelFormat, null);

                int bytesPerPixel = 1;
                switch (bitmap.Bitmap.PixelFormat)
                {
                    case PixelFormat.Format24bppRgb:
                        bytesPerPixel = 3;
                        break;
                    case PixelFormat.Format32bppArgb:
                        bytesPerPixel = 4;
                        break;
                }

                int[] sum = new int[bytesPerPixel];

                for (int i = 0; i < width; i++)
                    for (int j = 0; j < height; j++)
                    {
                        for (int b = 0; b < bytesPerPixel; b++)
                            sum[b] = 0;

                        int idx = 0;
                        int cnt = 0;
                        for (int x = i * ratioX; x < Math.Min(bitmap.Rect.Width, (i + 1) * ratioX); x++)
                            for (int y = j * ratioY; y < Math.Min(bitmap.Rect.Height, (j + 1) * ratioY); y++)
                            {
                                idx = y * bitmap.Rect.Width * bytesPerPixel + x * bytesPerPixel;
                                for (int b = 0; b < bytesPerPixel; b++)
                                    sum[b] += bitmap.Pixels[idx + b];
                                cnt++;
                            }
                        idx = j * width * bytesPerPixel + i * bytesPerPixel;
                        for (int b = 0; b < bytesPerPixel; b++)
                            convertBmp.Pixels[idx + b] = (byte)(sum[b] / cnt);
                    }
            }
            else
                convertBmp = bitmap;

            return convertBmp;
        }
Пример #2
0
        public ArtCamBitmap GetBwBitmap()
        {
            bool[,] bwPixels = PrepareBwPixels();

            ArtCamBitmap bwBmp = new ArtCamBitmap(new Rectangle(0, 0, width, height), PixelFormat.Format1bppIndexed, null);

            for (int x = 0; x < width; x++)
                for (int y = 0; y < height; y++)
                {
                    int bmpIdx = (x / 8) + bwBmp.Stride * y;
                    byte pixel = 0;
                    if (bwPixels[x, y])
                        pixel = (byte)Math.Pow(2, 7 - (x % 8));
                    bwBmp.Pixels[bmpIdx] |= pixel;
                }

            return bwBmp;
        }
Пример #3
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (preview == null)
            {
                preview = new ArtCamBitmap(new Rectangle(0, 0, 3488, 2616), PixelFormat.Format8bppIndexed, helper);
                ucPictureBox1.Bitmap = preview;
            }

            try
            {
                previewMeter.Clear();
                preview.Snapshot(previewMeter);
                preview.UpdateBitmap(previewMeter);
                previewMeter.Finish();
            }
            catch (ApplicationException ex)
            {
                MessageBox.Show("Exception: " + ex.Message);
            }
        }
Пример #4
0
        private void button3_Click(object sender, EventArgs e)
        {
            if ((snapshot == null) || (snapshot.Rect != ucPictureBox1.SnapshotRect))
            {
                snapshot = new ArtCamBitmap(ucPictureBox1.SnapshotRect, PixelFormat.Format8bppIndexed, helper);
                snapshot.BitmapUpdated += new EventHandler(BitmapUpdated);

                pictureBox1.Image = snapshot.Bitmap;
            }
            bool isInk = false;
            try
            {
                snapshotMeter.Clear();

                snapshot.Snapshot(snapshotMeter);

                ImageConvertor converter = new ImageConvertor(snapshot);
                ArtCamBitmap convertBmp = converter.GetImageAnalyzer(snapshotMeter, true);
                ImageAnalyzer analyzer = new ImageAnalyzer(convertBmp.Pixels, convertBmp.Bitmap.PixelFormat, convertBmp.Rect.Width, convertBmp.Rect.Height);
                label7.Text = "(" + convertBmp.Rect.Width + "," + convertBmp.Rect.Height + ")";
                //ImageAnalyzer analyzer = new ImageAnalyzer(snapshot.Pixels, snapshot.Bitmap.PixelFormat, snapshot.Rect.Width, snapshot.Rect.Height);
                isInk = analyzer.IsInk(snapshotMeter);

                ArtCamBitmap bwBmp = analyzer.GetBwBitmap();
                bwBmp.UpdateBitmap(null);
                pictureBox2.Image = bwBmp.Bitmap;
                pictureBox2.Invalidate();

                snapshot.UpdateBitmap(snapshotMeter);
                snapshotMeter.Finish();
            }
            catch (ApplicationException ex)
            {
                MessageBox.Show("Exception: " + ex.Message);
            }
            finally
            {
                TimeAnalysis();
                DisplayInk(isInk);
            }
        }
Пример #5
0
 public ImageConvertor(ArtCamBitmap bitmap)
 {
     this.bitmap = bitmap;
 }