Sådan konverteres billede til byte, få billedbredde og højde ved hjælp af Java



Dette er at konvertere et hvilket som helst billede til byte format. Du kan konvertere jpg eller png format til byte format og gemme til database, hvis det kræves ved hjælp af Java. Dette script giver også billedegenskab som den faktiske billedbredde og højden i pixels. Yuu kan få billedegenskaber med formatet "bredde x højde" i et strengformat.

Konverter billede til byte, få billedbredde og højde ved hjælp af Java

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Forrige Artikel

12 Bedste iOS Apps til arkitekter at bruge på iPad og iPhone

12 Bedste iOS Apps til arkitekter at bruge på iPad og iPhone

Facebook Twitter pinterest WhatsApp Telegram IOS Arkitekt Apps begynder at eksplodere i App Store med den store skærm iPad og Apple Pencil. Apps til arkitekter er nemme at bruge, kan spare mange timer i designfasen. Der er masser af funktioner, der tilbydes af iOS arkitekt apps, herunder multicolor tegning, let materiale valg osv....

Næste Artikel

Dette er hvordan du kan finde, hvis nogen har åbnet din GMail

Dette er hvordan du kan finde, hvis nogen har åbnet din GMail

Facebook Twitter pinterest WhatsApp Telegram Har du mistanke om, at nogen læser din Gmail eller sender e-mails fra din Gmail-konto? Dette indlæg beskriver, hvordan man finder ud af, om nogen åbner din GMail-konto. Dette viser dig listen over loginaktiviteter og historien om de seneste succesfulde loginaktiviteter. D...