Microsoft.Protocols.TestSuites.Rdpegfx.RdpegfxTestUtility.captureFromImage C# (CSharp) Method

captureFromImage() public static method

Capture a bitmap from an image
public static captureFromImage ( Image srcImage, RDPGFX_POINT16 capPos, int width, int height, Image &bgImage ) : Bitmap
srcImage Image The source of captured bitmap
capPos Microsoft.Protocols.TestTools.StackSdk.RemoteDesktop.Rdpegfx.RDPGFX_POINT16 Left-top position in source image for captured bitmap
width int Width of captured bitmap
height int Height of captured bitmap
bgImage Image The image after a part is captured
return System.Drawing.Bitmap
        public static Bitmap captureFromImage(Image srcImage, RDPGFX_POINT16 capPos, int width, int height, out Image bgImage)
        {
            // Cut a bitmap(width * height) from position(left,top) of srcImage
            Bitmap bitmap = new Bitmap(width, height);
            Graphics g = Graphics.FromImage(bitmap);
            Rectangle destRect = new Rectangle(0, 0, width, height);
            Rectangle srcRect = new Rectangle(capPos.x, capPos.y, width, height);
            g.DrawImage(srcImage, destRect, srcRect, GraphicsUnit.Pixel);

            // Fill the cut rectangle with solid color at position(left, top)
            bgImage = srcImage;
            Bitmap bgBmp = (Bitmap)bgImage;
            Color brushColor = bgBmp.GetPixel(capPos.x, capPos.y);
            SolidBrush pixelBrush = new SolidBrush(brushColor);
            Graphics srcg = Graphics.FromImage(srcImage);
            srcg.FillRectangle(pixelBrush, srcRect);
            return bitmap;
        }

Usage Example

        public void RDPEGFX_Segmentation_Negative_MultiSegmentNoSegmentArray()
        {
            this.TestSite.Log.Add(LogEntryKind.Comment, "Do capability exchange.");
            RDPEGFX_CapabilityExchange();

            this.TestSite.Log.Add(LogEntryKind.Comment, "Set the test type to {0}.", RdpegfxNegativeTypes.Segmentation_MultiSegments_WithoutSegmentArray);
            this.rdpegfxAdapter.SetTestType(RdpegfxNegativeTypes.Segmentation_MultiSegments_WithoutSegmentArray);

            this.TestSite.Log.Add(LogEntryKind.Comment, "Create a surface and fill it with green color.");
            // Create & output a surface
            RDPGFX_RECT16 surfRect = RdpegfxTestUtility.ConvertToRect(RdpegfxTestUtility.surfPos, RdpegfxTestUtility.surfWidth2, RdpegfxTestUtility.surfHeight2);

            this.TestSite.Log.Add(LogEntryKind.Comment, "Create the first surface and map the surface to output");
            Surface surf = this.rdpegfxAdapter.CreateAndOutputSurface(surfRect, PixelFormat.PIXEL_FORMAT_XRGB_8888);

            this.TestSite.Assert.IsNotNull(surf, "Surface {0} is created", surf.Id);

            // Send solid fill request to client to fill surface with green color
            RDPGFX_RECT16 fillSurfRect = RdpegfxTestUtility.ConvertToRect(RdpegfxTestUtility.imgPos, RdpegfxTestUtility.surfWidth2, RdpegfxTestUtility.surfHeight2);

            RDPGFX_RECT16[] fillRects = { fillSurfRect };  // Relative to surface
            uint            fid       = this.rdpegfxAdapter.SolidFillSurface(surf, RdpegfxTestUtility.fillColorGreen, fillRects);

            this.TestSite.Log.Add(LogEntryKind.Debug, "Surface is filled with solid color in frame: {0}", fid);

            this.rdpegfxAdapter.ExpectFrameAck(fid);

            // To be modified ....
            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending Encode Header/Data Messages to client.");
            // byte compFlag = RdpSegmentedPdu.PACKET_COMPR_TYPE_RDP8 | RdpSegmentedPdu.PACKET_COMPRESSED;
            byte compFlag = (byte)PACKET_COMPR_FLAG.PACKET_COMPR_TYPE_RDP8;

            Image bgImage;
            Image compImage = RdpegfxTestUtility.captureFromImage(image_64X64, RdpegfxTestUtility.imgPos,
                                                                  RdpegfxTestUtility.ccLargeBandWidth, RdpegfxTestUtility.ccLargeBandHeight, out bgImage);

            this.TestSite.Log.Add(LogEntryKind.Comment, "Send a large size bitmap using multipart datapacking but without SegmentArray field to the client for frame {0}.", fid);
            fid = this.rdpegfxAdapter.SendUncompressedImage(compImage, RdpegfxTestUtility.imgPos.x, RdpegfxTestUtility.imgPos.y, surf.Id, PixelFormat.PIXEL_FORMAT_XRGB_8888, compFlag, RdpegfxTestUtility.segmentPartSize);

            this.TestSite.Log.Add(LogEntryKind.Comment, "Expect SUT to drop the connection");
            bool bDisconnected = this.rdpbcgrAdapter.WaitForDisconnection(waitTime);

            this.TestSite.Assert.IsTrue(bDisconnected, "RDP client should terminate the connection when received an invalid message.");
        }
All Usage Examples Of Microsoft.Protocols.TestSuites.Rdpegfx.RdpegfxTestUtility::captureFromImage