Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #29076
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2014-07-12 13:49 -0700 |
| References | <26a272f4-3e52-439d-9139-f79d739df5e3@r33g2000yqn.googlegroups.com> |
| Message-ID | <ae206f7a-9d4b-44f2-9577-1def95831b53@googlegroups.com> (permalink) |
| Subject | Re: Sepia tone image filter for Java |
| From | jf498989@gmail.com |
On Monday, June 29, 2009 11:03:09 PM UTC-7, Macky G wrote:
> After spending hours searching the web and not finding an answer, I
> finally put together a function to create sepia images with Java.
> This function produces amazing results, I'm very happy with it. I
> hope it saves everyone time...
>
> (You'll need your image to be in a BufferedImage object. The web has
> plenty of tutorials for that.)
>
>
> /**
> *
> * @param img Image to modify
> * @param sepiaIntensity From 0-255, 30 produces nice results
> * @throws Exception
> */
> public static void applySepiaFilter(BufferedImage img, int
> sepiaIntensity) throws Exception
> {
> // Play around with this. 20 works well and was recommended
> // by another developer. 0 produces black/white image
> int sepiaDepth = 20;
>
> int w = img.getWidth();
> int h = img.getHeight();
>
> WritableRaster raster = img.getRaster();
>
> // We need 3 integers (for R,G,B color values) per pixel.
> int[] pixels = new int[w*h*3];
> raster.getPixels(0, 0, w, h, pixels);
>
> // Process 3 ints at a time for each pixel. Each pixel has 3 RGB
> colors in array
> for (int i=0;i<pixels.length; i+=3)
> {
> int r = pixels[i];
> int g = pixels[i+1];
> int b = pixels[i+2];
>
> int gry = (r + g + b) / 3;
> r = g = b = gry;
> r = r + (sepiaDepth * 2);
> g = g + sepiaDepth;
>
> if (r>255) r=255;
> if (g>255) g=255;
> if (b>255) b=255;
>
> // Darken blue color to increase sepia effect
> b-= sepiaIntensity;
>
> // normalize if out of bounds
> if (b<0) b=0;
> if (b>255) b=255;
>
> pixels[i] = r;
> pixels[i+1]= g;
> pixels[i+2] = b;
> }
> raster.setPixels(0, 0, w, h, pixels);
> }
Hi: this code works super good. I have converted it to BBC Bacic for Windows. what is your full name as I like to pass on credit to my group where due.
Thank you John Fortier
Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread
Re: Sepia tone image filter for Java jf498989@gmail.com - 2014-07-12 13:49 -0700
Re: Sepia tone image filter for Java Roedy Green <see_website@mindprod.com.invalid> - 2014-07-14 02:12 -0700
Re: Sepia tone image filter for Java Joerg Meier <joergmmeier@arcor.de> - 2014-07-14 11:24 +0200
Re: Sepia tone image filter for Java Roedy Green <see_website@mindprod.com.invalid> - 2014-07-15 03:59 -0700
Re: Sepia tone image filter for Java Knute Johnson <eternal@knutejohnson.com> - 2014-07-15 10:11 -0700
Re: Sepia tone image filter for Java Knute Johnson <eternal@knutejohnson.com> - 2014-07-15 10:22 -0700
Re: Sepia tone image filter for Java Knute Johnson <eternal@knutejohnson.com> - 2014-07-17 18:53 -0700
Re: Sepia tone image filter for Java Jeff Higgins <jeff@invalid.invalid> - 2014-07-19 08:18 -0400
csiph-web