현재 Grasshopper 캔버스에 비트 맵을 렌더링하는 히스토그램 렌더러 작업 중입니다.비트 맵 렌더링 관련 문제
private readonly Bitmap _overlayedImage;
이름 _image
을 가진 Bitmap
예는 다음과 같습니다 :
_bitmap http://puu.sh/6mUk4/20b879710a.png
두 비트 맵의 총 둘 다private readonly Bitmap _image;
아래에 설명하고있다
t
기본적으로, _overlayedImage
가 _image
비트 맵을 사용하여 생성되는 비트 맵이며, 이름에서 알 수 있듯이, 당신은에서 볼 수있는 (텍스트 오버레이 : 그 이름 _overlayedImage
로 인스턴스를 Bitmap
은 다음과 같습니다 이미지를 올렸습니다) 검정색 배경을 추가합니다. 이것은이
_overlayedImage = overlayBitmap(_image, width * 3, height * 3, times, dates, colors);
* 3
이미지 크기를 조정하는 데 사용됩니다) 할당 방법이다.
현재 여러 가지 문제가 있습니다.
이 방법을 사용하면 _image
을 캔버스에 렌더링 할 수 있습니다.
코드는 다음과 같다 :
protected override void Render(Grasshopper.GUI.Canvas.GH_Canvas canvas, Graphics graphics, Grasshopper.GUI.Canvas.GH_CanvasChannel channel) {
// Render the default component.
base.Render(canvas, graphics, channel);
// Now render our bitmap if it exists.
if (channel == Grasshopper.GUI.Canvas.GH_CanvasChannel.Wires) {
var comp = Owner as KT_HeatmapComponent;
if (comp == null)
return;
List<HeatMap> maps = comp.CachedHeatmaps;
if (maps == null)
return;
if (maps.Count == 0)
return;
int x = Convert.ToInt32(Bounds.X + Bounds.Width/2);
int y = Convert.ToInt32(Bounds.Bottom + 10);
for (int i = 0; i < maps.Count; i++) {
Bitmap image = maps[i].overlayedImage;
if (image == null)
continue;
Rectangle mapBounds = new Rectangle(x, y, maps[i].Width, maps[i].Height);
mapBounds.X -= mapBounds.Width/2;
Rectangle edgeBounds = mapBounds;
GH_Capsule capsule = GH_Capsule.CreateCapsule(edgeBounds, GH_Palette.Normal);
capsule.Render(graphics, Selected, false, false);
capsule.Dispose();
graphics.DrawImage(image, mapBounds);
graphics.DrawRectangle(Pens.Black, mapBounds);
// some graphics interpolation and bicubic methods
y = edgeBounds.Bottom - (mapBounds.Height) - 4;
}
}
}
comp.CachedHeatmaps;
이 무엇인지에 따라 경찰 :
private readonly List<HeatMap> _maps = new List<HeatMap>();
internal List<HeatMap> CachedHeatmaps {
get { return _maps; }
}
그러나, 나는이 _overlayedImage
에 Render()
를 사용하려고 할 때마다, 나는 그렇게 할 수 없다. 우연히있는 전설의 차원은 각각 maps[i].Width
및 maps[i].Height
반환 1
및 100
을 같이
은 내가 Render()
방법으로 문제를 격리 한, 그것은
Rectangle mapBounds = new Rectangle(x, y, maps[i].Width, maps[i].Height);
이 주요 문제가이 선을 보인다 세로 100 픽셀, 가로 1 픽셀
내가 궁금한 점이 많아서 사과 드리지만 다른 방법으로 설명 할 수는 없다고 생각합니다.
가도 캔버스에 표시되기 전에 효과적으로 이미지를 파괴 내가 _overlayedImage.Dispose()
를 사용하여 내 주요 방법으로 :
당신이 비트 맵은 서로 다른 크기를 가지고 있습니다. 다른지도 [i]를 사용해야합니까? 너비/높이를 사용하여 렌더링 하시겠습니까? (당신의 _overlayedImage가 3x 크기이기 때문에) –
흥미롭게도'_maps'의'width'와'height'를 찾으려고 할 때'Render()'는 전혀 호출되지 않습니다. Grasshopper의 기본 동작 치수가 일치하지 않으면'Render()'를 호출하지 않습니다. '_maps'의 크기를 찾는 방법에 대한 아이디어가 있습니까? – theGreenCabbage
오 나는 값을 알아내는 방법을 알아 냈습니다. – theGreenCabbage