Beispiel #1
0
 internal static Bitmap ConvertImage(java.awt.Image img)
 {
     if (img is BufferedImage)
     {
         return(((BufferedImage)img).getBitmap());
     }
     if (img is NetVolatileImage)
     {
         return(((NetVolatileImage)img).bitmap);
     }
     if (img is sun.awt.image.ToolkitImage)
     {
         sun.awt.image.ImageRepresentation ir = ((sun.awt.image.ToolkitImage)img).getImageRep();
         // start the production and wait if not produce the image
         lock ( ir ) {
             ir.prepare(null);
             while (ir.getBufferedImage() == null)
             {
                 ir.wait();
             }
         }
         return(ir.getBufferedImage().getBitmap());
     }
     if (img is NoImage)
     {
         return(null);
     }
     Console.WriteLine(new System.Diagnostics.StackTrace());
     throw new NotImplementedException("Image class:" + img.GetType().FullName);
 }
Beispiel #2
0
        public override bool drawImage(java.awt.Image img, java.awt.geom.AffineTransform xform, ImageObserver observer)
        {
            if (img == null)
            {
                return(true);
            }

            if (xform == null || xform.isIdentity())
            {
                return(drawImage(img, 0, 0, null, observer));
            }

            throw new NotImplementedException("drawImage(Image,AffineTransform,ImageObserver) not implemented for non-null or non-identity AffineTransform!");
        }
Beispiel #3
0
        public override bool drawImage(java.awt.Image img, int x, int y, java.awt.image.ImageObserver observer)
        {
            Image image = J2C.ConvertImage(img);

            if (image == null)
            {
                return(false);
            }
            lock (image)
            {
                g.DrawImage(image, x, y);
            }
            return(true);
        }
Beispiel #4
0
        public override bool drawImage(java.awt.Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, java.awt.image.ImageObserver observer)
        {
            Image image = J2C.ConvertImage(img);

            if (image == null)
            {
                return(false);
            }
            Rectangle destRect = new Rectangle(dx1, dy1, dx2 - dx1, dy2 - dy1);
            Rectangle srcRect  = new Rectangle(sx1, sy1, sx2 - sx1, sy2 - sy1);

            lock (image)
            {
                g.DrawImage(image, destRect, srcRect, GraphicsUnit.Pixel);
            }
            return(true);
        }
Beispiel #5
0
        public override bool drawImage(java.awt.Image img, int x, int y, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)
        {
            Image image = J2C.ConvertImage(img);

            if (image == null)
            {
                return(false);
            }
            using (Brush brush = J2C.CreateBrush(bgcolor))
            {
                g.FillRectangle(brush, x, y, image.Width, image.Height);
            }
            lock (image)
            {
                g.DrawImage(image, x, y);
            }
            return(true);
        }
Beispiel #6
0
 internal static Bitmap ConvertImage(java.awt.Image img)
 {
     if (img is BufferedImage)
     {
         return(((BufferedImage)img).getBitmap());
     }
     if (img is NetVolatileImage)
     {
         return(((NetVolatileImage)img).bitmap);
     }
     if (img is sun.awt.image.ToolkitImage)
     {
         return(((sun.awt.image.ToolkitImage)img).getImageRep().getBitmap());
     }
     if (img is NoImage)
     {
         return(null);
     }
     Console.WriteLine(new System.Diagnostics.StackTrace());
     throw new NotImplementedException("Image class:" + img.GetType().FullName);
 }
Beispiel #7
0
        /// <summary>
        /// 指定したフォントを描画するとき、描画指定したy座標と、描かれる文字の中心線のズレを調べます
        /// </summary>
        /// <param name="font"></param>
        /// <returns></returns>
        public static int getStringDrawOffset(java.awt.Font font)
        {
            int ret = 0;

            java.awt.Dimension size = measureString(PANGRAM, font);
            if (size.height <= 0)
            {
                return(0);
            }
            java.awt.Image      b  = null;
            java.awt.Graphics2D g  = null;
            BitmapEx            b2 = null;

            try {
                int string_desty = size.height * 2; // 文字列が書き込まれるy座標
                int w            = size.width * 4;
                int h            = size.height * 4;
                b       = new java.awt.Image();
                b.image = new System.Drawing.Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                g       = new java.awt.Graphics2D(System.Drawing.Graphics.FromImage(b.image));
                g.setColor(java.awt.Color.white);
                g.fillRect(0, 0, w, h);
                g.setFont(font);
                g.setColor(java.awt.Color.black);
                g.drawString(PANGRAM, size.width, string_desty);

                b2 = new BitmapEx(b.image);
                // 上端に最初に現れる色つきピクセルを探す
                int  firsty = 0;
                bool found  = false;
                for (int y = 0; y < h; y++)
                {
                    for (int x = 0; x < w; x++)
                    {
                        java.awt.Color c = new cadencii.java.awt.Color(b2.GetPixel(x, y));
                        if (c.getRed() != 255 || c.getGreen() != 255 || c.getBlue() != 255)
                        {
                            found  = true;
                            firsty = y;
                            break;
                        }
                    }
                    if (found)
                    {
                        break;
                    }
                }

                // 下端
                int endy = h - 1;
                found = false;
                for (int y = h - 1; y >= 0; y--)
                {
                    for (int x = 0; x < w; x++)
                    {
                        java.awt.Color c = new cadencii.java.awt.Color(b2.GetPixel(x, y));
                        if (c.getRed() != 255 || c.getGreen() != 255 || c.getBlue() != 255)
                        {
                            found = true;
                            endy  = y;
                            break;
                        }
                    }
                    if (found)
                    {
                        break;
                    }
                }

                int center = (firsty + endy) / 2;
                ret = center - string_desty;
            } catch (Exception ex) {
                serr.println("Util#getStringDrawOffset; ex=" + ex);
            } finally {
                if (b != null && b.image != null)
                {
                    b.image.Dispose();
                }
                if (g != null)
                {
                    g.nativeGraphics.Dispose();
                }
                if (b2 != null && b2 != null)
                {
                    b2.Dispose();
                }
            }
            return(ret);
        }