1、Load and Display(加载与显示)

Images can be loaded and displayed to the screen at their actual size or any other size.

图像可以按照其实际尺寸或任何其他尺寸加载并显示到屏幕。
PImage img;  // Declare variable "a" of type PImage

void setup() {
size(640, 360);
// The image file must be in the data folder of the current sketch
//图片文件必须在当前草稿文件的同一文件夹才能加载成功。
// to load successfully
img = loadImage("moonwalk.jpg"); // Load the image into the program
} void draw() {
// 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 size
image(img, 0, height/2, img.width/2, img.height/2);
}

2、Background Image. (背景图片)

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

此示例介绍将加载背景图像的最快方法转换到Processing。 要加载图像作为背景,它必须与程序的宽度和高度相同。

PImage bg;
int y; void setup() {
size(640, 360);
// The background image must be the same size as the parameters
// into the size() method. In this program, the size of the image
// is 640 x 360 pixels.
bg = loadImage("moonwalk.jpg");
} void draw() {
background(bg); stroke(226, 204, 0);
line(0, y, width, y); y++;
if (y > height) {
y = 0;
}
}

3、透明度。

向左移动,指针对面的形象改变立场。本方案通过用色调()函数修改图像的α值覆盖在另一个图象。

PImage img;
float offset = 0;
float easing = 0.05; void setup() {
size(640, 360);
img = loadImage("moonwalk.jpg"); // Load an image into the program
} void draw() {
image(img, 0, 0); // Display at full opacity
float dx = (mouseX-img.width/2) - offset;
offset += dx * easing;
tint(255, 127); // Display at half opacity
image(img, offset, 0);
}

4、遮罩

为图像加载“遮罩”以指定图像不同部分的透明度。 使用Image的mask()方法将两个图像混合在一起。

PImage img;
PImage imgMask; void setup() {
size(640, 360);
img = loadImage("moonwalk.jpg");
imgMask = loadImage("mask.jpg");
img.mask(imgMask);
imageMode(CENTER);
} void draw() {
background(0, 102, 153);
image(img, width/2, height/2);
image(img, mouseX, mouseY);
}

5、创建图像。

createImage()函数提供了一个新的像素的缓冲区。 此示例创建图像渐变。

PImage img;

void setup() {
size(640, 360);
img = createImage(230, 230, ARGB);
for(int i = 0; i < img.pixels.length; i++) {
float a = map(i, 0, img.pixels.length, 255, 0);
img.pixels[i] = color(0, 153, 204, a);
}
} void draw() {
background(0);
image(img, 90, 80);
image(img, mouseX-img.width/2, mouseY-img.height/2);
}

6、点画

鼠标水平位置控制点的大小。 使用根据图像中的像素着色的椭圆创建简单的点画效果。

PImage img;
int smallPoint, largePoint; void setup() {
size(640, 360);
img = loadImage("moonwalk.jpg");
smallPoint = 4;
largePoint = 40;
imageMode(CENTER);
noStroke();
background(255);
} void draw() {
float pointillize = map(mouseX, 0, width, smallPoint, largePoint);
int x = int(random(img.width));
int y = int(random(img.height));
color pix = img.get(x, y);
fill(pix, 128);
ellipse(x, y, pointillize, pointillize);
}

7、请求图像由Ira Greenberg(从为Flash开发人员处理)。

展示如何使用requestImage()函数与preloader动画。 requestImage()函数在单独的线程上加载图像,以使草图在加载时不会冻结。 当你加载大图片时,它非常有用。这些图像是小的快速下载,但尝试应该大的图像,以获得完整的效果。

