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 re-reproduced, 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 shows that there is a piece of code (at least for me) that has some weight.


Yesterday, through Photoshop to reverse the image, it does solve the problem, but in the future, the image provided by others can not be old by me to turn,

In addition, when the code is not under my control, but also to explain some of the unwarranted nonsense, attracting unnecessary trouble.

Simply, eliminate the problem in the bud, try to stay away from the whirlpool as well.


A separate function, 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, as long as the scale and translate parameters of the corresponding changes, the current 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;}

The calling method is as follows:

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


Resources:

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/



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.