Java Web Implementation of cutting pictures and uploading complete code

This example shares a complete case of cutting and uploading pictures on Java Web for your reference. The specific contents are as follows

Realization idea

• use the jcrop plug-in phone to cut the coordinates of the picture • transfer the collected parameters to the background, and draw the image with Java graphic object in the background for cutting ◦ background processing flow: 1. Compress the uploaded picture according to the proportion, upload it to the file server, and save the compressed picture in the local temporary directory. 2. Echo the compressed image to the page and use jcrop for clipping. The mobile phone clipping coordinates (x, y, width, height) ■ @ paramx target slice starting point coordinates x ■ @ param y target slice starting point coordinates y ■ @ param width target slice width ■ @ param height target slice height 3. Process clipping in the background and upload again

JSP page

Background java code

Picture upload tool class

Picture clipping tool class

Summary of problems encountered:

-Solution to the offset phenomenon of cropped picture: collect the cropped coordinate information by using the equal proportion of the compressed picture - the mutual transformation between multipartfile and file

The first method:

A file will be generated in the temporary folder of the root directory of the project;

The second method:

transferTo(File dest);

A new file will be generated in the project;

The third method:

File f = (file) XXX strong rotation is enough. The precondition is to configure multipartresolver, otherwise the exception of type conversion failure will be reported.   

Never tried;

The fourth method:

Workbook wb = Workbook. getWorkbook(xxx .getInputStream());

Convert to input stream and read directly;

The fifth method:

byte[] buffer = myfile. getBytes();

First convert to byte array, never tried;

The sixth method:

Direct to input stream

Reference: jcop API: http://code.Ciaoca.com/jquery/jcrop/.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>