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

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.

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

Leave a comment

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

Free Newsletter


How to Solve WhatsApp Not Working Issue on Android

WhatsApp has massive popularity when we talk about modern-day messaging apps. This application literally revolutionized the text-messaging aspect of smartphones. Millions of users can...

8 Best Voice Recorder Apps for Apple Watch to take Voice Notes

Apple Watch is one of the best devices that come handy when you want to record a voice memo. No matter if it is...

10 Best Portable Power Banks for Apple Watch and iPhone

The latest addition in the AppleWatch family, Series 4 is offering two days of battery life. This is enough for our daily routine. When...

iOS 9 & OS X El Capitan – Apple WWDC 2015 Keynote Review

Every year Apple conducting their World Wide Developer Conference for their developers to introduce latest developments in their Softwares like iOS, OS X and...

12 Best Board Games for Android Users

The board games are very popular and now you can access boardgames on Android tablets and phones. Yes, you can still enjoy most of...

12 Best Laptop Camera Cover & Phone Camera Cover

While most people know that your Phone's and Laptop's Camera can spy you. After all, for all you know, a hacker could have access...