C#Bitblit 에서트맵어(Compact Framework)
-
20-09-2019 - |
문제
내가 사용되면 BitBlt 스크린샷을 저장하여 이미지 파일(..Net Compact Framework V3.5,윈도우 모바일 2003 년 이상).사합니다.지금 내가 원을 그리는 비트맵습니다.용 this.CreateGraphics().DrawImage(mybitmap, 0, 0)
, 하지만 내가 궁금하는 경우 그것은 일 BitBlt 전에 좋아하고 그냥 바꾸라.그래서 내가 쓴:
[DllImport("coredll.dll")]
public static extern int BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop);
(더 아래:)
IntPtr hb = mybitmap.GetHbitmap();
BitBlt(this.Handle, 0, 0, mybitmap.Width, mybitmap.Height, hb, 0, 0, 0x00CC0020);
그러나 양식 숙박 평 흰색이다.그 이유는 무엇입니까?어디에 오류가 나는 최선을 다하고?감사에 대한 의견입니다.환호,데이비드
해결책
this.Handle
가 창 처리 아 디바이스 컨텍스트.
대체 this.Handle
가 this.CreateGraphics().GetHdc()
물론 당신은 필요를 파괴하는 그래픽 객체 등등...
IntPtr hb = mybitmap.GetHbitmap();
using (Graphics gfx = this.CreateGraphics())
{
BitBlt(gfx.GetHdc(), 0, 0, mybitmap.Width, mybitmap.Height, hb, 0, 0, 0x00CC0020);
}
또한 hb
가 Bitmap Handle
아 device context
그래서 위의 조각은 여전히 작동하지 않습니다.을 만들 필요가 있는 장치에서 비트맵:
using (Bitmap myBitmap = new Bitmap("c:\test.bmp"))
{
using (Graphics gfxBitmap = Graphics.FromImage(myBitmap))
{
using (Graphics gfxForm = this.CreateGraphics())
{
IntPtr hdcForm = gfxForm.GetHdc();
IntPtr hdcBitmap = gfxBitmap.GetHdc();
BitBlt(hdcForm, 0, 0, myBitmap.Width, myBitmap.Height, hdcBitmap, 0, 0, 0x00CC0020);
gfxForm.ReleaseHdc(hdcForm);
gfxBitmap.ReleaseHdc(hdcBitmap);
}
}
}
다른 팁
이 라인을 따라 무언가를 의미합니까?
public void CopyFromScreen(int sourceX, int sourceY, int destinationX,
int destinationY, Size blockRegionSize,
CopyPixelOperation copyPixelOperation)
{
IntPtr desktopHwnd = GetDesktopWindow();
if (desktopHwnd == IntPtr.Zero)
{
throw new System.ComponentModel.Win32Exception();
}
IntPtr desktopDC = GetWindowDC(desktopHwnd);
if (desktopDC == IntPtr.Zero)
{
throw new System.ComponentModel.Win32Exception();
}
if (!BitBlt(hDC, destinationX, destinationY, blockRegionSize.Width,
blockRegionSize.Height, desktopDC, sourceX, sourceY,
copyPixelOperation))
{
throw new System.ComponentModel.Win32Exception();
}
ReleaseDC(desktopHwnd, desktopDC);
}
참고로, 이거야 SDF에서 바로.
편집 :이 스 니펫에서는 실제로 명확하지 않지만 BitBlt의 HDC는 대상 비트 맵 (페인트하려는)의 HDC입니다.
당신은 확실합니까? this.Handle
유효한 장치 컨텍스트를 말하면? 반환 값을 확인해 보셨습니까? BitBlt
기능?
다음을 시도하십시오.
[DllImport("coredll.dll", EntryPoint="CreateCompatibleDC")]
public static extern IntPtr CreateCompatibleDC(IntPtr hdc);
[DllImport("coredll.dll", EntryPoint="GetDC")]
public static extern IntPtr GetDC(IntPtr hwnd);
IntPtr hdc = GetDC(this.Handle);
IntPtr hdcComp = CreateCompatibleDC(hdc);
BitBlt(hdcComp, 0, 0, mybitmap.Width, mybitmap.Height, hb, 0, 0, 0x00CC0020);
제휴하지 않습니다 StackOverflow