package com.example.caseData.utils; import org.springframework.core.io.ClassPathResource; import java.io.*; public class ImageUtil { public static byte[] readImageToBytes(String imagePath) throws IOException { ClassPathResource resource = new ClassPathResource(imagePath); try (InputStream inputStream = resource.getInputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { byte[] buffer = new byte[1024]; int bytesRead; while ((bytesRead = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead); } return outputStream.toByteArray(); } } }