我目前正在研究将位图渲染到Grasshopper画布上的直方图渲染器。共有两个位图的是,他们都低于渲染位图的问题
private readonly Bitmap _image;
解释和:
private readonly Bitmap _overlayedImage;
的Bitmap
实例名为_image
看起来是这样的:
_bitmap http://puu.sh/6mUk4/20b879710a.png
虽然t他Bitmap
实例名称为_overlayedImage
看起来是这样的:
基本上,_overlayedImage
是使用_image
位图创建位图,顾名思义,覆盖文本(你可以在看我发布的图片)并添加了黑色背景。这是它是如何分配
_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()
,我无法这样做。
我已隔离问题向Render()
方法,它似乎这条线
Rectangle mapBounds = new Rectangle(x, y, maps[i].Width, maps[i].Height);
是主要问题,因为分别maps[i].Width
和maps[i].Height
返回1
和100
,这是巧合的图例的尺寸,这是垂直100像素和水平1像素。
我对这个长得不错的问题表示歉意,但我不认为我可以用任何其他方式解释它。
你的两个位图有不同的尺寸。你应该使用不同的地图[i] .Width/Height来渲染? (因为你的_overlayedImage是size的3倍) –
有趣的是,当我试图找出'_maps'的'width'和'height'时,我的'Render()'根本不会被调用,因为默认的Grasshopper行为如果尺寸不匹配,则不调用Render()。有关如何查找'_maps'的维度的任何想法? – theGreenCabbage
哦,我想出了如何找出价值。 – theGreenCabbage