Menu

Silverlight sample

Help
Anonymous
2011-03-02
2013-04-23
  • Anonymous

    Anonymous - 2011-03-02

    Hi
    I tried to use the library in a C# project. I could create a sample that would paint a background, but could not go any further. tried to paint some rectangle but nothing was displayed.

    Used such a code

        private readonly WriteableBitmap _bmp;
        private readonly SLBackBuffer _backBuffer;
        double m_x = new double;
        double m_y = new double;

        public MainPage()
        {
          InitializeComponent();

          m_x = 100; m_y = 100;
          m_x = 500; m_y = 350;

          _bmp = new WriteableBitmap(800, 800);
          imageCanvas.Source = _bmp;

          _backBuffer = new SLBackBuffer(_bmp);     

          GammaLookUpTable gamma = new GammaLookUpTable(1.8);
          IBlender NormalBlender = new BlenderBGRA();
          IBlender GammaBlender = new BlenderGammaBGRA(gamma);
          RendererBase g = _backBuffer.BackBufferImage.NewRenderer();
          g.PushTransform();
          g.Clear(new RGBA_Doubles(0, 0, 1));
          ImageBuffer rasterNormal = new ImageBuffer(g.DestImage, NormalBlender);
          //ImageBuffer rasterGamma = new ImageBuffer(g.DestImage, GammaBlender);
          ImageClippingProxy clippingProxyNormal = new ImageClippingProxy(rasterNormal);
          //ImageClippingProxy clippingProxyGamma = new ImageClippingProxy(rasterGamma);

          clippingProxyNormal.clear(new RGBA_Doubles(1, 0, 1));

          IRasterizer ras = new rasterizer_scanline_aa();
          IScanlineCache sl = new scanline_packed_8();

          Ellipse e = new Ellipse();

          // Render two "control" circles
          e.init(m_x, m_y, 3, 3, 16);
          ras.add_path(e);
          Renderer.RenderSolid(clippingProxyNormal, ras, sl, new RGBA_Bytes(0, 1, 0, 1));
          e.init(m_x, m_y, 3, 3, 16);
          ras.add_path(e);
          Renderer.RenderSolid(clippingProxyNormal, ras, sl, new RGBA_Bytes(0, 0, 1, 1));

          // Creating a rounded rectangle
          RoundedRect r = new RoundedRect(m_x, m_y, m_x, m_y, 10);
          r.normalize_radius();

          // Drawing as an outline
          conv_stroke p = new conv_stroke(r);
          p.width(10.0);
          ras.add_path(p);

          //Renderer.RenderSolid(clippingProxyGamma, ras, sl, new RGBA_Bytes(0, 0, 0));
          Renderer.RenderSolid(clippingProxyNormal, ras, sl, new RGBA_Bytes(1, 0, 0, 1));

          _backBuffer.Invalidate();
        }

    the backbuffer class looks like this

      public class SLBackBuffer
      {
        public ImageBuffer BackBufferImage { get; private set; }
        private readonly WriteableBitmap _writeableBitmap;

        public SLBackBuffer(WriteableBitmap writeableBitmap)
        {
          _writeableBitmap = writeableBitmap;
          Initialize(writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, 32);
        }

        public SLBackBuffer(WriteableBitmap writeableBitmap, int width, int height)
        {
          _writeableBitmap = writeableBitmap;
          Initialize(width, height, 32);
        }

        public void Invalidate()
        {
          UpdateHardwareSurface();
        }

        internal void UpdateHardwareSurface()
        {
          if (BackBufferImage != null)
          {
            switch (BackBufferImage.BitDepth)
            {
              case 32:
                int offset;
                byte buffer = BackBufferImage.GetBuffer(out offset);
                int index = 0;
                int backBufferHeight = BackBufferImage.Height();
                int backBufferStrideInBytes = BackBufferImage.StrideInBytes();
                int backBufferStrideInInts = backBufferStrideInBytes / 4;
                int destBuffer = _writeableBitmap.Pixels;
                for (int y = 0; y < backBufferHeight; y++)
                {
                  int yOffset = y*backBufferHeight;
                  for (int x = 0; x < backBufferStrideInInts; x++)
                  {
                    byte b = buffer;
                    byte g = buffer;
                    byte r = buffer;
                    byte a = buffer;
                    destBuffer = (a << 24) | (r << 16) | (g << 8) | (b << 0);
                    index += 4;
                  }
                }
                break;
            }

            _writeableBitmap.Invalidate();
          }
        }

        internal void Initialize(int width, int height, int bitDepth)
        {
          if (width > 0 && height > 0)
          {
            switch (bitDepth)
            {
              case 32:
                BackBufferImage = new ImageBuffer(width, height, 32, new BlenderPreMultBGRA());
                break;
              default:
                throw new NotImplementedException("Don't support this bit depth yet.");
            }
          }
        }

      }

    Any idea what could be wrong?
    here are the complete files for the sample
    http://designleon.zapto.org:6869/x_d/rsdn/AggSharpSample.zip

    Thx for any feedback.

     
  • Lars Brubaker

    Lars Brubaker - 2012-12-01

    I'm sorry to not have responded sooner.  We have consolidated all our code onto bitbucket. You can find the code at: https://bitbucket.org/MatterHackers/agg-sharp.  If you are still having troubles could you ask there?

    Thanks, Lars.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.