이 자습서에서는 Java REST API를 사용하여 BMP를 JPG로 변환하는 방법을 배웁니다. BMP(비트맵)은 특히 Microsoft Windows 및 OS/2 운영 체제에서 비트맵 디지털 이미지를 저장하는 데 사용되는 이미지 파일 형식입니다. 파일 형식은 최대 10,000 x 10,000 픽셀의 2D 디지털 이미지를 24비트 RGB 색상으로 저장할 수 있으며 최대 1,670만 색상을 허용합니다. BMP 파일 형식은 오늘날 사용되는 가장 오래된 이미지 형식 중 하나이며 크기 조정, 자르기 및 다른 이미지 형식으로의 변환과 같은 간단한 이미지 조작에 널리 사용됩니다.
반면 JPG 또는 JPEG는 Joint Photographic Experts Group의 약자이며 이미지 파일 형식의 한 유형입니다. 파일 크기가 작고 이미지 품질이 높기 때문에 디지털 사진을 저장하는 데 널리 사용됩니다. JPG 파일은 압축률이 높으며 일반적으로 웹 그래픽 및 기타 온라인 이미지에 사용됩니다. Java Low Code API에서 BMP를 JPG로 변환해야 하는 경우 다음 샘플을 사용하여 동일한 작업을 수행할 수 있습니다.
필수 조건
- 계정 생성 및 API 자격 증명 얻기
- 다운로드 Aspose.Imaging Cloud SDK for Java
- 위의 SDK로 Java 프로젝트 설정
Java REST API에서 BMP를 JPG로 변환하는 단계
- API에 대한 클라이언트 ID 및 클라이언트 암호 설정
- 클라이언트 자격 증명으로 ImagingAPI 클래스의 인스턴스 생성
- 입력 및 출력 파일 지정
- 입력된 BMP 파일을 읽고 클라우드 스토리지에 업로드
- 입력 및 출력 파일 형식으로 ConvertImageRequest 객체 생성
- convertImage 메서드를 호출하여 REST API를 사용하여 BMP를 JPG로 변환
- 출력 JPG 파일을 로컬 디스크에 저장
Java Low Code API에서 BMP를 JPG로 변환하는 코드
String ClientID = Client.getID(); //replace Client.getID() with your own client ID here | |
String ClientSecret = Client.getSecret(); //replace3 Client.getSecret() with your own client secret here | |
String APIBaseUrl="https://api.aspose.cloud"; | |
String Local_Path = "C:/Temp/"; | |
ImagingApi imagingApiSdk = new ImagingApi(ClientSecret, ClientID, APIBaseUrl); | |
// Input & output file names | |
String inputFileName = "BMPtoJPG.bmp"; | |
String outputFileName = "BMPtoJPG.jpg"; | |
try { | |
// Upload local image to Cloud Storage | |
File inputFile = new File(Local_Path + inputFileName); | |
FileInputStream inputFileStream = new FileInputStream(inputFile); | |
byte[] inputImageData = IOUtils.toByteArray(inputFileStream); | |
UploadFileRequest uploadFileRequest = new UploadFileRequest(inputFileName, inputImageData, null); | |
FilesUploadResult filesUploadResult = imagingApiSdk.uploadFile(uploadFileRequest); | |
String outputFormat = "jpg"; | |
String remoteFolder = null; // Input file is saved at the root of the storage | |
String remoteStorage = null; // Cloud Storage name | |
ConvertImageRequest convertImageRequest = new ConvertImageRequest(inputFileName, outputFormat, remoteFolder, remoteStorage); | |
byte[] convertedImageData = imagingApiSdk.convertImage(convertImageRequest); | |
// Save exported image to local storage | |
FileOutputStream fileOutputStream = new FileOutputStream(Local_Path + outputFileName); | |
fileOutputStream.write(convertedImageData); | |
fileOutputStream.close(); | |
} catch (Exception e) { | |
System.out.println(e.getMessage()); | |
} |
위에 제공된 코드를 사용하면 Java REST API를 사용하여 BMP를 JPG로 변환할 수 있습니다. Aspose.Imaging REST API SDK의 도움으로 BMP 파일을 제공하고 출력 JPG 파일을 다운로드하여 로컬에 저장하기만 하면 됩니다.
이 BMP에서 JPG로의 변환은 Windows, Linux 또는 Mac에서 코드가 없거나 낮은 코드 앱으로 사용할 수 있습니다.
다음 항목에서 유사한 기능을 찾을 수 있습니다. Java REST API를 사용하여 BMP를 PDF로 변환하는 방법