简体   繁体   English

从单点拉伸/扭曲背景图像

[英]Stretching/distorting a background image from a single point

Usually when an image is being resized in javascript or css3(using background-size), it will stretch an image from the center point. 通常,当使用javascript或css3(使用background-size)调整图片大小时,它将从中心点拉伸图片。 I need an image to be stretched and distorted from a single point that could be anywhere. 我需要从可能在任何地方的单个点拉伸和扭曲图像。 It's going to be dynamic so I don't want to resort to using separate images. 这将是动态的,所以我不想诉诸使用单独的图像。

Here's a pic that illustrates what I mean: 这是一张图片,说明了我的意思:
在此处输入图片说明

Hopefully there's an answer out there! 希望那里有一个答案!

You have a few options to achieve this effect. 您可以选择几种方法来达到这种效果。

The "correct" way would be to use canvas to draw the image: Skewing images individually using canvas “正确”的方法是使用画布绘制图像: 使用画布分别倾斜图像

Another way would be to fake the effect using the CSS transform skew. 另一种方法是使用CSS转换倾斜来伪造效果。 http://developerdrive.com/demo/skewing_elements/skewing_elements.html http://developerdrive.com/demo/skewing_elements/skewing_elements.html

You would do this inside an element with "overflow: hidden" to make it look like a background image. 您可以在具有“溢出:隐藏”的元素内执行此操作,以使其看起来像背景图像。

It's not even clear to me what you want from the image you're linking too. 我也不清楚您要链接的图像中想要什么。 Do you want it distorted or not? 您是否希望它失真? And is the distortion uniform? 失真是否均匀?

I'm going to guess whatever you're doing can be approximated by drawing an ever decreasing set of (or maybe rectangles) clipped from the center of a some image and drawing them onto a "canvas" (think generic term not html5 term) given new coordinates for the center of each clipping. 我将猜测您正在做什么,可以通过绘制从某个图像中心截取的一组不断减少的(或矩形)集合并将它们绘制到“画布”上来进行近似(认为通用术语不是html5术语)给定每个裁剪中心的新坐标。 There may be a faster way to draw this than redrawing parts of the image multiple times, it's just how I visualize it possibly working.. at least maybe in some mathematical sense. 绘制此图像的方法可能比多次重绘图像的部分更快,这只是我如何可视化它的工作方式。至少在某种数学意义上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM