I have a problem with the bitmap generated from a 2D drawing (.slddrw) using GetPreviewBitmapFile
. The image is generated with unnecessary white margins. It doesn't trim the drawing correctly. The issue occurs only with the width, while the height is trimmed properly. I use the generated bitmap to preview the drawing in the Image window in a form that I created. Below, I am attaching photos and a code snippet responsible for generating the preview.
Do you have any ideas on how to fix this?
Here are the bitmaps generated by SolidWorks (You need to click and open the image because in this view, the forum background blends with the white margins of the bitmap):
Here is the part of the code responsible for the preview:
Private Sub ShowPreview(drawingPath As String)
On Error GoTo ErrorHandler
Debug.Print "Rozpoczynam generowanie podglądu dla: " & drawingPath
Dim previewPicture As stdole.StdPicture
Set previewPicture = swApp.GetPreviewBitmap(drawingPath, "")
If previewPicture Is Nothing Then
Debug.Print "Nie udało się uzyskać podglądu!"
Exit Sub
End If
Debug.Print "Uzyskano podgląd:"
Debug.Print "Szerokość: " & previewPicture.Width
Debug.Print "Wysokość: " & previewPicture.Height
Dim tempPath As String
tempPath = Left(drawingPath, InStrRev(drawingPath, "\")) & "preview.bmp"
SavePicture previewPicture, tempPath
Debug.Print "Zapisano podgląd do: " & tempPath
With PreviewImage
.PictureSizeMode = fmPictureSizeModeZoom
.Picture = previewPicture
End With
Exit Sub
ErrorHandler:
Debug.Print "Błąd podczas generowania podglądu: " & Err.Description
Set PreviewImage.Picture = Nothing
End Sub