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); }
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); }
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); }
public override void setPaint(java.awt.Paint paint) { if (paint is java.awt.Color) { setColor((java.awt.Color)paint); return; } if (paint == null || this.javaPaint == paint) { return; } this.javaPaint = paint; if (paint is java.awt.GradientPaint) { java.awt.GradientPaint gradient = (java.awt.GradientPaint)paint; LinearGradientBrush linear; if (gradient.isCyclic()) { linear = new LinearGradientBrush( J2C.ConvertPoint(gradient.getPoint1()), J2C.ConvertPoint(gradient.getPoint2()), J2C.ConvertColor(gradient.getColor1()), J2C.ConvertColor(gradient.getColor2())); } else { //HACK because .NET does not support continue gradient like Java else Tile Gradient //that we receize the rectangle very large (factor z) and set 4 color values // a exact solution will calculate the size of the Graphics with the current transform Color color1 = J2C.ConvertColor(gradient.getColor1()); Color color2 = J2C.ConvertColor(gradient.getColor2()); float x1 = (float)gradient.getPoint1().getX(); float x2 = (float)gradient.getPoint2().getX(); float y1 = (float)gradient.getPoint1().getY(); float y2 = (float)gradient.getPoint2().getY(); float diffX = x2 - x1; float diffY = y2 - y1; const float z = 60; //HACK zoom factor, with a larger factor .NET will make the gradient wider. linear = new LinearGradientBrush( new PointF(x1 - z * diffX, y1 - z * diffY), new PointF(x2 + z * diffX, y2 + z * diffY), color1, color1); ColorBlend colorBlend = new ColorBlend(4); Color[] colors = colorBlend.Colors; colors[0] = colors[1] = color1; colors[2] = colors[3] = color2; float[] positions = colorBlend.Positions; positions[1] = z / (2 * z + 1); positions[2] = (z + 1) / (2 * z + 1); positions[3] = 1.0f; linear.InterpolationColors = colorBlend; } linear.WrapMode = WrapMode.TileFlipXY; brush = linear; pen.Brush = brush; return; } if (paint is java.awt.TexturePaint) { java.awt.TexturePaint texture = (java.awt.TexturePaint)paint; brush = new TextureBrush( J2C.ConvertImage(texture.getImage()), J2C.ConvertRect(texture.getAnchorRect())); pen.Brush = brush; return; } throw new NotImplementedException("setPaint(" + paint.GetType().FullName + ")"); }