Home Web Front-end H5 Tutorial Html5 Canvas Preliminary Study Notes (12) - Image cropping and adjustment

Html5 Canvas Preliminary Study Notes (12) - Image cropping and adjustment

Feb 28, 2017 pm 04:05 PM

The previous article talked about the two operations of images, reading and exporting. After reading the image, we use drawImage with only three parameters. This article will Introducing 5 parameters and #drawImage of 9 parameters respectively. In fact, The last function is very similar to drawRegion in j2me. First introduce the drawImage function with 5 parameters that can adjust the size of the image.

First look at the following effect:



##The code is as follows:

var image = new Image();
image.src = "grossini.png";
image.onload = function(){
context.drawImage(image,50,50);
context.drawImage(image,100,50,image.width * 1.5,image.height * 1.5);
context.drawImage(image,200,50,image.width * 0.5,image.height * 0.5);
context.drawImage(image,250,50,160,50);
}
Copy after login

In the

onload function of the image, I wrote four drawImage, of which the last three are 5 parameters, the effect is very obvious, one enlarges the picture 1.5 times, and the other reduces the picture to 0.5, there is also an unequal scaling. That is to say, the last two parameters are the width and height of the picture we want to draw. Of course, under normal circumstances, they are just proportional scaling. You can also specify other widths, such as the effect of the last sentence.

Let’s introduce the

drawImage function that can be cut. First, let’s look at the parameter introduction:

drawImage

(picture, picture The starting x coordinates of cropping, the starting y coordinates of cropping in the picture, the width of the cropping area, the height of the cropping area, the drawn Position x coordinates, drawn position y coordinates, drawn graphic width, drawn graphic height)

First look at the following effect:



The code is as follows:

var image = new Image();
image.src = "grossini.png";
image.onload = function(){
context.drawImage(image,50,50);
context.drawImage(image,0,0,image.width,image.height / 3,100,50,image.width * 1.5,image.height * 0.5);
context.drawImage(image,0,image.height / 3,image.width,image.height * 2/ 3,180,50,image.width * 1.5,image.height);
Copy after login

This function is better than the previous one There is an additional cropping function that allows us to crop images arbitrarily. It is often used in this way. The effect is as follows:



##Code As follows:

var test = new Image();
test.src = "test.png";
test.onload = function(){
context.drawImage(test,50,180);
context.drawImage(test,67 * 3,0,67,121,50,280,67,121);
}
Copy after login

This example shows that cutting simple small pictures from a list of large pictures is one of the uses of cutting.

The above is the content of Html5 Canvas Preliminary Study Notes (12) - Image Cutting and Adjustment. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

See all articles