[英]GetPreviewBitmapFile save preview bitmap with strange colors (SolidWorks)
I'm developing C# VSTA macro for our manufacturing department. 我正在为我们的制造部门开发C#VSTA宏。 I'm using SldWorks.GetPreviewBitMapFile
to save a bitmap preview of the selected model and show it in the picturebox as shown below: 我正在使用SldWorks.GetPreviewBitMapFile
保存所选模型的位图预览,并将其显示在图片框中,如下所示:
The code looks fine and execute fine except for the strange colors: 该代码看起来不错,并且执行得很好,除了奇怪的颜色:
bool status = swApp.GetPreviewBitmapFile(filepath, configuration, "D:\\preview.bmp");
pictureBox1.ImageLocation = "D:\\Preview.bmp";
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.Refresh();
Has anyone had a similar problem and what's the remedy? 有没有人有类似的问题,有什么补救办法?
Here is an example of working code: 这是一个工作代码示例:
//to compare output
iSwApp.GetPreviewBitmapFile(@"c:\Path\Part1.SLDPRT", "Default", @"c:\Path\Part1_0.bmp");
object com = iSwApp.GetPreviewBitmap(@"c:\Path\Part1.SLDPRT", "Default");
stdole.StdPicture pic = com as stdole.StdPicture;
Bitmap bmp = Bitmap.FromHbitmap((IntPtr)pic.Handle);
bmp.Save(@"c:\Path\Part1_1.bmp");
There are few notes about GetPreviewBitmap from SW API: 关于SW API的GetPreviewBitmap的几点说明:
I was able to make it work in SolidWorks x64 only in .NET add-in and in VBA macros. 我能够使其仅在.NET插件和VBA宏中在SolidWorks x64中工作。 Let me know if you need add-in example. 让我知道您是否需要插件示例。
An update for SW2016. SW2016的更新。 The GetPreviewBitmapFile function works for an out-of-process Csharp console program. GetPreviewBitmapFile函数适用于进程外的Csharp控制台程序。 However, the colors of the generated bitmap are very strange. 但是,生成的位图的颜色非常奇怪。 It turns out the only valid solution is to use the SaveBmp function. 事实证明,唯一有效的解决方案是使用SaveBmp函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.