Skip to content

Instantly share code, notes, and snippets.

@kodiyan
Last active August 29, 2015 14:02
Show Gist options
  • Save kodiyan/a908e6997f2892ace44b to your computer and use it in GitHub Desktop.
Save kodiyan/a908e6997f2892ace44b to your computer and use it in GitHub Desktop.
Converting Picture to Byte from Local Folder and Printe in Console
package com.main;
import javax.imageio.ImageIO;
import org.apache.commons.io.IOUtils;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
public class ImageUtil {
public static String imageWH() {
File imageFile = new File ("C:\\test50.png");
FileInputStream fisLocal = new FileInputStream(imageFile);
byte[] imageByteLocal = IOUtils.toByteArray(fisLocal);
//converting file format
FileInputStream fis = new FileInputStream(imageFile);
//Get Image height and width
BufferedImage bimg = ImageIO.read(fis);
int width = bimg.getWidth();
int height = bimg.getHeight();
return (width + "x" + height);
}
}
@kodiyan
Copy link
Author

kodiyan commented Jun 11, 2014

This is to convert any picture into byte format. You can save this picture into byte format and save to data base if required. This script also measuring the image actual width and height in pixels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment