簡體   English   中英

從JAVA中的對象JSON提取圖像

[英]Extract an image from an object JSON in JAVA

我正在嘗試使用數據庫發送的圖像,我想使用PHP和JSON編寫的WebApi將圖像發送到Java程序; 以下幾行摘錄自PHP程序:

$img = file_get_contents($stringPath);
$array = ["immagine" => base64_encode($img)];
echo json_encode($array);

在以下JAVA程序中,我使用restlet框架:

ClientResource resource = new ClientResource("link to the webApi");``
String retur = resource.get().getText();
JSONObject obj = new JSONObject(retur);

我如何從JSON對象中提取我從PHP progra發送的圖像

如果我理解您的問題正確,那么您只需像在php代碼中一樣執行相反的步驟即可。

byte[] content = Base64.decodeBase64(obj.getString("immagine"));
ByteArrayInputStream bais = new ByteArrayInputStream(content);
BufferedImage image = ImageIO.read(bais);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM