Use Java to teach you how to take a screenshot

Source: Internet
Author: User

First of all, this problem has plagued me for a long time. It is actually quite simple for me to find a way.

Let's talk a little bit about it. Let's see how I got down to this monster...

First, use a jquery plug-in, jcrop. Use this tool to capture the desired image size.

Then submit the size of the object, that is, the coordinates.

For example, the following code: <form action = "/browsing/privacy. do? Method = dos "method =" Post "name =" formsa ">
<Input type = "hidden" size = "4" id = "X" name = "X"/>
<Input type = "hidden" size = "4" id = "Y" name = "Y"/>
<Input type = "hidden" size = "4" id = "W" name = "W"/>
<Input type = "hidden" size = "4" id = "H" name = "H"/>
</Form>

Here, we recorded four coordinates to capture the coordinate data of the image height, width, and XY. If you use images instead of the input file field button for aesthetic purposes, there is a difficulty here. How can we solve this problem. The solution is to use <a hidefocus = "true" class = "addfilea" href = "javascript: void (0)">
<Input hidefocus = "true" class = "addfilei" type = "file" id = "Files" name = "file" size = "1" onchange = "formsubmit () "/> </a>

Then define the style. addfilea {position: relative; cursor: hand; text-Decoration: none; Background-image: URL ('/browsing/PIC/sctx02.gif'); width: 20px; Height: 30px}
. Addfilei {cursor: hand; position: relative; left: 0px; width: pixel PX; Height: 30; Background-color: Blue; opacity: 0; filter: alpha (opacity = 0); Height: 30px}

This method can be used to implement the image submission file domain. (Why? For security reasons, JavaScript cannot be used to submit file domains)

After the image is intercepted, the coordinates are settled. Now, how can we use Java code to intercept images.

See the following code: String x = request. getparameter ("X ");
String y = request. getparameter ("Y ");
String W = request. getparameter ("W ");
String H = request. getparameter ("H ");
String images = request. getparameter ("imagesload ");
Actionforward forwrad = new actionforward ();
User user = (User) request. getsession (). getattribute ("user "));
Browsinguser = browsinguserdao. Load (user. getdataid ());
Systemparameter = (systemparameter) request. getsession (). getservletcontext (). getattribute ("systemparameter ");
String imagesurl = systemparameter. getfileurlname () + file. Separator + images;
Images = images. Replace ("/", file. separator );
Operateimage image = new operateimage (integer. parseint (x), integer. parseint (Y), integer. parseint (W), integer. parseint (h ));
Image. setsrcpath (systemparameter. getfliepath () + file. Separator + "touxiang" + file. Separator + User. GetUserName () + file. Separator + images );
Image. setsrcpath (systemparameter. getfliepath () + images );
Images = This. returnstring (systemparameter. getfliepath () + images );
Image. setsubpath (images );
Image. Cut ();

Then the image is captured, and the path of the image is images.

Then you can use the images path to display the captured image.

Contact TZ

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.