【发布时间】:2019-02-27 22:16:38
【问题描述】:
我想将位图编码为 PNG,然后将其保存到文件中。
但我的heatmap_PictureBox_Bitmap.Save( filepathname )
..导致错误:
GDI+ 中出现一般错误。
heatmap_PictureBox_Bitmap 包含彩色图像。
这可以在我的 Windows 10 上的 .NET 应用上正常显示图片:
public const MOBILE_UPLOADER_PATH = "C:\demo\DEMO4\MOBILE UPLOADER\"
public const XY_HEATMAP_PNG_FILENAME = "XY_HEATMAP.PNG"
public const XY_HEATMAP_PNG_PATHNAME = MOBILE_UPLOADER_PATH & XY_HEATMAP_PNG_FILENAME
dim heatmap_PictureBox_Bitmap as Bitmap
. . .
' Build the image bitmap:
for x = 0 to x_range
for y = 0 to y_range
' red, green, blue are integers 0 to 255
pixel_color = Color.FromArgb( red, green, blue )
heatmap_PictureBox_Bitmap.SetPixel( x, y, pixel_color )
next
next
. . .
PictureBox_heat_map.Image = heatmap_PictureBox_Bitmap ' displays ok
但添加此行(如下)会导致错误“GDI+ 中发生一般错误。”
. . .
heatmap_PictureBox_Bitmap.Save( XY_HEATMAP_PNG_PATHNAME ) <<<< CAUSES THE ERROR
PictureBox_heat_map.Image = heatmap_PictureBox_Bitmap
我的假设:
1.heatmap_PictureBox_Bitmap是非编码/压缩图像数据
2.bitmap.save( pathname )编码为.PNG
我也试过
heatmap_PictureBox_Bitmap.Save(XY_HEATMAP_PNG_PATHNAME, System.Drawing.Imaging.ImageFormat.Png)
..同样的问题。
XY_HEATMAP_PNG_PATHNAME 中的目录存在。
【问题讨论】:
-
如何加载它?加载图像时需要遵循一些规则,例如不释放它们所来自的流。另外,请发布一些实际代码,而不仅仅是伪代码。我们无法从您的代码近似中看出哪里出了问题。
-
我刚刚添加了有关如何创建位图的代码
-
对不起,使用给定的代码,我根本没有收到任何错误。你需要提供更多细节。
-
VB 编辑器修复了大小写和间距。这不可能是真正的代码。您是如何创建或加载位图的?
-
我在 VS 编辑器中关闭了大小写和间距。这是真正的代码。我会提供更多细节。
标签: vb.net image-processing bitmap gdi+