ในบทความที่ชัดเจนนี้ คุณจะได้เรียนรู้วิธี แปลง PNG เป็น BMP ด้วย NET REST API เราจะพัฒนา ตัวแปลง PNG เป็น BMP ด้วย C# Low Code API โดยทำตามขั้นตอนที่ครอบคลุมที่กล่าวถึงในส่วนต่อไปนี้ แอปพลิเคชันที่สร้างขึ้นสามารถใช้กับแอปพลิเคชัน .NET ใดๆ ที่รองรับในสภาพแวดล้อม macOS, Windows หรือ Linux และสามารถทำการแปลงได้ฟรี
ข้อกำหนดเบื้องต้น
สร้างบัญชีและรับข้อมูลรับรอง API เพื่อทำการแปลง PNG เป็น BMP
ดาวน์โหลด Aspose.Imaging Cloud SDK for .NET to convert PNG to BMP
กำหนดค่าโครงการ C# .NET ด้วย SDK ข้างต้นเพื่อแปลง PNG เป็น BMP
ขั้นตอนในการแปลง PNG เป็น BMP ด้วย NET REST API
- ตั้งค่ารหัสไคลเอ็นต์และความลับไคลเอ็นต์สำหรับ API เพื่อแปลง PNG เป็น BMP
- สร้างอินสแตนซ์คลาส ImagingAPI ด้วยข้อมูลรับรองผู้ใช้เพื่อทำการแปลง PNG เป็น BMP
- ระบุต้นทาง PNG และชื่อไฟล์ BMP เอาท์พุต
- เข้าถึงและโหลดไฟล์ PNG ต้นฉบับและอัปโหลดไปยังที่เก็บข้อมูลบนคลาวด์
- สร้างอินสแตนซ์ของ ConvertImageRequest ด้วยสตรีมไฟล์ PNG อินพุตและรูปแบบ BMP เอาต์พุต
- เรียกใช้เมธอด ConvertImage เพื่อ แปลง PNG เป็น BMP ด้วย NET REST API
- บันทึกสตรีมไฟล์ BMP ที่ส่งคืนบนดิสก์ภายในเครื่อง
ขั้นตอนง่ายๆ คือการส่งออกไฟล์ประเภท จาก PNG เป็น BMP ด้วย C# Low Code API เราจะเริ่มต้นด้วยการเริ่มต้น SDK โดยใช้อินสแตนซ์ของคลาส ImagingAPI จากนั้นเราจะเข้าถึงไฟล์ PNG ต้นทางโดยใช้ FileStream จากดิสก์ จากนั้นโดยใช้อินสแตนซ์คลาส ConvertImageRequest ทำการแปลงเป็น BMP โดยใช้เมธอด ConvertImage()
รหัสสำหรับการแปลง PNG เป็น 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 PngToBmpConverter | |
{ | |
public void PngToBmp() | |
{ | |
var clientID = "Client ID"; | |
var clientSecret = "Client Secret"; | |
var apiBaseUrl = "https://api.aspose.cloud"; | |
var localPath = "C:/Words/"; | |
var pngToBmpImageApi = new ImagingApi(clientSecret, clientID, apiBaseUrl); | |
// Source and output file names | |
var inputFileName = "Source.png"; | |
var outputFileName = "PngtoBmp.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 PNG image file to Cloud Storage | |
var inpuFileStream = File.Open(localPath + '/' + inputFileName, FileMode.Open); | |
inpuFileStream.Position = 0; | |
var uploadPngFileReques = new UploadFileRequest(inputFileName, inpuFileStream, null); | |
pngToBmpImageApi.UploadFile(uploadPngFileReques); | |
var convertPngToBmpRequest = new ConvertImageRequest(inputFileName, outputFormat, | |
remoteFolder, remoteStorage); | |
var bmpDataStream = pngToBmpImageApi.ConvertImage(convertPngToBmpRequest); | |
bmpDataStream.Position = 0; | |
using (var fileStream = File.Create(localPath + outputFileName + "." + outputFormat)) | |
{ | |
bmpDataStream.Seek(0, SeekOrigin.Begin); | |
bmpDataStream.CopyTo(fileStream); | |
} | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine(e.Message); | |
} | |
} | |
} | |
} |
โค้ดตัวอย่างที่ชัดเจนนี้สาธิตวิธีการแปลง PNG เป็น BMP ด้วย C# Cloud API หลังจากจัดการขั้นตอนที่จำเป็นเบื้องต้นแล้ว คุณจะต้องจัดเตรียมเส้นทางเพื่อเข้าถึงอิมเมจ PNG ต้นทางบนดิสก์ และโดยการใช้ Aspose.Imaging REST API SDK ทำการเรนเดอร์ไปยัง BMP ได้รับสตรีมไฟล์รูปภาพ BMP ที่เป็นผลลัพธ์เป็นการตอบกลับหลังจากการแปลงเสร็จสิ้น จากนั้นคุณสามารถบันทึกไว้ในดิสก์ได้
In this article, we have explored to transform PNG to BMP with Cloud API. If you are interested in performing JPG to WEBP conversion, refer to the article on how to Convert JPG to WEBP with NET REST API.