Microsoft MVP성태의 닷넷 이야기
C# SharpDX 화면 캡쳐 관련해서 질문 드립니다. [링크 복사], [링크+제목 복사],
조회: 13215
글쓴 사람
이완호 (dldhksgh90 at naver.com)
홈페이지
첨부 파일
 
(연관된 글이 1개 있습니다.)

                        _device.ImmediateContext.CopyResource(textureResource, d3d11Texture2D);
                        DataBox mapSource = _device.ImmediateContext.MapSubresource(d3d11Texture2D, 0, MapMode.Read, SharpDX.Direct3D11.MapFlags.None);
                        Bitmap bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

                        Rectangle bounds = new Rectangle(0,0, desktopBounds.Width, desktopBounds.Height);
                        BitmapData mapDest = bitmap.LockBits(bounds, System.Drawing.Imaging.ImageLockMode.WriteOnly, bitmap.PixelFormat);
                        var sourcePtr = mapSource.DataPointer;
                        var destPtr = mapDest.Scan0;

                        for (int y = 0; y < height; y++)
                        {

                            Utilities.CopyMemory(destPtr, sourcePtr, width * 4);
                            sourcePtr = IntPtr.Add(sourcePtr, mapSource.RowPitch);
                            destPtr = IntPtr.Add(destPtr, mapDest.Stride);
                        }
                        

                        createBitmap(bitmap);
                        bitmap.UnlockBits(mapDest);

해당 코드를 통해 Bitmap 을 생성하고


                    EncoderParameters myEncoderParameters = new EncoderParameters(1);
                    myEncoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 80L);
                    sendImage.Save(memory, GetEncoder(ImageFormat.Jpeg), myEncoderParameters);

생성된 비트맵을 버퍼로 뽑아내어 소켓을 통해 송수신 받습니다.
여기서 System.Drawing.Bitmap에서 MemoryStream으로 변환하는 과정의 소요시간을 줄이고 싶습니다.

그렇기에 SharpDX.Direct2D1.Bitmap 으로 만들었을 경우 네트워크 송수신을 위해 메모리스트림을 통해 더욱 적은 용량의 버퍼로 변환하는 방법이 있을까요 ?





[연관 글]






[최초 등록일: ]
[최종 수정일: 12/17/2021]


비밀번호

댓글 작성자
 



2021-12-18 12시44분
그러면, 애당초 Utilities.CopyMemory의 루프에서 JPG 데이터를 구성하는 것이 더 좋지 않을까요? 물론, 그것을 위해서는 적절한 JPEG 라이브러리를 쓰시는 것이 좋을 듯합니다.

사실, 화면 캡쳐를 연속으로 뜰 것이라면 일종의 동영상이라고 봐야 합니다. 그렇다면 동영상 코덱을 적용해 보는 것도 나쁘진 않을 것입니다. 가령, 아래의 프로젝트가 그런 식으로 작성된 것입니다.

akon47/ScreenRecorder
; https://github.com/akon47/ScreenRecorder

(업데이트: 2021-12-22)

아래의 글을 참고하세요.

C# - (SharpDX + DXGI) 화면 캡처한 이미지를 빠르게 JPG로 변환하는 방법
; https://www.sysnet.pe.kr/2/0/12889
정성태

NoWriterDateCnt.TitleFile(s)