Home Code How to Convert Picture into Byte, Get Image Width and Height using...

How to Convert Picture into Byte, Get Image Width and Height using Java

This is to convert any picture into byte format. You can convert jpg or png format into byte format and save it to the database if required using Java. This script also gives image property like actual image width and height in pixels. You can get picture properties with “width x height” format in a string format.

Convert Picture into Byte, Get Image Width and Height using Java

Related: How to Take Screenshot and Save to MSSQL Database using Java and Selenium Webriver

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);

Disclaimer: MashTips is supported by its audience. When you purchase through links on our site, we may earn an affiliate commission at no extra cost to you.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Free Newsletter


How to Transfer Files Between Smartphone and Computer?

Sometimes you may need to move around files between your smartphones and computer like iPhone, Android, Mac, and PC. This is necessary, because, most...

Search MP3 Songs & Download with Google Search Engine

With Search Engines like Google and Bing, you can search Mp3 and other songs and download songs to your computer directly from the browser. There is...

A Complete Guide to Switch From iPhone to Android

Smartphone users are switching back and forth between iPhone and Android Phones. This guide to switch from iPhone to Android is to effectively transfer...

Best Selfie App for iPhone to Enhance your Photos.

Even though you have a powerful camera on iPhone, the selfies may not come as perfect when you use the front camera. Here the...

How to find out Blackberry phone locked or unlocked?

There is no way to use your cell phone in outside of your country if it is locked bu your service provider unless they...

How to Get Animated Stickers on WhatsApp

WhatsApp Sticker is a pretty fun way to chat with your favorite ones over WhatsApp. Following the image stickers, you can now send animated...