# Image() is slow, are there any alternatives?

**URL:** <https://discourse.processing.org/t/image-is-slow-are-there-any-alternatives/20146>\
**Category:** Coding Questions\
**Created:** [April 25, 2020, 7:51pm UTC](https://discourse.processing.org/t/image-is-slow-are-there-any-alternatives/20146 "2020-04-25T19:51:09Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [April 28, 2020, 10:00am UTC](https://discourse.processing.org/t/image-is-slow-are-there-any-alternatives/20146/21 "2020-04-28T10:00:50Z")

</div>

> [@KevinWho](#):
>
> what is the nine argument version?

It’s in my post! It’s also here - [PGraphics](https://processing.github.io/processing-javadocs/core/processing/core/PGraphics.html#image-processing.core.PImage-float-float-float-float-int-int-int-int-) For some reason not included on the Processing `image()` docs page.

> [@KevinWho](#):
>
> The text is blurry, buttons are blurry, even some images look blurry.

Possibly due to differences in scaling algorithm - have a look at different settings of `smooth()` - [smooth() / Reference / Processing.org](https://processing.org/reference/smooth_.html)

---

<div class="post-metadata">

**Author:** ![behreajj](https://avatars.discourse-cdn.com/v4/letter/b/b5a626/32.png) [@behreajj](https://discourse.processing.org/u/behreajj)\
**Post date:** [April 28, 2020, 11:36am UTC](https://discourse.processing.org/t/image-is-slow-are-there-any-alternatives/20146/22 "2020-04-28T11:36:08Z")

</div>

Hi @KevinWho,

As far as appearance goes, I usually set the `textureSampling` of the `P2D` renderer. I don’t know if it’s in the documentation, so I usually look [here](https://github.com/processing/processing/blob/8e86389c7e017d0e4d61f81fb942c25e3ed348c7/core/src/processing/opengl/Texture.java#L54). You can also look at rendering [hint](https://processing.org/reference/hint_.html)s. Here’s an example of working with pixel art.

 ![exmpl](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/6/670a91c9bb337ff8b05a639f0438598f48b3bd53.png)

```auto
import processing.opengl.*;

int point = 2;
int linear = 3;
int bilinear = 4;
int trilinear = 5;

PImage img;

void setup() {
  size(512, 512, P2D);
  PGraphicsOpenGL rndr = (PGraphicsOpenGL)getGraphics();
  rndr.textureSampling(point);
  rndr.hint(DISABLE_TEXTURE_MIPMAPS);

  // 256 x 128
  img = loadImage("https://upload.wikimedia.org/wikipedia/" + 
     "commons/e/e9/2xsai_example.png");
}

void draw() {
  image(img, 0, 0, width, height); // replace with 9 param
}

```

So a single renderer gives you improved frame rate, but a buffer does not?

Best,  
Jeremy

---

<div class="post-metadata">

**Author:** ![KevinWho](https://avatars.discourse-cdn.com/v4/letter/k/dbc845/32.png) [@KevinWho](https://discourse.processing.org/u/KevinWho)\
**Post date:** [April 28, 2020, 5:08pm UTC](https://discourse.processing.org/t/image-is-slow-are-there-any-alternatives/20146/23 "2020-04-28T17:08:49Z")

</div>

I am not exactly sure what you are asking, but it does seem that if I set the size() to  
size(800,800,P2D); instead of size(800,800); it runs faster (about 2 times faster). also the code that you gave me there, I tried adapting it and it says that these give nullpointers. ` rndr.textureSampling(point); rndr.hint(DISABLE_TEXTURE_MIPMAPS);` not sure what they do.  
what does this stuff below do?

```auto
  PGraphicsOpenGL rndr = (PGraphicsOpenGL)getGraphics();
  rndr.textureSampling(point);
  rndr.hint(DISABLE_TEXTURE_MIPMAPS);

```

also after adding that to my code, and messing with some settings in size(), a lot of things are giving errors even after I deleted them. I’m getting nullpoints, and a few divbyzero errors, that don’t make sense. all I did was put size(800, 800, OPENGL); and all this happened, I have since put it back to how it was, and after restarted processing, I still get the same errors.

I keep getting that its returning null with this one function:

```auto
PImage animateOffset(PImage[] imgs, int speed, int offset) {
  int returnNumb = ((millis() + offset) / speed) % imgs.length;
  return imgs[returnNumb];
}

```

It has always worked, and no speed is not 0, and imgs has stuff in it.  
Even this print statement is giving me crashing and giving me nulls now.

```auto
  println(returnNumb, imgs.length);

```

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/a60df73e663fac7b21573ff01720033c0aa22429.png)

I am confused why when I did nothing, and then came back to the program an hour later it worked with no changes, when before it would crash every time it ran.

---

<div class="post-metadata">

**Author:** ![behreajj](https://avatars.discourse-cdn.com/v4/letter/b/b5a626/32.png) [@behreajj](https://discourse.processing.org/u/behreajj)\
**Post date:** [April 28, 2020, 7:49pm UTC](https://discourse.processing.org/t/image-is-slow-are-there-any-alternatives/20146/24 "2020-04-28T19:49:58Z")

</div>

Hi @KevinWho,

It is difficult to address these issues with the screenshots and code snippets you have provided. In the mean time, general advice:

1. When you encounter a red band error which stops your program, but you feel it hasn’t given you enough information, click on the bug in the upper right hand corner, to the left of the label that says “Java”. This will make the error message more informative, although more overwhelming. There is a video by Dan Shiffman about debugging in Processing.

https://player.vimeo.com/video/140134398

1. Try to strip away complexity when you encounter a problem. Simplify. Open a new Processing sketch and type in code that is new to you until you feel you understand it; then integrate it into a complex project.

2. Keep a separate copy of a complex project that is known to be working; work on a separate experimental copy. A more systematic, though complicated to learn, process for doing this is called source control.

Many of the questions you’ve raised are related to fundamental programming concepts. I’ll rephrase them as I interpret them. Try searching on Processing for the answers, and/or on the web; they will give you better answers than I can. First, it might help you to organize your questions into a numbered list according to priority.

- What is a graphics renderer?
- What is the difference between a primitive and an object?
- How does inheritance work in object oriented programming?
- What is OpenGL?
- What is a pointer?
- How does pass by reference vs. pass by value work?
- What is mutability?
- What is a mip-map?
- How does a renderer sample a texture?

Feel free to correct me if I’ve misinterpreted the topics you’ve raised. You may know a lot about some of these topics in isolation, for example, I’m sure you’ve defined a class before, but even so, research might help you turn islands into peninsulas into continents. Making video games is hard, even in a dedicated game engine, which Processing is not.

Best,  
Jeremy

---

<div class="post-metadata">

**Author:** ![KevinWho](https://avatars.discourse-cdn.com/v4/letter/k/dbc845/32.png) [@KevinWho](https://discourse.processing.org/u/KevinWho)\
**Post date:** [April 28, 2020, 7:51pm UTC](https://discourse.processing.org/t/image-is-slow-are-there-any-alternatives/20146/25 "2020-04-28T19:51:18Z")

</div>

ok, I will take a look at that when I have time. For now my error is gone, so ill do that if it comes back.

[Previous page](https://discourse.processing.org/t/image-is-slow-are-there-any-alternatives/20146.md?page=1)
