Get mirrored images in HTML5-resolve texture inversion issues in WebGL

Source: Internet
Author: User

Get mirrored images in HTML5-resolve texture inversion issues in WebGL

The beautiful Life of the Sun Vulcan (http://blog.csdn.net/opengl_es)

This article follows "Attribution-non-commercial use-consistent" authoring public agreement

Reprint Please keep this sentence: Sun Vulcan's Beautiful Life-this blog focuses on Agile development and mobile and IoT device research: IOS, Android, HTML5, Arduino, Pcduino . Otherwise, the article from this blog refused to reprint or reprint. Thank you for your cooperation.



I wait outside the Web front end line, solves this kind of problem, indeed some tricky!

Fortunately, some useful information is available, plus some image processing knowledge accumulated in the previous study of UIKit and Quarzcore and the inversion of images in Opengles in IOS,

The organic combination of this information on the Web gives you a piece of code that has some weight (at least for me) as follows.


Yesterday, after the image was reversed by Photoshop, it did solve the problem. It's just an image from someone else in the future. I can't always turn around,

Other than that. When the code is not under my control. We have to explain some gratuitous nonsense, which leads to unnecessary trouble.

Simply. Eliminate the problem in the bud and try to stay away from the whirlpool as well.


An independent function in which the input parameter is the image before mirroring. The output parameter is the image after mirroring,

This function temporarily only supports horizontal mirroring, vertical mirroring, only the scale and translate of the parameters should be changed, the current demo example is to deal with Y, then the vertical image will be processed by the x-coordinate:

function Mirrorimage (orgimage) {    var imagewidth = orgimage.width;    var imageheight = orgimage.height;    var Tempcanvas = document.createelement (' canvas ');    Tempcanvas.width = ImageWidth;    Tempcanvas.height = ImageHeight;    var context = Tempcanvas.getcontext ("2d");    Context.scale (1,-1);    Context.translate (0,-imageheight);    Context.drawimage (orgimage, 0, 0);    var flipimage = context.getimagedata (0, 0, imagewidth, imageheight);    return flipimage;}

Call methods such as the following:

    var Backwalltex = three. Imageutils.loadtexture (' 2 of the power of the picture. jpg ');    Backwalltex.image = Mirrorimage (backwalltex.image);


References:

http://www.html5canvastutorials.com/advanced/html5-canvas-mirror-transform-tutorial/

Http://www.zeali.net/mirrors/html5canvastutorials/advanced/html5-canvas-transform-scale-tutorial/index.html

http://www.html5canvastutorials.com/advanced/html5-canvas-get-image-data-tutorial/



Get mirrored images in HTML5-resolve texture inversion issues in WebGL

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.