int imgCount = 12;
PImage[] imgs = new PImage[imgCount];
float imgW; // Keeps track of loaded images (true or false)
boolean[] loadStates = new boolean[imgCount]; // For loading animation
float loaderX, loaderY, theta; void setup() {
size(640, 360);
imgW = width/imgCount; // Load images asynchronously
for (int i = 0; i < imgCount; i++){
imgs[i] = requestImage("PT_anim"+nf(i, 4)+".gif");
}
} void draw(){
background(0); // Start loading animation
runLoaderAni(); for (int i = 0; i < imgs.length; i++){
// Check if individual images are fully loaded
if ((imgs[i].width != 0) && (imgs[i].width != -1)){
// As images are loaded set true in boolean array
loadStates[i] = true;
}
}
// When all images are loaded draw them to the screen
if (checkLoadStates()){
drawImages();
}
} void drawImages() {
int y = (height - imgs[0].height) / 2;
for (int i = 0; i < imgs.length; i++){
image(imgs[i], width/imgs.length*i, y, imgs[i].height, imgs[i].height);
}
} // Loading animation
void runLoaderAni(){
// Only run when images are 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 are loaded - no false values left in array
boolean checkLoadStates(){
for (int i = 0; i < imgs.length; i++){
if (loadStates[i] == false){
return false;
}
}
return true;
}

processing学习整理---Image的更多相关文章

  1. processing学习整理---Structure

    1.语法介绍:与java很相近,可以认为就是java. 2.运行命令(linux): processing-java --output=/tmp/processing-xx --run --force ...

  2. processing学习整理---Input(输入)

    1.鼠标1D. 左右移动鼠标可移动天平. “mouseX”变量用于控制矩形的大小和颜色. void setup(){ size(640,360); noStroke(); colorMode(RGB, ...

  3. dataTables 插件学习整理

    在项目中使用了dataTables 插件,学习整理一下. dataTables 的官方中文网站 http://www.datatables.club 引入文件: 所有的都要引入 jq文件 1. dat ...

  4. js数组学习整理

    原文地址:js数组学习整理 常用的js数组操作方法及原理 1.声明数组的方式 var colors = new Array();//空的数组 var colors = new Array(3); // ...

  5. TweenMax学习整理--特有属性

    TweenMax学习整理--特有属性   构造函数:TweenMax(target:Object, duration:Number, vars:Object) target:Object -- 需要缓 ...

  6. HttpClient学习整理

    HttpClient简介HttpClient 功能介绍    1. 读取网页(HTTP/HTTPS)内容    2.使用POST方式提交数据(httpClient3)    3. 处理页面重定向    ...

  7. !!对python列表学习整理列表及数组详细介绍

    1.Python的数组分三种类型:(详细见 http://blog.sina.com.cn/s/blog_6b783cbd0100q2ba.html) (1) list 普通的链表,初始化后可以通过特 ...

  8. Java设计模式(学习整理)---命令模式

    设计模式之Command(学习整理) 1.Command定义 不少Command模式的代码都是针对图形界面的,它实际就是菜单命令,我们在一个下拉菜单选择一个命令时,然后会执行一些动作. 将这些命令封装 ...

  9. Wix学习整理(5)——安装时填写注册表

    原文:Wix学习整理(5)--安装时填写注册表 一 Microsoft操作系统的注册表 什么是注册表? 注册表是Mircrosoft Windows中的一个重要的数据库,用于存储系统和应用程序的设置信 ...

随机推荐

  1. easyui datagrid加载数据的两种方式

    1.加载本地数据 var obj = {"total":2,"rows":[{id:"1",name:"一"},{id: ...

  2. HTML5新增的语义标签和IE版本低的兼容性问题

    <!DOCTYPE html><html> <head> <!-- HTML5中浏览器兼容(较低版本的IE浏览器不支持H5的布局):需要在<head&g ...

  3. CodeIgniter框架——CI中视图路径问题

    答: 视图中的所有路径全部和 index.php 同级,也就是和 index.php 属于一个目录下,也就是网站根目录. 因为 index.php 后面看似是路径的东西其实那只是一种 URL 参数而已 ...

  4. vue之v-bind:style

    <div class="collect" @click="collected=!collected"> <i class="fa f ...

  5. django database relations

    注意Django的生成的默认api from django.db import models class Place(models.Model): ''' pass class Restaurant( ...

  6. if you have content fetched asynchronously on pages where SEO is important, SSR might be necessary

    if you have content fetched asynchronously on pages where SEO is important, SSR might be necessary

  7. 【转】IBM PowerVM虚拟化技术笔记

    1. 从CPU虚拟化的角度, 分区(partition)可以分成两大类:Micro-partition和Dedicated-procesor.前者可以将物理处理器以0.01的 粒度分配给微分区,分区创 ...

  8. Spring学习笔记1—依赖注入(构造器注入、set注入和注解注入)

    什么是依赖注入 在以前的java开发中,某个类中需要依赖其它类的方法时,通常是new一个依赖类再调用类实例的方法,这种方法耦合度太高并且不容易测试,spring提出了依赖注入的思想,即依赖类不由程序员 ...

  9. ACM解题之(ZOJ 1094) Matrix Chain Multiplication

    题目来源: 点击打开链接 题目翻译: 矩阵乘法问题是动态规划的典型例子. 假设你必须评估一个表达式,如A * B * C * D * E,其中A,B,C,D和E是矩阵.由于矩阵乘法是关联的,乘法运算的 ...

  10. cqlsh script

    1.time类型 cqlsh> COPY my_keyspace.typetest from STDIN;Using 1 child processes Starting copy of my_ ...