Open GoogleCodeExporter opened 9 years ago
Hi,
Another example script for clipping that does not work :
---8<------8<------8<------8<------8<------8<------8<------8<------8<------8<---
var ctx = elem.getContext('2d');
var drawPath = function(x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6)
{
ctx.moveTo(x1, y1);
ctx.lineTo(x2, y2);
ctx.lineTo(x3, y3);
ctx.lineTo(x4, y4);
ctx.lineTo(x5, y5);
ctx.lineTo(x6, y6);
ctx.lineTo(x1, y1);
}
var drawTexture = function(x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6,
source, l,
t, w, h)
{
var img = new Image();
var onImageLoad = function()
{
ctx.save();
ctx.beginPath();
drawPath(x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6);
ctx.clip();
ctx.drawImage(img, l, t, w, h);
ctx.restore();
};
img.onload = onImageLoad;
img.src = source;
}
drawCase(283,314,326,314,348,353,326,392,283,392,261,353, '#00FE00',
'Images/Textures/grass_40.png', 261.5, 314, 87, 78);
---8<------8<------8<------8<------8<------8<------8<------8<------8<------8<---
An hexagon is filled using a backcolor, and a texture is drawn clipped in the
same
hexagon.
Color filling is good, but clipping on image does not work : image left part is
not
clipped, but right part is clipped.
Same code works fine in Firefox.
Original comment by maitred...@gmail.com
on 14 Sep 2009 at 7:55
[deleted comment]
Screenshots :
Same code rendered on IE and FireFox.
Left image is generated server-side (asp.net C#)
Right image is Canvas. Magenta background is not drawn.
Original comment by maitred...@gmail.com
on 14 Sep 2009 at 8:05
Attachments:
Hello, as already said in another issue report, the clip function does NOT work
with IE
+ ExCanvas, even with the latest revision. There are a few workarounds, but
they don't
really work.
Original comment by fabien.menager
on 14 Sep 2009 at 8:43
Hi,
Thanks for your precision.
What about clipping implementation in silverlight excanvas ?
Is it still in a "TODO" stub, or someone has started working on it ?
Original comment by maitred...@gmail.com
on 16 Sep 2009 at 8:00
For Silverlight clipping,
can someone say if this XAML code is correct :
<Canvas Width="300" Height="300" Clip="M108,200 L129,200 L139,221 L129,242
L108,242
L97,221 z">
</Canvas>
So adding clipping show not be too hard : Elements are added to "current
clipping
canvas".
Let think about a possible behavior :
- I draw elements -> drawn to root.
- I save context.
- I create a path (beginPath, move, line, line... close).
- I "clip" -> new clipping canvas is created.
- I draw elements -> rendered elements are children of "clipping canvas"
- I restore context.
- I draw elements -> drawn to root
Any feeling about this ?
Original comment by maitred...@gmail.com
on 16 Sep 2009 at 1:30
This may work, if SL is better than VML (what I really hope). I wanted to use
this kind
of method for VML, and really thought it would work, but this doesn't :(
I cannot test it at the moment, but you could with a really minimal example,
with a few
shapes.
Original comment by fabien.menager
on 16 Sep 2009 at 2:12
I have made a small try to add clipping to silverlight excanvas.
Seems to work well.
Here are the diff file and screenshot.
Left is Firefox 3.5, right is IE 8.
Left image is rendered server-side, right image is generated client-side
(javascript
+ canvas).
Before this code, images would have corners out of their area.
Original comment by maitred...@gmail.com
on 16 Sep 2009 at 3:44
Attachments:
Nice, maitredede.
Do you mind signing the CLA so I can apply your patch?
http://code.google.com/legal/individual-cla-v1.0.html
Original comment by erik.arv...@gmail.com
on 19 Sep 2009 at 6:26
Excellent patch. I would also very much like that patch to be committed to
Excanvas.
Original comment by andre...@pvv.ntnu.no
on 26 Sep 2009 at 10:46
Would it be possible to use the similar logic for image clipping using
drawImage()?
Original comment by andre...@pvv.ntnu.no
on 26 Sep 2009 at 11:30
Hi,
My patch is made for silverlight version of excanvas. Clipping is done for each
elements drawn after the "clip" function, including images.
You can give it a try ;)
Original comment by maitred...@gmail.com
on 27 Sep 2009 at 7:36
I've given it a try, and it works nicely. Would it be possible to get this
patch
ported to the VML version of excanvas, so that image clipping would work for
more users?
Original comment by andre...@pvv.ntnu.no
on 4 Oct 2009 at 9:58
Original issue reported on code.google.com by
poweroft...@gmail.com
on 10 Jun 2009 at 4:44