Пример #1
0
        void RenderSelectedSample()
        {
            SampleName sampleName = (SampleName)listBox1.SelectedItem;

            //render!
            using (Graphics g = this.panel1.CreateGraphics())
                using (Bitmap bmp1 = new Bitmap(400, 500))
                    using (LockBmp bmplock = bmp1.Lock())
                    {
                        BitmapBuffer wb = bmplock.CreateNewBitmapBuffer();
                        switch (sampleName)
                        {
                        case SampleName.DrawEllipses:
                            DrawEllipses(wb);
                            break;

                        case SampleName.DrawEllipsesFlower:
                            DrawEllipsesFlower(wb);
                            break;

                        case SampleName.DrawStaticShapes:
                            DrawStaticShapes(wb);
                            break;
                        }

                        bmplock.WriteAndUnlock();
                        //

                        g.Clear(System.Drawing.Color.White);
                        g.DrawImage(bmp1, 0, 0);
                    }
        }
Пример #2
0
        private void button3_Click(object sender, EventArgs e)
        {
            using (Bitmap src = new Bitmap("d:\\WImageTest\\L01.png"))
                using (LockBmp srcLock = src.Lock())
                    using (Bitmap dest = new Bitmap(400, 500))
                        using (LockBmp dstLock = dest.Lock())
                        {
                            BitmapBuffer dstWb = dstLock.CreateNewBitmapBuffer();
                            BitmapBuffer srcWb = srcLock.CreateNewBitmapBuffer();
                            int          y     = 0;
                            dstWb.Clear(BitmapBufferEx.ColorInt.FromArgb(255, 255, 255, 255));

                            dstWb.Blit(new RectD(10, 10, src.Width, src.Height),
                                       srcWb,
                                       new RectD(0, 0, src.Width, src.Height), BitmapBufferExtensions.BlendMode.None
                                       );
                            dstWb.Blit(new RectD(100, 100, src.Width * 2, src.Height * 2),
                                       srcWb,
                                       new RectD(0, 0, src.Width, src.Height), BitmapBufferExtensions.BlendMode.None
                                       );

                            dstLock.WriteAndUnlock();
                            dest.Save("d:\\WImageTest\\a0004.png");
                        }
        }
Пример #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            using (Bitmap bmp1 = new Bitmap(400, 500))
                using (LockBmp bmplock = bmp1.Lock())
                {
                    BitmapBuffer wb = bmplock.CreateNewBitmapBuffer();
                    //lines

                    int y = 0;

                    wb.DrawLine(0, y, 100, y + 100, BitmapBufferEx.ColorInt.FromArgb(255, 255, 0, 0));     //red
                    wb.DrawLine(0, y + 100, 100, y + 0, BitmapBufferEx.ColorInt.FromArgb(255, 0, 0, 255)); //blue

#if DEBUG
                    wb.DrawLineAa(100, y, 200, y + 100, BitmapBufferEx.ColorInt.FromArgb(255, 255, 0, 0));
                    wb.DrawLineAa(100, y + 100, 200, y + 0, BitmapBufferEx.ColorInt.FromArgb(255, 0, 0, 255)); //blue
#endif


                    //----------
                    y += 150;
                    wb.DrawLineDDA(0, y, 100, y + 100, BitmapBufferEx.ColorInt.FromArgb(255, 255, 0, 0));     //red
                    wb.DrawLineDDA(0, y + 100, 100, y + 0, BitmapBufferEx.ColorInt.FromArgb(255, 0, 0, 255)); //blue


                    wb.DrawEllipse(200, 0, 300, 100, BitmapBufferEx.ColorInt.FromArgb(255, 255, 0, 0));

                    //
                    bmplock.WriteAndUnlock();

                    bmp1.Save("d:\\WImageTest\\a0002.png");
                }
        }
Пример #4
0
 static BitmapBuffer LoadBitmapAsReadonly(string path)
 {
     using (Bitmap bmp = new Bitmap(path))
         using (LockBmp lockBmp = new LockBmp(bmp))
         {
             return(lockBmp.CreateNewBitmapBuffer());
         }
 }
Пример #5
0
        private void button2_Click(object sender, EventArgs e)
        {
            using (Bitmap bmp1 = new Bitmap(400, 500))
                using (LockBmp bmplock = bmp1.Lock())
                {
                    BitmapBuffer wb = bmplock.CreateNewBitmapBuffer();

                    int y = 0;
                    wb.FillRectangle(5, 5, 20, 20, BitmapBufferEx.ColorInt.FromArgb(255, 255, 0, 0));
                    wb.FillTriangle(100, 0, 150, 150, 200, 0, BitmapBufferEx.ColorInt.FromArgb(255, 0, 0, 255));
                    bmplock.WriteAndUnlock();
                    bmp1.Save("d:\\WImageTest\\a0003.png");
                }
        }
