- Cách nhanh nhất để đọc hình ảnh từ một tệp vào BufferedImage trong Java/Grails là gì?
- Cách nhanh nhất để ghi hình ảnh từ BufferedImage vào một tệp trong Java/Grails là gì?
biến thể của tôi (đọc):Cách nhanh nhất để đọc/ghi hình ảnh từ một tệp vào BufferedImage?
byte [] imageByteArray = new File(basePath+imageSource).readBytes()
InputStream inStream = new ByteArrayInputStream(imageByteArray)
BufferedImage bufferedImage = ImageIO.read(inStream)
tôi biến thể (ghi):
BufferedImage bufferedImage = // some image
def fullPath = // image page + file name
byte [] currentImage
try{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, "jpg", baos);
baos.flush();
currentImage = baos.toByteArray();
baos.close();
}catch(IOException e){
System.out.println(e.getMessage());
}
}
def newFile = new FileOutputStream(fullPath)
newFile.write(currentImage)
newFile.close()
Tôi đọc rằng Bộ công cụ Java rất nhanh để đọc không đúng? Bạn có thể sửa đổi câu trả lời của bạn nếu điều này là đúng? –
@ stephan1001 Tôi xin lỗi, tôi không quen với các gói liên quan đến giao diện người dùng. –
Gói đầy đủ của Tệp và Đường dẫn là gì? –