ImageConsumer: imageComplete(int status) : ImageConsumer « java.awt.image « Java by API

Java by API
1. com.sun.image.codec.jpeg
2. java.applet
3. java.awt
4. java.awt.datatransfer
5. java.awt.dnd
6. java.awt.event
7. java.awt.font
8. java.awt.geom
9. java.awt.image
10. java.awt.print
11. java.beans
12. java.io
13. java.lang
14. java.lang.instrument
15. java.lang.management
16. java.lang.reflect
17. java.math
18. java.net
19. java.nio
20. java.nio.channels
21. java.nio.charset
22. java.rmi.server
23. java.security
24. java.security.cert
25. java.sql
26. java.text
27. java.util
28. java.util.concurrent
29. java.util.logging
30. java.util.prefs
31. java.util.regex
32. java.util.zip
33. javax.accessibility
34. javax.comm
35. javax.naming
36. javax.net
37. javax.net.ssl
38. javax.print
39. javax.servlet
40. javax.servlet.http
41. javax.sql
42. javax.sql.rowset
43. javax.swing
44. javax.swing.border
45. javax.swing.colorchooser
46. javax.swing.event
47. javax.swing.filechooser
48. javax.swing.plaf.basic
49. javax.swing.plaf.metal
50. javax.swing.plaf.synth
51. javax.swing.table
52. javax.swing.text
53. javax.swing.text.html
54. javax.swing.text.html.parser
55. javax.swing.tree
56. javax.swing.undo
57. javax.xml
58. javax.xml.parsers
59. javax.xml.transform
60. javax.xml.transform.dom
61. javax.xml.transform.stream
62. javax.xml.validation
63. javax.xml.xpath
64. org.apache.commons.lang
65. org.apache.commons.lang.builder
66. org.apache.commons.lang.exception
67. org.apache.commons.lang.time
68. org.apache.commons.logging
69. org.apache.commons.math
70. org.eclipse.jface.action
71. org.eclipse.jface.dialogs
72. org.eclipse.jface.operation
73. org.eclipse.jface.viewers
74. org.eclipse.jface.window
75. org.eclipse.jface.wizard
76. org.eclipse.swt
77. org.eclipse.swt.browser
78. org.eclipse.swt.custom
79. org.eclipse.swt.dnd
80. org.eclipse.swt.events
81. org.eclipse.swt.graphics
82. org.eclipse.swt.layout
83. org.eclipse.swt.ole.win32
84. org.eclipse.swt.printing
85. org.eclipse.swt.program
86. org.eclipse.swt.widgets
87. org.w3c.dom
88. org.xml.sax
89. org.xml.sax.helpers
90. sun.audio
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java by API » java.awt.image » ImageConsumer 
ImageConsumer: imageComplete(int status)

// This example is from the book _Java AWT Reference_ by John Zukowski.
// Written by John Zukowski.  Copyright (c) 1997 O'Reilly & Associates.
// You may study, use, modify, and distribute this example for any purpose.
// This example is provided WITHOUT WARRANTY either expressed or
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.ColorModel;
import java.awt.image.FilteredImageSource;
import java.awt.image.ImageConsumer;
import java.awt.image.ImageFilter;
import java.awt.image.ImageProducer;

public class MainClass extends Applet {
  Image i, j;

  public void init() {
    i = getImage(getDocumentBase()"rosey.jpg");
    j = createImage(new FilteredImageSource(i.getSource()new DynamicFilter(2505, Color.yellow)));
  }

  public void paint(Graphics g) {
    g.drawImage(j, 1010this);
  }
}

class DynamicFilter extends ImageFilter {
  Color overlapColor;

  int delay;

  int imageWidth;

  int imageHeight;

  int iterations;

  DynamicFilter(int delay, int iterations, Color color) {
    this.delay = delay;
    this.iterations = iterations;
    overlapColor = color;
  }

  public void setDimensions(int width, int height) {
    imageWidth = width;
    imageHeight = height;
    consumer.setDimensions(width, height);
  }

  public void setHints(int hints) {
    consumer.setHints(ImageConsumer.RANDOMPIXELORDER);
  }

  public void resendTopDownLeftRight(ImageProducer ip) {
  }

  public void imageComplete(int status) {
    if ((status == IMAGEERROR|| (status == IMAGEABORTED)) {
      consumer.imageComplete(status);
      return;
    else {
      int xWidth = imageWidth / iterations;
      if (xWidth <= 0)
        xWidth = 1;
      int newPixels[] new int[xWidth * imageHeight];
      int iColor = overlapColor.getRGB();
      for (int x = 0; x < (xWidth * imageHeight); x++)
        newPixels[x= iColor;
      int t = 0;
      for (; t < (imageWidth - xWidth); t += xWidth) {
        consumer.setPixels(t, 0, xWidth, imageHeight, ColorModel.getRGBdefault(), newPixels, 0,
            xWidth);
        consumer.imageComplete(ImageConsumer.SINGLEFRAMEDONE);
        try {
          Thread.sleep(delay);
        catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
      int left = imageWidth - t;
      if (left > 0) {
        consumer.setPixels(imageWidth - left, 0, left, imageHeight, ColorModel.getRGBdefault(),
            newPixels, 0, xWidth);
        consumer.imageComplete(ImageConsumer.SINGLEFRAMEDONE);
      }
      consumer.imageComplete(STATICIMAGEDONE);
    }
  }
}

           
       
Related examples in the same category
1. ImageObserver.ALLBITS
2. ImageConsumer.IMAGEABORTED
3. ImageConsumer.IMAGEERROR
4. ImageConsumer.SINGLEFRAMEDONE
5. ImageConsumer.STATICIMAGEDONE
6. ImageConsumer: setPixels(int x, int y, int w, int h, ColorModel model, int[] pixels, int off, int scansize)
w_ww___.___j__ava_2s_.co___m___
Home | Contact Us
Copyright 2003 - 07 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.