Created
April 24, 2026 10:46
-
-
Save blog-aspose-cloud/904d8dcac71d16525ef4a1b1af4ad42d to your computer and use it in GitHub Desktop.
Convert STL to JPG in .NET
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.IO; | |
| using Aspose.CAD.Cloud.Sdk; | |
| using Aspose.CAD.Cloud.Sdk.Model; | |
| class Program | |
| { | |
| static void Main() | |
| { | |
| // 1. Authenticate | |
| var authApi = new AuthApi("https://api.aspose.cloud"); | |
| var token = authApi.OAuthTokenPost(new OAuthTokenRequest | |
| { | |
| GrantType = "client_credentials", | |
| ClientId = "YOUR_CLIENT_ID", | |
| ClientSecret = "YOUR_CLIENT_SECRET" | |
| }); | |
| // 2. Upload STL | |
| var storageApi = new StorageApi(token.AccessToken); | |
| using (var stlStream = File.OpenRead("model.stl")) | |
| { | |
| storageApi.UploadFile("TempFolder/model.stl", stlStream); | |
| } | |
| // 3. Convert to JPG | |
| var cadApi = new CadApi(token.AccessToken); | |
| var options = new ConvertOptions | |
| { | |
| Format = "jpg", | |
| Quality = 85, // JPEG quality (0‑100) | |
| Width = 1024, // Desired width in pixels | |
| Height = 768 // Desired height in pixels | |
| }; | |
| cadApi.ConvertFile("TempFolder/model.stl", "TempFolder/model.jpg", options); | |
| // 4. Download JPG | |
| using (var jpgStream = storageApi.DownloadFile("TempFolder/model.jpg")) | |
| using (var file = File.Create("model_converted.jpg")) | |
| { | |
| jpgStream.CopyTo(file); | |
| } | |
| // 5. Clean up temporary files | |
| storageApi.DeleteFile("TempFolder/model.stl"); | |
| storageApi.DeleteFile("TempFolder/model.jpg"); | |
| Console.WriteLine("Conversion completed successfully."); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment