나를 만들고해야 하는 응용 프로그램 추가 많이 제거 할 수 있습니다 UIElement
을 Canvas
.기본적으로 Canvas
의 컬렉션을 포함 UIElement
고 자동으로 렌더/업데이트 화면에 따라 무엇이 포함되어 있습니다.
를 방지하기 위해서는 톤의 UIElements
는 겹치는 서로 다른 화면에 내가 선호하는 추가 모든 이들의 보조 Canvas
를 만든 다음 Image
에서 그것을(감사 WritableBitmap
).마지막으로 추가 이 Image
에 현재 Canvas
.여할 수 있도록 연회장이 마련되어 있으며 이미지 내 캔버스에 기대가 더 나은 성능을 제공합니다.불행하게도 그것은 내가 삭제할 수 없습니다 완전히 WritableBitmap
, 는 경우에도,내가 설정 null
.
다음 코드를 보여 줍니다:
//My constructor
public WP8Graphics()
{
//Here my collection DataBinded with the Canvas from the Mainpage
this.UIElements = new ObservableCollection<UIElement>();
//The secondary Canvas
GraphicCanvas = new Canvas();
GraphicCanvas.Height = MainPage.CurrentCanvasHeight;
GraphicCanvas.Width = MainPage.CurrentCanvasWidth;
}
///This method can be hit thousand times, it basically create a rectangle
public void fillRect(int x, int y, int width, int height)
{
// some code
// CREATE THE RECTANGLE rect
GraphicCanvas.Children.Add(rect); // My secondary Canvas
WriteableBitmap wb1 = new WriteableBitmap(GraphicCanvas, null);
wb1.Invalidate();
WriteableBitmap wb2 = new WriteableBitmap((int)MainPage.CurrentCanvasWidth, (int)MainPage.CurrentCanvasHeight);
for (int i = 0; i < wb2.Pixels.Length; i++)
{
wb2.Pixels[i] = wb1.Pixels[i];
}
wb2.Invalidate();
wb1 = null;
Image thumbnail = new Image();
thumbnail.Height = MainPage.CurrentCanvasHeight;
thumbnail.Width = MainPage.CurrentCanvasWidth;
thumbnail.Source = wb2;
this.UIElements.Add(thumbnail);
}
과 같은 후 24 WriteableBitmap
성 OutOfMemoryException 가 나타납니다.저는 많은 기사를 읽고 이 문제에 대한 내 경우에 그것은 보인다 WriteableBitmap
에 따라 달라집 나 GraphicCanvas 고 남아 있기 때문에 아직도에 대한 참조가 있습니다.할 수 없습 삭제 내 그래픽 캔버스도 설정 myImage 원본은 null 입니다.
저는 2 개의 질문:
- 할 수 있는 다른 방법이 있 이미지를 만들어서 캔버스나의 컬렉션을 UIElements?
- 그것은 가능한 제거하는 기준을 유지하는 WriteableBitmap 살아?
될 수 있도록 노력하겠습니다 충분히 명확하고 쉽게 읽을 수 있습니다.
을 읽어 주셔서 감사합니다.
편집 atomaras 제안하지만 여전히 같은 문제
WriteableBitmap wb1 = new WriteableBitmap(GraphicCanvas, null);
이 라인이 여전히 발생 OutOfMemoryException.