Message 1 of 3
Need Help in using saveas function to save thumbnail image

Not applicable
10-08-2016
02:44 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Now I am facing a problem,I use database.SaveAs function to save a dwg file,but the dwg file do not have an thumbnail image,so I trid to search kean's blog ,and I write code like below,but I can't get what I want.
[CommandMethod("SendSaveAsCmd", CommandFlags.Session)] public static void DoSaveAs() { string filepath = @"C:\Users\FL_DRAWING\Desktop\Images\1.dwg"; string targetpath = @"C:\Users\FL_DRAWING\Desktop\Images\newdwg.dwg"; Document doc = Application.DocumentManager.Open(filepath, false); doc.LockDocument(); Database db = doc.Database; object ocmd = Application.GetSystemVariable("CMDECHO"); string newpath = targetpath.Replace("\\", "/"); string cmd = "(setvar \"CMDECHO\" 0)" + "(command \"_.SAVEAS\" \"\" \"" + newpath + "\")" + "(setvar \"CMDECHO\" " + ocmd.ToString() + ")" + "(princ) "; doc.SendStringToExecute(cmd,false,false,false); doc.CloseAndDiscard(); }
And I tried Another way like below
[CommandMethod("SaveThumbnail", CommandFlags.Session)] public static void DoSaveThumbnail() { string filepath = @"C:\Users\FL_DRAWING\Desktop\Images\1.dwg"; string targetpath = @"C:\Users\FL_DRAWING\Desktop\Images\newdwg.dwg"; Document doc = Application.DocumentManager.Open(filepath); doc.LockDocument(); Database db = doc.Database; db.RetainOriginalThumbnailBitmap = true; Bitmap thumb = db.ThumbnailBitmap; db.ThumbnailBitmap = thumb; db.SaveAs(targetpath, DwgVersion.Current); doc.CloseAndDiscard(); }
But the thumb is null in line Bitmap thumb = db.ThumbnailBitmap
In one of kean's blog ,I saw Document.CapturePreviewImage
So I rewrite my code like below
[CommandMethod("SaveThumbnail", CommandFlags.Session)] public static void DoSaveThumbnail() { string filepath = @"C:\Users\FL_DRAWING\Desktop\Images\1.dwg"; string targetpath = @"C:\Users\FL_DRAWING\Desktop\Images\newdwg.dwg"; Document doc = Application.DocumentManager.Open(filepath); doc.LockDocument(); Database db = doc.Database; Bitmap thumb = doc.CapturePreviewImage(320, 240); db.ThumbnailBitmap = thumb; db.SaveAs(targetpath, DwgVersion.Current); doc.CloseAndDiscard(); }
And I get a thumbnail image with a black background, but the thumbnail could not fullfill the thumbnail in Windows document viewer.And I also could not see cleer in Windows Document viewer.
Any help will be great, thank you.