2009-09-28 5 views
7

기본적으로 픽셀을 비트 맵에 쓰고 WPF를 통해 해당 비트 맵을 업데이트하고 표시 할 수있는 WPF에서 GDI 유형 기능을 원합니다. 참고, 마우스 움직임에 대한 응답으로 픽셀을 업데이트하여 즉석에서 비트 맵에 애니메이션을 적용 할 수 있어야합니다. InteropBitmap은 메모리의 픽셀에 쓸 수 있고 메모리 위치를 비트 맵에 복사 할 수 있기 때문에 InteropBitmap이 완벽하다는 것을 읽었습니다.하지만 좋은 예제가 없습니다.wpf 2d 고성능 그래픽

누구나 WPF에서 고성능 2D 그래픽을 수행하기 위해 InteropBitmap 또는 다른 클래스를 사용하는 데 유용한 리소스, 자습서 또는 블로그를 알고 있습니까?

+0

픽셀 단위로 작업하는 경우 WPF가 정말로 필요합니까? – MusiGenesis

+0

나머지 응용 프로그램의 컨텍스트는 WPF입니다. – Klay

답변

4

다음은 내가 찾은 것입니다 :

Image를 서브 클래 싱하는 클래스를 생성했습니다.

public class MyImage : Image { 
    // the pixel format for the image. This one is blue-green-red-alpha 32bit format 
    private static PixelFormat PIXEL_FORMAT = PixelFormats.Bgra32; 
    // the bitmap used as a pixel source for the image 
    WriteableBitmap bitmap; 
    // the clipping bounds of the bitmap 
    Int32Rect bitmapRect; 
    // the pixel array. unsigned ints are 32 bits 
    uint[] pixels; 
    // the width of the bitmap. sort of. 
    int stride; 

public MyImage(int width, int height) { 
    // set the image width 
    this.Width = width; 
    // set the image height 
    this.Height = height; 
    // define the clipping bounds 
    bitmapRect = new Int32Rect(0, 0, width, height); 
    // define the WriteableBitmap 
    bitmap = new WriteableBitmap(width, height, 96, 96, PIXEL_FORMAT, null); 
    // define the stride 
    stride = (width * PIXEL_FORMAT.BitsPerPixel + 7)/8; 
    // allocate our pixel array 
    pixels = new uint[width * height]; 
    // set the image source to be the bitmap 
    this.Source = bitmap; 
} 

WriteableBitmap에는 서명되지 않은 int 배열을 픽셀 데이터로 사용하는 WritePixels라는 메서드가 있습니다. 나는 이미지의 소스를 WriteableBitmap으로 설정했다. 이제 픽셀 데이터를 업데이트하고 WritePixels를 호출하면 이미지가 업데이트됩니다.

저는 비즈니스 포인트 데이터를 포인트 목록으로 별도의 개체에 저장합니다. 목록에서 변환을 수행하고 변환 된 점으로 픽셀 데이터를 업데이트합니다. 이렇게하면 기하학 객체의 오버 헤드가 없습니다.

참고로, 나는 포인트를 Bresenham의 알고리즘이라는 것을 사용하여 그린 선으로 연결합니다.

이 방법은 매우입니다. 눈에 띄는 지체없이 마우스 움직임에 대한 응답으로 약 50,000 포인트 (및 연결 라인)를 업데이트하고 있습니다.

1

여기에 Web cameras with InteropBitmap을 사용하는 블로그 게시물이 있습니다. InteropBitmap의 사용법을 보여주는 전체 소스 코드 프로젝트가 포함되어 있습니다.

+0

블로그에서이 인용문을 사랑하십시오. "... 이미징 측면에서 WPF 성능이 좋지 않습니다." – MusiGenesis