8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Java】URLから画像を読み込みbinary配列を取得したい

Last updated at Posted at 2015-07-03

画像ファイルアップロードする際に取得したデータをbinary形式で送らなきゃ行けなかったのでメモ
ImageIO便利だった

public byte[] binary getImageByteArray(String imageUrl, String fileNameExtension) {
  URL url = new URL(imageUrl);
  BufferedImage readImage = ImageIO.read(url);
  ByteArrayOutputStream outPutStream = new ByteArrayOutputStream();
  ImageIO.write(readImage, fileNameExtension, outPutStream);
  return outPutStream.toByteArray();
}
byte[] binary = getImageByteArray("http://example.com/example.png", "png");
8
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?