Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to draw a picture with the same scale in java

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how to draw a picture in the same scale in java. I hope you will get something after reading this article. Let's discuss it together.

After getting a picture from the client, I found that the transmitted picture is too large to be displayed in the typeset format, especially when there are a lot of pictures on the page.

When you encounter picture problems, there are the following solutions:

1. Specify (customize) the size of the picture

In this position, the picture is displayed as big as it is.

This situation is simple and easy, but the picture is easily deformed, and the picture is too large, which leads to the slow opening speed of the page.

Second, get the picture size

Because the picture is too large, it should not be displayed in the face where there are too many pictures.

Here is a way to read a large picture and generate a small picture to solve the picture problem.

/ *

* Created on 2004-10-11

*

* TODO To change the template for this generated file go to

* Window-Preferences-Java-Code Style-Code Templates

, /

Package net.jspcn.test

Import java.io.File

Import java.io.FileOutputStream

Import java.awt.Image

Import java.awt.image.BufferedImage

Import com.sun.image.codec.jpeg.JPEGCodec

Import com.sun.image.codec.jpeg.JPEGImageEncoder

Public class JpgTest {

Public void jpgTset () throws Exception {

File _ file = new File ("d:1.jpg"); / / read the file

Image src = javax.imageio.ImageIO.read (_ file); / / construct Image object

Int wideth=src.getWidth (null); / / get the source image width

Int height=src.getHeight (null); / / get the source image length

BufferedImage tag = new BufferedImage (wideth/2,height/2,BufferedImage.TYPE_INT_RGB)

Tag.getGraphics () .drawImage (src,0,0,wideth/2,height/2,null); / / draw a scaled-down picture

FileOutputStream out=new FileOutputStream ("D: ewfile.jpg"); / / output to the file stream

/ / File file = new File ("D: ewFile.jpg")

JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder (out)

/ / JPEGImageEncoder encoder = JPEGCodec.c

Encoder.encode (tag); / / near JPEG coding

Out.close ()

}

Public static void main (String [] args) {

Try {

New JpgTest () .jpgTset ()

} catch (Exception e) {

E.printStackTrace ()

}

}

}

Of course, on this basis, you can write a picture processing program to process your pictures in batches.

After reading this article, I believe you have a certain understanding of "how to draw a picture in the same scale in java". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report