Пример #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            //render!
            using (System.Drawing.Graphics g = this.panel1.CreateGraphics())
                using (System.Drawing.Bitmap bmp1 = new System.Drawing.Bitmap(panel1.Width, panel1.Height))
                    using (LockBmp bmplock = bmp1.Lock())
                    {
                        BitmapBuffer wb = bmplock.CreateNewBitmapBuffer();

                        Draw(wb);
                        bmplock.WriteAndUnlock();
                        //

                        g.Clear(System.Drawing.Color.White);
                        g.DrawImage(bmp1, 0, 0);
                    }
        }
Пример #7
0
        private void button6_Click(object sender, EventArgs e)
        {
            BitmapBuffer unmodifiedBmp = LoadBitmapAsReadonly("../../02.jpg");
            BitmapBuffer flipImg       = unmodifiedBmp.RotateFree(20, false);


            using (LockBmp bmplock = destBmp.Lock())
            {
                BitmapBuffer wb = bmplock.CreateNewBitmapBuffer();
                wb.Clear(Colors.White);

                wb.Blit(new RectD(0, 0, flipImg.PixelWidth, flipImg.PixelHeight),
                        flipImg,
                        new RectD(0, 0, flipImg.PixelWidth, flipImg.PixelHeight));

                bmplock.WriteAndUnlock();

                g.Clear(System.Drawing.Color.White);
                g.DrawImage(destBmp, 0, 0);
            }
        }
Пример #8
0
        private void button4_Click(object sender, EventArgs e)
        {
            BitmapBuffer unmodifiedBmp = LoadBitmapAsReadonly("../../02.jpg");
            BitmapBuffer rotateBmp     = unmodifiedBmp.Rotate(BitmapBufferExtensions.FastRotateAngle.Rotate270);


            using (LockBmp bmplock = destBmp.Lock())
            {
                BitmapBuffer wb = bmplock.CreateNewBitmapBuffer();
                wb.Clear(Colors.White);

                wb.Blit(new RectD(0, 0, rotateBmp.PixelWidth, rotateBmp.PixelHeight),
                        rotateBmp,
                        new RectD(0, 0, rotateBmp.PixelWidth, rotateBmp.PixelHeight));

                bmplock.WriteAndUnlock();

                g.Clear(System.Drawing.Color.White);
                g.DrawImage(destBmp, 0, 0);
            }
        }
Пример #9
0
        private void button2_Click(object sender, EventArgs e)
        {
            BitmapBuffer unmodifiedBmp = LoadBitmapAsReadonly("../../02.jpg");
            BitmapBuffer sticker       = LoadBitmapAsReadonly("../../01.jpg");

            BitmapBuffer overlayResult = Overlay(unmodifiedBmp, sticker, new BitmapBufferEx.PointD(10, 10));

            using (LockBmp bmplock = destBmp.Lock())
            {
                BitmapBuffer wb = bmplock.CreateNewBitmapBuffer();
                wb.Clear(Colors.Black);

                wb.Blit(new RectD(0, 0, overlayResult.PixelWidth, overlayResult.PixelHeight),
                        overlayResult,
                        new RectD(0, 0, overlayResult.PixelWidth, overlayResult.PixelHeight));

                bmplock.WriteAndUnlock();

                g.Clear(System.Drawing.Color.White);
                g.DrawImage(destBmp, 0, 0);
            }
        }
Пример #10
0
        void UpdateRenderFrame()
        {
            // Wrap updates in a GetContext call, to prevent invalidation and nested locking/unlocking during this block
            // NOTE: This is not strictly necessary for the SL version as this is a WPF feature, however we include it here for completeness and to show
            // a similar API to WPF
            //render!
            using (LockBmp bmplock = destBmp.Lock())
            {
                BitmapBuffer wb = bmplock.CreateNewBitmapBuffer();
                emitter.TargetBitmap   = wb;
                emitter.ParticleBitmap = particleBmp;

                wb.Clear(Colors.Black);


                double elapsed = (DateTime.Now - lastUpdate).TotalSeconds;
                lastUpdate = DateTime.Now;
                emitter.Update(elapsed);
                //			bmp.Blit(new Point(100, 150), circleBmp, new Rect(0, 0, 200, 200), Colors.Red, BlendMode.Additive);
                //			bmp.Blit(new Point(160, 55), circleBmp, new Rect(0, 0, 200, 200), Color.FromArgb(255, 0, 255, 0), BlendMode.Additive);
                //			bmp.Blit(new Point(220, 150), circleBmp, new Rect(0, 0, 200, 200), Colors.Blue, BlendMode.Additive);

                //double timeNow = _stopwatch.ElapsedMilliseconds;
                //double elapsedMilliseconds = timeNow - _lastTime;
                //_lowestFrameTime = Math.Min(_lowestFrameTime, elapsedMilliseconds);
                //// FpsCounter.Text = string.Format("FPS: {0:0.0} / Max: {1:0.0}", 1000.0 / elapsedMilliseconds, 1000.0 / _lowestFrameTime);
                //_lastTime = timeNow;



                //
                bmplock.WriteAndUnlock();
                //

                g.Clear(System.Drawing.Color.White);
                g.DrawImage(destBmp, 0, 0);
            }
        }