src/share/classes/java/awt/image/BufferedImage.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  59  * coordinate of (0,&nbsp;0).  Any <code>Raster</code> used to construct a
  60  * <code>BufferedImage</code> must therefore have minX=0 and minY=0.
  61  *
  62  * <p>
  63  * This class relies on the data fetching and setting methods
  64  * of <code>Raster</code>,
  65  * and on the color characterization methods of <code>ColorModel</code>.
  66  *
  67  * @see ColorModel
  68  * @see Raster
  69  * @see WritableRaster
  70  */
  71 
  72 public class BufferedImage extends java.awt.Image
  73                            implements WritableRenderedImage, Transparency
  74 {
  75     int        imageType = TYPE_CUSTOM;
  76     ColorModel colorModel;
  77     WritableRaster raster;
  78     OffScreenImageSource osis;
  79     Hashtable properties;
  80 
  81     boolean    isAlphaPremultiplied;// If true, alpha has been premultiplied in
  82     // color channels
  83 
  84     /**
  85      * Image Type Constants
  86      */
  87 
  88     /**
  89      * Image type is not recognized so it must be a customized
  90      * image.  This type is only used as a return value for the getType()
  91      * method.
  92      */
  93     public static final int TYPE_CUSTOM = 0;
  94 
  95     /**
  96      * Represents an image with 8-bit RGB color components packed into
  97      * integer pixels.  The image has a {@link DirectColorModel} without
  98      * alpha.
  99      * When data with non-opaque alpha is stored


1089     }
1090 
1091     /**
1092      * Returns the height of the <code>BufferedImage</code>.
1093      * @param observer ignored
1094      * @return the height of this <code>BufferedImage</code>
1095      */
1096     public int getHeight(ImageObserver observer) {
1097         return raster.getHeight();
1098     }
1099 
1100     /**
1101      * Returns the object that produces the pixels for the image.
1102      * @return the {@link ImageProducer} that is used to produce the
1103      * pixels for this image.
1104      * @see ImageProducer
1105      */
1106     public ImageProducer getSource() {
1107         if (osis == null) {
1108             if (properties == null) {
1109                 properties = new Hashtable();
1110             }
1111             osis = new OffScreenImageSource(this, properties);
1112         }
1113         return osis;
1114     }
1115 
1116 
1117     /**
1118      * Returns a property of the image by name.  Individual property names
1119      * are defined by the various image formats.  If a property is not
1120      * defined for a particular image, this method returns the
1121      * <code>UndefinedProperty</code> field.  If the properties
1122      * for this image are not yet known, then this method returns
1123      * <code>null</code> and the <code>ImageObserver</code> object is
1124      * notified later.  The property name "comment" should be used to
1125      * store an optional comment that can be presented to the user as a
1126      * description of the image, its source, or its author.
1127      * @param name the property name
1128      * @param observer the <code>ImageObserver</code> that receives
1129      *  notification regarding image information


   1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  59  * coordinate of (0,&nbsp;0).  Any <code>Raster</code> used to construct a
  60  * <code>BufferedImage</code> must therefore have minX=0 and minY=0.
  61  *
  62  * <p>
  63  * This class relies on the data fetching and setting methods
  64  * of <code>Raster</code>,
  65  * and on the color characterization methods of <code>ColorModel</code>.
  66  *
  67  * @see ColorModel
  68  * @see Raster
  69  * @see WritableRaster
  70  */
  71 
  72 public class BufferedImage extends java.awt.Image
  73                            implements WritableRenderedImage, Transparency
  74 {
  75     int        imageType = TYPE_CUSTOM;
  76     ColorModel colorModel;
  77     WritableRaster raster;
  78     OffScreenImageSource osis;
  79     Hashtable<?, ?> properties;
  80 
  81     boolean    isAlphaPremultiplied;// If true, alpha has been premultiplied in
  82     // color channels
  83 
  84     /**
  85      * Image Type Constants
  86      */
  87 
  88     /**
  89      * Image type is not recognized so it must be a customized
  90      * image.  This type is only used as a return value for the getType()
  91      * method.
  92      */
  93     public static final int TYPE_CUSTOM = 0;
  94 
  95     /**
  96      * Represents an image with 8-bit RGB color components packed into
  97      * integer pixels.  The image has a {@link DirectColorModel} without
  98      * alpha.
  99      * When data with non-opaque alpha is stored


1089     }
1090 
1091     /**
1092      * Returns the height of the <code>BufferedImage</code>.
1093      * @param observer ignored
1094      * @return the height of this <code>BufferedImage</code>
1095      */
1096     public int getHeight(ImageObserver observer) {
1097         return raster.getHeight();
1098     }
1099 
1100     /**
1101      * Returns the object that produces the pixels for the image.
1102      * @return the {@link ImageProducer} that is used to produce the
1103      * pixels for this image.
1104      * @see ImageProducer
1105      */
1106     public ImageProducer getSource() {
1107         if (osis == null) {
1108             if (properties == null) {
1109                 properties = new Hashtable<>();
1110             }
1111             osis = new OffScreenImageSource(this, properties);
1112         }
1113         return osis;
1114     }
1115 
1116 
1117     /**
1118      * Returns a property of the image by name.  Individual property names
1119      * are defined by the various image formats.  If a property is not
1120      * defined for a particular image, this method returns the
1121      * <code>UndefinedProperty</code> field.  If the properties
1122      * for this image are not yet known, then this method returns
1123      * <code>null</code> and the <code>ImageObserver</code> object is
1124      * notified later.  The property name "comment" should be used to
1125      * store an optional comment that can be presented to the user as a
1126      * description of the image, its source, or its author.
1127      * @param name the property name
1128      * @param observer the <code>ImageObserver</code> that receives
1129      *  notification regarding image information