CADImage from CADImage to BMP

Discuss and ask questions about CAD DLL (CAD Image DLL, CAD Importer DLL).

Moderators: SDS, support, admin

Post Reply
Javier
Posts: 1
Joined: 07 Dec 2004, 11:44
Location: Mexico

CADImage from CADImage to BMP

Post by Javier » 07 Dec 2004, 11:51

I want to know how I can save my .PLT file into BMP format in C#.

I tried with this but it does not work.[xx(]

Code: Select all

private void btnConvert_Click(object sender, System.EventArgs e)
		{
			float AbsWidht=0, AbsHeight=0;
			CADDraw CrDraw= new CADDraw();
			FRect CrDraw1= new FRect();
			long r=0;
			double K= 0;

			DLLWin32Import.GetBoxCAD(DLLWin32Import.CADFile, AbsWidht, AbsHeight);
			DLLWin32Import.GetClientRect(DLLWin32Import.CADFile, ref CrDraw.R);
			if (AbsWidht==0)
				K= 1;
			else
				K= AbsHeight/ AbsWidht;
			//DLLWin32Import.GetExtentsCAD(DLLWin32Import.CADFile, ref CrDraw1);
			CrDraw.Size= Marshal.SizeOf(CrDraw);
			CrDraw.R.Top= 0;
			CrDraw.R.Left= 0;
			
			CrDraw.R.Right= CrDraw.R.Right * 100 / 100;
			CrDraw.R.Bottom= Convert.ToInt32(((double)(CrDraw.R.Right * K)));
			CrDraw.R.Bottom= CrDraw.R.Bottom * 100 / 100;
			CrDraw.DrawMode= 0;
			
			IntPtr hImagen= DLLWin32Import.DrawCADtoBitmap(DLLWin32Import.CADFile, ref CrDraw);
			long Size = DLLWin32Import.GlobalSize(hImagen);
			
            IntPtr P = DLLWin32Import.GlobalLock(hImagen);
            IntPtr FHnd = DLLWin32Import.CreateFile("c:\\ejemplo.bmp", GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, IntPtr.Zero);
			DLLWin32Import.WriteFile (FHnd,ref P, Size,ref r, 0);
            DLLWin32Import.CloseHandle( FHnd);
            DLLWin32Import.GlobalUnlock( hImagen);
            DLLWin32Import.GlobalFree( hImagen);
}

public class DLLWin32Import
	{
		public static IntPtr CADFile = new IntPtr();
		public static float fAbsHeight, fAbsWidth;
		public static int fScale = 100;
		public static int FX, FY;
		public static FPoint fScaleRect = new FPoint();
		public static Point fStart = new Point();
		public static Point fOld = new Point();

		[DllImport("kernel32.dll")]
		public static extern IntPtr WriteFile (IntPtr hFile, ref IntPtr lpBuffer , long nNumberOfBytesToWrite, ref long lpNumberOfBytesWritten, int lpOverlapped);
		[DllImport("kernel32.dll")]
		public static extern IntPtr CreateFile(string lpFileName, long dwDesiredAccess, long dwShareMode, int lpSecurityAttributes, long dwCreationDisposition , long dwFlagsAndAttributes, IntPtr hTemplateFile);
		[DllImport("kernel32.dll")]					public static extern long CloseHandle(IntPtr hObject);
		[DllImport("kernel32.dll")]	
		public static extern IntPtr GlobalAlloc(long wFlags, long dwBytes);
		[DllImport("kernel32.dll")]
		public static extern IntPtr GlobalFree(IntPtr hMem);
		[DllImport("kernel32.dll")]
		public static extern IntPtr GlobalLock (IntPtr hMem); 
		[DllImport("kernel32.dll")]
		public static extern IntPtr GlobalUnlock(IntPtr hMem);
	    [DllImport("kernel32.dll")]
		public static extern long GlobalSize(IntPtr hMem);
		[DllImport("User32.dll")]
		public static extern bool GetClientRect (IntPtr hWnd, ref Rect fRect);
		[DllImport("CADImage.dll")]
		public static extern IntPtr CreateCAD(IntPtr hWindow, string lpFileName);		
		[DllImport("CADImage.dll")]
		public static extern int CloseCAD(IntPtr hObject);
		[DllImport("CADImage.dll")]
		public static extern int DrawCAD(IntPtr hObject, IntPtr hDC, ref Rect lprc); //??
		[DllImport("CADImage.dll")]
		public static extern int GetExtentsCAD(IntPtr handle, ref FRect fRect);	
		[DllImport("CADImage.dll")] 
		public static extern int CADLayerCount(IntPtr hObject);
		[DllImport("CADImage.dll")] 
		public static extern IntPtr CADLayer(IntPtr hObject, int nIndex, ref DXFData lpData);
		[DllImport("CADImage.dll")] 
		public static extern int GetLastErrorCAD([MarshalAs(UnmanagedType.LPStr)]string lbBuf);
		[DllImport("CADImage.dll")] 
		public static extern int DrawCADEx(IntPtr hObject, ref CADDraw lpcd);
		[DllImport("CADImage.dll")] 
		public static extern int CADLayerVisible(IntPtr hObject, int visible);
		[DllImport("CADImage.dll")] 
		public static extern int CADVisible(IntPtr hObject, [MarshalAs(UnmanagedType.LPStr)] string lpLayerName);				
		[DllImport("CADImage.dll")] 
		public static extern IntPtr DrawCADtoBitmap(IntPtr hObject, ref CADDraw lpcd);
		[DllImport("CADImage.dll")] 
		public static extern IntPtr DrawCADtoGif(IntPtr hObject, ref CADDraw lpcd);
		[DllImport("CADImage.dll")] 
		public static extern IntPtr DrawCADtoJpeg(IntPtr hObject, ref CADDraw lpcd);
		[DllImport("CADImage.dll")]
		public static extern int GetBoxCAD(IntPtr hObject, float AbsWidht, float AbsHeight);
	}

Evgeny
Posts: 115
Joined: 16 Mar 2004, 11:04
Location: Russia

Post by Evgeny » 09 Dec 2004, 15:41

<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by Javier</i>
<br />I want to know how I can save my .PLT file into BMP format in C#.

<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
Thank you for your question.
We will make and publish demo as soon as possible.

support
Posts: 3254
Joined: 30 Mar 2005, 11:36
Contact:

Post by support » 04 Aug 2006, 13:22

CADImageDLL (available on: http://www.cadsofttools.com/download/cadimage.zip) containes <b>C#</b> demo application. Follow the <b>File > Save As BMP</b> menu items.

Sergey.

please post questions to the forum or write to support@cadsofttools.com

Post Reply