Example #1
0
        /// <summary>
        /// Returns a <seealso cref="BufferedImage"/> with a data layout and color model
        /// compatible with this <code>GraphicsConfiguration</code>.  This
        /// method has nothing to do with memory-mapping
        /// a device.  The returned <code>BufferedImage</code> has
        /// a layout and color model that is closest to this native device
        /// configuration and can therefore be optimally blitted to this
        /// device. </summary>
        /// <param name="width"> the width of the returned <code>BufferedImage</code> </param>
        /// <param name="height"> the height of the returned <code>BufferedImage</code> </param>
        /// <returns> a <code>BufferedImage</code> whose data layout and color
        /// model is compatible with this <code>GraphicsConfiguration</code>. </returns>
        public virtual BufferedImage CreateCompatibleImage(int width, int height)
        {
            ColorModel     model  = ColorModel;
            WritableRaster raster = model.CreateCompatibleWritableRaster(width, height);

            return(new BufferedImage(model, raster, model.AlphaPremultiplied, null));
        }
 internal static WritableRaster MakeRaster(ColorModel cm, Raster srcRas, int w, int h)
 {
     lock (typeof(TexturePaintContext))
     {
         if (Xrgbmodel == cm)
         {
             if (XrgbRasRef != null)
             {
                 WritableRaster wr = (WritableRaster)XrgbRasRef.get();
                 if (wr != null && wr.Width >= w && wr.Height >= h)
                 {
                     XrgbRasRef = null;
                     return(wr);
                 }
             }
             // If we are going to cache this Raster, make it non-tiny
             if (w <= 32 && h <= 32)
             {
                 w = h = 32;
             }
         }
         else if (Argbmodel == cm)
         {
             if (ArgbRasRef != null)
             {
                 WritableRaster wr = (WritableRaster)ArgbRasRef.get();
                 if (wr != null && wr.Width >= w && wr.Height >= h)
                 {
                     ArgbRasRef = null;
                     return(wr);
                 }
             }
             // If we are going to cache this Raster, make it non-tiny
             if (w <= 32 && h <= 32)
             {
                 w = h = 32;
             }
         }
         if (srcRas != null)
         {
             return(srcRas.CreateCompatibleWritableRaster(w, h));
         }
         else
         {
             return(cm.CreateCompatibleWritableRaster(w, h));
         }
     }
 }
Example #3
0
        /// <summary>
        /// Returns a <code>BufferedImage</code> that supports the specified
        /// transparency and has a data layout and color model
        /// compatible with this <code>GraphicsConfiguration</code>.  This
        /// method has nothing to do with memory-mapping
        /// a device. The returned <code>BufferedImage</code> has a layout and
        /// color model that can be optimally blitted to a device
        /// with this <code>GraphicsConfiguration</code>. </summary>
        /// <param name="width"> the width of the returned <code>BufferedImage</code> </param>
        /// <param name="height"> the height of the returned <code>BufferedImage</code> </param>
        /// <param name="transparency"> the specified transparency mode </param>
        /// <returns> a <code>BufferedImage</code> whose data layout and color
        /// model is compatible with this <code>GraphicsConfiguration</code>
        /// and also supports the specified transparency. </returns>
        /// <exception cref="IllegalArgumentException"> if the transparency is not a valid value </exception>
        /// <seealso cref= Transparency#OPAQUE </seealso>
        /// <seealso cref= Transparency#BITMASK </seealso>
        /// <seealso cref= Transparency#TRANSLUCENT </seealso>
        public virtual BufferedImage CreateCompatibleImage(int width, int height, int transparency)
        {
            if (ColorModel.Transparency == transparency)
            {
                return(CreateCompatibleImage(width, height));
            }

            ColorModel cm = GetColorModel(transparency);

            if (cm == null)
            {
                throw new IllegalArgumentException("Unknown transparency: " + transparency);
            }
            WritableRaster wr = cm.CreateCompatibleWritableRaster(width, height);

            return(new BufferedImage(cm, wr, cm.AlphaPremultiplied, null));
        }
 internal static Raster GetCachedRaster(ColorModel cm, int w, int h)
 {
     lock (typeof(GradientPaintContext))
     {
         if (cm == CachedModel)
         {
             if (Cached != null)
             {
                 Raster ras = (Raster)Cached.get();
                 if (ras != null && ras.Width >= w && ras.Height >= h)
                 {
                     Cached = null;
                     return(ras);
                 }
             }
         }
         return(cm.CreateCompatibleWritableRaster(w, h));
     }
 }