URL the URL=new URL (" http://image.luzhua.com/image/ooYBAFqf9mKAAOD-AANzINToj5k774.PNG ");
TrustAllHosts ();
URLConnection dConn=url. The openConnection ();
DConn. SetRequestProperty (" accept ", "*/*");
DConn. SetRequestProperty (" connection ", "Keep Alive -");
DConn. SetRequestProperty (" the user-agent, "
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ");
DConn. SetRequestProperty (" Accept - Charset ", "utf-8");
DConn. SetRequestProperty (" contentType ", "utf-8");
DConn. SetConnectTimeout (5000);
DConn. SetReadTimeout (5000);
DConn. SetUseCaches (false);
DConn. SetDefaultUseCaches (false);
DConn. The connect ();
ByteArrayOutputStream baos=new ByteArrayOutputStream ();
Byte [] buffer=new byte [1024].
int len;
While ((len=input. Read (buffer)) & gt; 1) {
Baos. Write (buffer, 0, len);
}
Baos. Flush ();
String suffix=ImageType. ImageType (new ByteArrayInputStream (baos. ToByteArray ()));
BufferedImage image=ImageIO. Read (new ByteArrayInputStream (baos. ToByteArray ()));
This. Height=image. GetHeight ();
This. Width=image. GetWidth ();
Some images will appear this kind of problems
Javax.mail. Imageio. IIOException: Error reading PNG image data
At com. Sun. Imageio. Plugins. PNG. PNGImageReader. ReadImage (PNGImageReader. Java: 1308)
At com. Sun. Imageio. Plugins. PNG. PNGImageReader. Read (1577) PNGImageReader. Java:
The at javax.mail. Imageio. Imageio. Read (imageio. Java: 1448)
The at javax.mail. Imageio. Imageio. Read (imageio. Java: 1352)
. At com. The onion. The health system. View image. The ImageInfo. & lt; init> (ImageInfo. Java: 73)
At com. Onion. Health. System. View image. CrawlDownImage. ImageInfo (CrawlDownImage. Java: 150)
. Ats com. The onion. The health system. The article. The service. The impl. ArticleFileServiceImpl. Main (271) ArticleFileServiceImpl. Java:
Under Caused by: Java. IO. EOFException: Unexpected end of ZLIB input stream
The at Java. Util. Zip. InflaterInputStream. The fill (InflaterInputStream. Java: 240)
The at Java. Util. Zip. InflaterInputStream. Read (158) InflaterInputStream. Java:
The at Java. IO. BufferedInputStream. The fill (BufferedInputStream. Java: 235)
The at Java. IO. BufferedInputStream. Read1 (BufferedInputStream. Java: 275)
The at Java. IO. BufferedInputStream. Read (BufferedInputStream. Java: 334)
The at Java. IO. A DataInputStream. ReadFully (195). A DataInputStream Java:
At com. Sun. Imageio. Plugins. PNG. PNGImageReader. DecodePass (PNGImageReader. Java: 1092)
At com. Sun. Imageio. Plugins. PNG. PNGImageReader. DecodeImage (PNGImageReader. Java: 1196)
At com. Sun. Imageio. Plugins. PNG. PNGImageReader. ReadImage (PNGImageReader. Java: 1301)
. Six more
Java. Lang. IllegalArgumentException: Destination image width must not be less than or equal to 0 pixels.
At net. Coobird. Thumbnailator. Thumbnails. ValidateDimensions (Thumbnails. Java: 147)
At net. Coobird. Thumbnailator. Thumbnails. Access $0 (Thumbnails. Java: 134)
At net. Coobird. Thumbnailator. Thumbnails $Builder. The size (885) Thumbnails. Java:
. Ats com. The onion. The health system. The article. The service. The impl. ArticleFileServiceImpl. Main (ArticleFileServiceImpl. Java: 292)
CodePudding user response:
This kind of circumstance how to obtain correct height to width picture?