Exemple #1
0
 public void CreateNewImage(int width, int height)
 {
     _simplePaintViewModel.SetStride(width * _simplePaintViewModel.GetBytesPerPixel());
     _simplePaintViewModel.SetWidth(width);
     _simplePaintViewModel.SetHeight(height);
     _simplePaintViewModel.ImageSave.Clear();
     _simplePaintViewModel.Imagesource = BitmapSource.Create(_simplePaintViewModel.GetWidth(), _simplePaintViewModel.GetHeight(), 400, 400, PixelFormats.Bgr24, null, _simplePaintViewModel.GetImageData(), _simplePaintViewModel.GetStride());
     _simplePaintViewModel.ImageSave.Push(new TempImage(_simplePaintViewModel.Imagesource, _simplePaintViewModel.GetStride()));
     _simplePaintViewModel.SetFirstImage(_simplePaintViewModel.Imagesource);
 }
 private void OpenImage(BitmapSource b)
 {
     _simplePaintViewModel.SetImageData(new byte[b.PixelHeight * b.PixelWidth * (b.Format.BitsPerPixel / 8)]);
     b.CopyPixels(_simplePaintViewModel.GetImageData(), b.PixelWidth * (b.Format.BitsPerPixel / 8), 0);
     _simplePaintViewModel.SetWidth(b.PixelWidth);
     _simplePaintViewModel.SetHeight(b.PixelHeight);
     _simplePaintViewModel.SetBytesPerPixel(b.Format.BitsPerPixel / 8);
     _simplePaintViewModel.SetStride(_simplePaintViewModel.GetBytesPerPixel() * b.PixelWidth);
     _simplePaintViewModel.ImageSave.Clear();
     _simplePaintViewModel.Imagesource = BitmapSource.Create(b.PixelWidth, b.PixelHeight, b.DpiX, b.DpiY, b.Format, b.Palette, _simplePaintViewModel.GetImageData(), _simplePaintViewModel.GetStride());
     _simplePaintViewModel.SetFirstImage(_simplePaintViewModel.Imagesource);
     _simplePaintViewModel.ImageSave.Push((new TempImage(_simplePaintViewModel.Imagesource, _simplePaintViewModel.Imagesource.PixelWidth * _simplePaintViewModel.Imagesource.Format.BitsPerPixel / 8)));
 }
Exemple #3
0
        public void PaintPixel(int x, int y)
        {
            int pt            = _simplePaintViewModel.Getptr();
            int bytesPerPixel = _simplePaintViewModel.GetBytesPerPixel();
            int j             = 0;
            int xPixelWidth   = bytesPerPixel * pt;
            int stride        = _simplePaintViewModel.GetStride();

            y = y + 1;
            int xArrayPosition = x * bytesPerPixel;
            int actualPosition;
            int yArrayPosition;

            byte[] pixelData = _simplePaintViewModel.GetImageData();
            for (int pixelOverY = pt; pixelOverY > 0; pixelOverY--)
            {
                yArrayPosition = (y - pixelOverY) * stride;
                actualPosition = yArrayPosition + xArrayPosition;
                for (int i = actualPosition; i < actualPosition + xPixelWidth && i < yArrayPosition + stride; i++)
                {
                    if (i < 0 || i > pixelData.Length - 1)
                    {
                        continue;
                    }
                    pixelData[i] = _simplePaintViewModel.CurrentColour[j];
                    j++;
                    if (j == bytesPerPixel)
                    {
                        j = 0;
                    }
                }
            }
            _simplePaintViewModel.SetImageData(pixelData);
            _simplePaintViewModel.Imagesource = BitmapSource.Create(_simplePaintViewModel.Imagesource.PixelWidth,
                                                                    _simplePaintViewModel.Imagesource.PixelHeight, _simplePaintViewModel.Imagesource.DpiX,
                                                                    _simplePaintViewModel.Imagesource.DpiY, _simplePaintViewModel.Imagesource.Format,
                                                                    _simplePaintViewModel.Imagesource.Palette, pixelData,
                                                                    stride);
        }