I'm working on a VB.NET program that resizes the current drawing window and creates a bitmap file.
Currently, I can get the window to resize to the correct length and width. However, I'm lost as far as creating a bitmap. I found some code in C# on the Through the Interface site:
Unfortunately, I'm not that familiar with C# and can't get the code to work if I try to convert to VB.net.
Any help would be greatly appreciated.
Ultimately, I want to then convert the bmp file to a gif with a transparent background. I know how to convert a bmp to gif, but is it possible to programmatically convert it to a transparent background?
You can use an online service to translate from C# to VB, like this DevFusion, using that, the code from Kean blog translate to this:
Imports acApp = Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.Runtime Imports System.Drawing.Imaging Imports System.Drawing Namespace ScreenshotTest Public Class Commands <CommandMethod("CSS")> _ Public Shared Sub CaptureScreenShot() ScreenShotToFile(acApp.Application.MainWindow, "c:\main-window.png", 0, 0, 0, 0) ScreenShotToFile(acApp.Application.DocumentManager
.MdiActiveDocument.Window, "c:\doc-window.png", 30, 26, 10, 10) End Sub Private Shared Sub ScreenShotToFile(wd As Autodesk.AutoCAD.Windows.Window, filename As String, top As Integer, bottom As Integer, left As Integer, right As Integer) Dim pt As Point = wd.Location Dim sz As Size = wd.Size pt.X += left pt.Y += top sz.Height -= top + bottom sz.Width -= left + right ' Set the bitmap object to the size of the screen Dim bmp As New Bitmap(sz.Width, sz.Height, PixelFormat.Format32bppArgb) Using bmp ' Create a graphics object from the bitmap Using gfx As Graphics = Graphics.FromImage(bmp) ' Take a screenshot of our window gfx.CopyFromScreen(pt.X, pt.Y, 0, 0, sz, CopyPixelOperation.SourceCopy) ' Save the screenshot to the specified location bmp.Save(filename, ImageFormat.Png) End Using End Using End Sub End Class End Namespace
As for a GIF file with a transparency color, you can do it using GDI+ and setting the Alfa of the selected color to 0 in the palette of the GIF, remember that GIF file have a palette with the colors (max 256) to display.
Thank you Gaston,
I didn't explain clearly in my original post, but the bmp will be created from a selection set. I'm not sure how I can use that code with a selection set.
Here's my code. I commented where I need to create the bmp. This can be done with COM, however, I would prefer to figure out how to do it with .net code.
Public Sub Main() Dim doc As Document = Application.DocumentManager.MdiActiveDocument() Dim ed As Editor = doc.Editor Dim docWindow As Window = doc.Window docWindow.WindowState = Window.State.Normal Dim size As System.Drawing.Size = docWindow.GetSize ed.WriteMessage(vbCrLf + "Document Size:" + vbCrLf + size.ToString() + vbCrLf) Dim newSize As System.Drawing.Size = New System.Drawing.Size(950, 573) 'was 608 docWindow.SetSize(newSize) ZoomExtents() '' Select objects in the drawing area Dim ssPrompt As PromptSelectionResult = ed.GetSelection() '' If the prompt status is OK, objects were selected If ssPrompt.Status = PromptStatus.OK Then Dim acSSet As SelectionSet = ssPrompt.Value 'This is where I want to export the selection set to a bmp file End If
What about of using the plotting API to export the zoomed area to a bitmap file?, you have to use the appropriate pc3 configuration file (Publish to Web JPG/PNG.pc3 or create a new one in the plotter manager).
The BMPOUT command does accept a selection set, but you would probably need to pInvoke acedCommand from objectArx c++ in order initialize it properly. (I'm using it from C++).
Otherwise, Keans' code should work just fine, just set visibility false or turn off unwanted layers on whatever you don't want to display in the image, and restore it afterwards.