แปลง SVG เป็น BMP ด้วย NET REST API

ในบทความที่ชัดเจนนี้ คุณจะได้เรียนรู้วิธี แปลง SVG เป็น BMP ด้วย NET REST API เราจะพัฒนา ตัวแปลง SVG เป็น BMP ด้วย C# Low Code API โดยทำตามขั้นตอนที่ครอบคลุมที่กล่าวถึงในส่วนต่อไปนี้ แอปพลิเคชันที่สร้างขึ้นสามารถใช้กับแอปพลิเคชัน .NET ใดๆ ที่รองรับในสภาพแวดล้อม macOS, Windows หรือ Linux และสามารถทำการแปลงได้ฟรี

ข้อกำหนดเบื้องต้น

ขั้นตอนในการแปลง SVG เป็น BMP ด้วย NET REST API

  1. ตั้งค่ารหัสไคลเอ็นต์และความลับไคลเอ็นต์สำหรับ API เพื่อแปลง SVG เป็น BMP
  2. สร้างอินสแตนซ์คลาส ImagingAPI ด้วยข้อมูลรับรองผู้ใช้เพื่อทำการแปลง SVG เป็น BMP
  3. ระบุชื่อไฟล์ SVG ต้นทางและเอาต์พุต BMP
  4. เข้าถึงและโหลดไฟล์ SVG ต้นฉบับและอัปโหลดไปยังที่เก็บข้อมูลบนคลาวด์
  5. สร้างอินสแตนซ์ของ ConvertImageRequest ด้วยสตรีมไฟล์ SVG อินพุตและรูปแบบ BMP เอาต์พุต
  6. เรียกใช้เมธอด ConvertImage เพื่อ แปลง SVG เป็น BMP ด้วย NET REST API
  7. บันทึกสตรีมไฟล์ BMP ที่เป็นผลลัพธ์ลงในดิสก์ภายในเครื่อง

ขั้นตอนง่ายๆ คือการส่งออกประเภทไฟล์ จาก SVG เป็น BMP ด้วย C# Low Code API เราจะเริ่มต้นกระบวนการโดยใช้อินสแตนซ์ของคลาส ImagingAPI เพื่อกำหนดค่า SDK จากนั้นเราจะเข้าถึงไฟล์ SVG ต้นทางโดยใช้ FileStream จากดิสก์ จากนั้นโดยใช้อินสแตนซ์คลาส ConvertImageRequest ทำการแปลงเป็น BMP โดยใช้เมธอด ConvertImage()

รหัสสำหรับการแปลง SVG เป็น BMP ใน NET Low Code API

using Aspose.Imaging.Cloud.Sdk.Api;
using Aspose.Imaging.Cloud.Sdk.Model.Requests;
using Aspose.Imaging.Cloud.Sdk.Model;
using System;
using System.IO;
namespace Kb_Aspose.KB
{
public class SvgToBmpConverter
{
public void SvgToBmp()
{
var clientID = "Client ID";
var clientSecret = "Client Secret";
var apiBaseUrl = "https://api.aspose.cloud";
var localPath = "C:/Words/";
var svgToBmpImageApi = new ImagingApi(clientSecret, clientID, apiBaseUrl);
// Source and output file names
var inputFileName = "Source.svg";
var outputFileName = "SvgtoBmp.bmp";
var outputFormat = "bmp";
var remoteFolder = null; // source file is saved at the root of the storage
var remoteStorage = null; // remote cloud Storage place name
try
{
// Upload the local SVG image file to Cloud Storage
var inpuFileStream = File.Open(localPath + '/' + inputFileName, FileMode.Open);
inpuFileStream.Position = 0;
var uploadSvgFileRequest = new UploadFileRequest(inputFileName, inpuFileStream, null);
svgToBmpImageApi.UploadFile(uploadSvgFileRequest);
var convertSvgToBmpRequest = new ConvertImageRequest(inputFileName, outputFormat,
remoteFolder, remoteStorage);
var bmpImageDataStream = svgToBmpImageApi.ConvertImage(convertSvgToBmpRequest);
bmpImageDataStream.Position = 0;
using (var fileStream = File.Create(localPath + outputFileName + "." + outputFormat))
{
bmpImageDataStream.Seek(0, SeekOrigin.Begin);
bmpImageDataStream.CopyTo(fileStream);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}

โค้ดตัวอย่างที่ชัดเจนนี้สาธิตวิธีการแปลง SVG เป็น BMP ด้วย C# Cloud API หลังจากระบุขั้นตอนที่จำเป็นเบื้องต้นแล้ว คุณจะต้องจัดเตรียมเส้นทางเพื่อเข้าถึงอิมเมจ SVG ต้นทางบนดิสก์ และโดยการใช้ Aspose.Imaging REST API SDK ทำการเรนเดอร์ไปยัง BMP ได้รับไฟล์สตรีม BMP ที่ส่งคืนเป็นออบเจ็กต์ตอบสนองหลังจากการแปลงเสร็จสิ้น จากนั้นคุณสามารถบันทึกไว้ในดิสก์หรืออาจใช้สตรีมรูปภาพในแอปพลิเคชันที่จำเป็น

In this article, we have explored to transform SVG to BMP with Cloud API. If you are interested in performing PNG to WEBP conversion, refer to the article on how to Convert PNG to WEBP with NET REST API.

 ไทย