9

I'm using libGDX for an android game; as far as I can tell, it doesn't have an API for blurring.

Reading on Wikipedia, it seems like blur is formed by setting each pixels RGB values to the average of all adjacent values. Which doesn't seem easily possible in libGDX -- setting pixel data.

So my question is simple:

Is it possible to fake (a decent) blur using only images?

I can potentially overlay multiple (in number, transparency, type) images; but can I create a convincing blur like this?

I'm tempted to say "no," but maybe someone else has achieved something similar. For clarity, I want a set of 1+ generic images I can render on top of ANY image to generate a blur-like effect.

ashes999
  • 11,261
  • 9
  • 59
  • 95

2 Answers2

7

If you're able to additively blend images and multiply them by a constant while doing so, then you can do a blur. Instead of averaging the pixels in a neighborhood, you'd average several copies of the image displaced by a small number of pixels from each other. Or more generally, you could do a Gaussian blur or whatever kind of blur, by controlling the weights - that is, multiplying each displaced copy of the image by a constant as it's being added onto the rest.

Algorithmically, it would look something like this:

clear output_image to 0
foreach offset, weight in filter_kernel:
    output_image += input_image * weight, shifted by offset

You'd use the same offsets and weights as in the standard way of doing a blur. There are plenty of articles on the Web on how to generate the weights for a Gaussian blur, for instance.

Nathan Reed
  • 33,657
  • 3
  • 90
  • 114
0

Blurring can be an expensive operation, perhaps a different approach could work, e.g.:

  1. Store multiple copies of the image blurred in several different directions (e.g. multiples of 45 degrees), then display the closest matching image at runtime. This will offer the highest performance, at the cost of memory usage.
  2. Scale the image down and then back to full-size with anti-aliasing/smoothing. Often this can be done with graphics hardware with very little performance impact.
Luke Van In
  • 621
  • 4
  • 8
  • It won't work, because it has to be dynamic, i.e. I can't know the exact setup of the screen ahead of time. – ashes999 Oct 20 '11 at 15:43