+ 9

How to make a simple zoom?

Java Script

9th Feb 2017, 8:02 AM
Michael55555
Michael55555 - avatar
5 odpowiedzi
+ 14
transform.scale(2); /* size times 2 */ transform.scale(0.5); /* size divided by 2 */
9th Feb 2017, 10:14 AM
visph
visph - avatar
+ 5
here is a nice implementation to scale a specific area http://stackoverflow.com/questions/3448347/how-to-scale-an-imagedata-in-html-canvas the following function to be exact: function scaleImageData(imageData, scale) { var scaled = ctx.createImageData(imageData.width * scale, imageData.height * scale); var subLine = ctx.createImageData(scale, 1).data for (var row = 0; row < imageData.height; row++) { for (var col = 0; col < imageData.width; col++) { var sourcePixel = imageData.data.subarray( (row * imageData.width + col) * 4, (row * imageData.width + col) * 4 + 4 ); for (var x = 0; x < scale; x++) subLine.set(sourcePixel, x*4) for (var y = 0; y < scale; y++) { var destRow = row * scale + y; var destCol = col * scale; scaled.data.set(subLine, (destRow * scaled.width + destCol) * 4) } } } return scaled; } let say you want to scale a specific area in the canvas: imgData=context.getImageData(x,y,areaWidth,areaHeight); scaledArea=scaledImageData(imgData, 2); context.putImageData(scaledArea,x,y); this will result in the original image with a given area which is now magnified x2 only works as magnifying rectangle tho... i am trying some modifications to make it a circle (magnifying glass) with no much luck yet xD
13th Feb 2017, 10:54 PM
Burey
Burey - avatar
+ 2
uses a magnifier
14th Feb 2017, 4:58 AM
Didi Georgel Danaila
Didi Georgel Danaila - avatar
+ 1
by using transform.scale in css3 you can make zooming in or out.
13th Feb 2017, 1:42 PM
Ayman zein Elbehairy
Ayman zein Elbehairy - avatar
+ 1
use transform.scale(x) css property to enlarge element to x times such as transform.scale(3) means enlarge element three times
14th Feb 2017, 4:33 PM
Nitendra Jangid
Nitendra Jangid - avatar