.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

create a bitmap file from the current dwg

5 REPLIES 5
Reply
Message 1 of 6
btmcad
4060 Views, 5 Replies

create a bitmap file from the current dwg

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:

http://through-the-interface.typepad.com/through_the_interface/2009/09/taking-screenshots-of-autocad...

 

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?

 

Thanks

btm

5 REPLIES 5
Message 2 of 6
ow
Contributor
in reply to: btmcad

You can use the BMPOUT command. (Or PNGOUT).

 

 

Regards,

ow

Message 3 of 6
hgasty1001
in reply to: btmcad

Hi,

 

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.

 

Gaston Nunez

 

 

 

 

 

Message 4 of 6
btmcad
in reply to: hgasty1001

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

 

Message 5 of 6
hgasty1001
in reply to: btmcad

Hi,

 

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).

 

Gaston Nunez

Message 6 of 6
ow
Contributor
in reply to: btmcad

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.

 

ow

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost