如何使用Processing.js水平翻转图像?

时间:2022-04-16 14:21:49

Not much to add to the question. How do you flip a image horizontally using Processing.js?

没有太多可以添加到这个问题。如何使用Processing.js水平翻转图像?

2 个解决方案

#1


5  

Assuming you've already loaded your img:

假设你已经加载了你的img:

processing.draw = function () {
   // place image
    processing.image(img, 0, 0);

    // flip using a matrix
    processing.pushMatrix();
    processing.scale(-1.0, 1.0)
    processing.image(img, -img.width, 0);
    processing.popMatrix();
};

If needed, it shouldn't be too hard to adjust the arguments to flip the image vertically.

如果需要,调整参数垂直翻转图像应该不会太难。

#2


0  

public PImage getReversePImage( PImage image ) {
 PImage reverse = new PImage( image.width, image.height );
 for( int i=0; i < image.width; i++ ){
   for(int j=0; j < image.height; j++){
     reverse.set( image.width - 1 - i, j, image.get(i, j) );
   }   
 }
 return reverse;
}

From http://uihacker.blogspot.com/2012/04/processing-flip-pimage-horizontally.html

#1


5  

Assuming you've already loaded your img:

假设你已经加载了你的img:

processing.draw = function () {
   // place image
    processing.image(img, 0, 0);

    // flip using a matrix
    processing.pushMatrix();
    processing.scale(-1.0, 1.0)
    processing.image(img, -img.width, 0);
    processing.popMatrix();
};

If needed, it shouldn't be too hard to adjust the arguments to flip the image vertically.

如果需要,调整参数垂直翻转图像应该不会太难。

#2


0  

public PImage getReversePImage( PImage image ) {
 PImage reverse = new PImage( image.width, image.height );
 for( int i=0; i < image.width; i++ ){
   for(int j=0; j < image.height; j++){
     reverse.set( image.width - 1 - i, j, image.get(i, j) );
   }   
 }
 return reverse;
}

From http://uihacker.blogspot.com/2012/04/processing-flip-pimage-horizontally.html