我有一個腳本,它返回一個基於顏色對象的List
的熱圖(它們是在圖形編碼軟件Grasshopper中從Gradient組件導出的RGB值)像這樣:調整位圖對象的物理尺寸
下面是一個返回Bitmap
我的C#熱圖拉法的摘錄。
private Bitmap DrawHeatmap(List<Color> colors, int U, int V){
colorHeatmapArray = new Color[colors.Count()];
for(int i = 0; i < colors.Count(); i++){
colorHeatmapArray[i] = colors[i];
}
// Create heatmap image.
Bitmap map = new Bitmap(U, V, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
int x = 0;
int y = 0;
for(int i = 0; i < colors.Count(); i++){
Color color = colorHeatmapArray[i];
map.SetPixel(x, y, color);
y++;
if (y >= map.Height){
y = 0;
x++;
}
if (x >= map.Width){
break;
}
}
return map;
}
我用於保存圖像的方法是這樣的:
private void saveBMP(){
_heatmap.Save(Path); // Path is just a string declared somewhere
}
_heatmap
是一個實例變量,聲明如下:private Bitmap _heatmap;
,其中I存儲在Bitmap
對象,使用DrawHeatmap()
方法。
我顯示在草蜢的「畫布」上的圖像的方式依賴於一些特定的蟈蟈法,具體而言,這個片段
RectangleF rec = Component.Attributes.Bounds;
rec.X = rec.Right + 10;
rec.Height = Height;
rec.Width = Width;
canvas.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
canvas.Graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
canvas.Graphics.DrawImage(_heatmap, GH_Convert.ToRectangle(rec));
canvas.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
canvas.Graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Default;
canvas.Graphics.DrawRectangle(Pens.Black, GH_Convert.ToRectangle(rec));
然而,當我保存Bitmap
對象,結果我得到的是稍微更高版本的我有什麼在畫布上,它看起來像這樣:
看起來不很漂亮是吧?
我的問題是 - 在調用saveBMP()
方法時,是否有辦法操縱Bitmap
來調整尺寸,使其看起來像我在畫布上所看到的那樣?
我不看到頂部圖像被映射到底部圖像的明顯方式。它看起來很相似,頂部的一個也看起來像是由剪刀手愛德華斯畫的。無法用酸葡萄釀造出優質的葡萄酒,「美麗」並不意味着什麼。 –
好吧,'RectangleF'代碼片段是熱圖在畫布上的顯示。 '_heatmap'對象沒有尺寸變化。它永遠不會被改變。我的問題是,有沒有辦法按'saveBMP()'操作'Bitmap'對象的尺寸?我不知道我是否在這裏正確地措辭。 – theGreenCabbage
不,這是不可能的。創建位圖對象時,位圖的大小是固定的。 U和V代碼。如果您重新調整圖像以使其適合位圖,那麼您對InterpolationMode屬性非常感興趣。最近的鄰居非常快,它不是很漂亮。當您使用SetPixel()時,您並不在意速度。 –