Processing learn to organize---Image

Source: Internet
Author: User

 

1. Load and display (loading and displaying)

Images can loaded and displayed to the screens at their actual a size or any other size.

The image can be loaded and displayed to the screen according to its actual size or any other size.
Pimage img;//Declare variable "a" of type PimagevoidSetup () {Size (640, 360); //The image file must is in the Data folder of the current sketch//The picture file must be in the same folder in the current draft file to load successfully. //To load successfullyimg = LoadImage ("moonwalk.jpg");//Load the image into the program}voidDraw () {//displays the image at its actual size at point (0,0)Image (IMG, 0, 0); //Displays the image at point (0, HEIGHT/2) at half of its sizeImage (IMG, 0, HEIGHT/2, IMG.WIDTH/2, IMG.HEIGHT/2);}
View Code

2,Background image. (background image)


This example presents the fastest-to-load a background image into processing. To load an image as the background, it must is the same width and height as the program.

This example shows the fastest way to load a background image into processing. To load an image as a background, it must be the same width and height as the program.

pimage BG;inty;voidSetup () {Size (640, 360); //The background image must be the same size as the parameters//Into the size () method. In the the the size of the image//is 640 x pixels.BG = LoadImage ("Moonwalk.jpg");}voidDraw () {background (BG); Stroke (226, 204, 0); Line (0, y, width, y); Y++; if(Y >height) {y= 0; }}
View Code

3, transparency.

Moving to the left, the image opposite the pointer changes position. This scheme overwrites the alpha value of the image with the hue () function to cover the other images.

pimage img;floatOffset = 0;floateasing = 0.05;voidSetup () {Size (640, 360); IMG= LoadImage ("moonwalk.jpg");//Load An image to the program}voidDraw () {Image (IMG,0, 0);//Display at full opacity  floatDX = (MOUSEX-IMG.WIDTH/2)-offset; Offset+ = DX *easing; Tint (255, 127);//Display at half opacityImage (IMG, offset, 0);}
View Code

4. Masking

Loads a matte for the image to specify the transparency of the different parts of the image. Use the Mask () method of image to blend two images together.

pimage img; Pimage Imgmask; void Setup () {  size (640);   = LoadImage ("moonwalk.jpg");   = LoadImage ("mask.jpg");  Img.mask (imgmask);  Imagemode (CENTER);} void Draw () {  background (0, 102, 153);  Image (IMG, Width/2, HEIGHT/2);  Image (IMG, mousex, mousey);}
View Code

5. Create an image.

The CreateImage () function provides a new pixel buffer. This example creates an image gradient.

pimage img; void Setup () {  size (640);     = CreateImage (n, v, ARGB);    for (int i = 0; i < img.pixels.length; i++) {    float a = map (i, 0, Img.pixels.length, 25 5, 0);     = Color (0, 153, 204, a);}   } void Draw () {  background (0);   (a);  Image (IMG, mousex-img.width/2, MOUSEY-IMG.HEIGHT/2);}
View Code

6, dot painting

The size of the mouse horizontal position control point. Creates a simple pip effect using an ellipse that is shaded based on the pixels in the image.

pimage img;intSmallpoint, Largepoint;voidSetup () {Size (640, 360); IMG= LoadImage ("Moonwalk.jpg"); Smallpoint= 4; Largepoint= 40;  Imagemode (CENTER);  Nostroke (); Background (255);}voidDraw () {floatPointillize = map (mousex, 0, Width, smallpoint, largepoint); intx =int(Random (img.width)); inty =int(Random (img.height)); Color pix=img.get (x, y); Fill (pix,128); Ellipse (x, Y, pointillize, pointillize);}
View Code

7. The request image is Greenberg by IRA (from the process for flash developers).

Shows how to use the Requestimage () function with Preloader animations. The Requestimage () function loads an image on a separate thread so that the sketch does not freeze when it is loaded. It is very useful when you load a large picture. These images are small and quick to download, but try to get a large image for the full effect.

intImgcount = 12; Pimage[] IMGs=NewPimage[imgcount];floatIMGW;//keeps track of loaded images (true or false)Boolean[] Loadstates =New Boolean[Imgcount];//For loading animationfloatLoaderx, Loadery, Theta;voidSetup () {Size (640, 360); IMGW= width/Imgcount; //Load Images asynchronously   for(inti = 0; i < Imgcount; i++) {Imgs[i]= Requestimage ("Pt_anim" +nf (i, 4) + ". gif"); }}voidDraw () {background (0); //Start Loading AnimationRunloaderani ();  for(inti = 0; i < imgs.length; i++){    //Check If individual images is fully loaded    if((Imgs[i].width! = 0) && (imgs[i].width! =-1)){      //As images is loaded set true in Boolean arrayLoadstates[i] =true; }  }  //When all images is loaded draw them to the screen  if(Checkloadstates ()) {drawimages (); }}voiddrawimages () {inty = (height-imgs[0].height)/2;  for(inti = 0; i < imgs.length; i++) {image (Imgs[i], Width/imgs.length*I, Y, imgs[i].height, imgs[i].height); }}//Loading AnimationvoidRunloaderani () {//Only run when images is loading  if(!checkloadstates ()) {Ellipse (Loaderx, Loadery,10, 10); Loaderx+ = 2; Loadery= Height/2 + sin (theta) * (HEIGHT/8); Theta+ = PI/22; //reposition Ellipse If it goes off the screen    if(Loaderx > Width + 5) {Loaderx=-5; }  }}//Return True when all images is loaded-no false values left in arrayBooleancheckloadstates () { for(inti = 0; i < imgs.length; i++){    if(Loadstates[i] = =false){      return false; }   }  return true;}
View Code

Processing learn to organize---Image

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.