I'm using SkiaSharp to draw text onto a canvas that I've already drawn a background image onto.
It's working fine when just drawing regular text, but I want to add an embossed effect to the text. To do this, I've tried using SKImageFilter.CreateDistantLitDiffuse, which gives the right effect, but the problem is that it fills the background with the light color (also influenced by the diffuse lighting constant). This ends up obliterating my background.
The image below shows the text with the embossed effect, but as you can see, it's background is not transparent. Also, the text should be white, but it's colour has been changed by the filter.
The image filter I'm using is:
fontPaint.ImageFilter = SKImageFilter.CreateDistantLitDiffuse(
new SKPoint3(2, 3, 4),
SKColors.Transparent,
-3,
(float)0.2)
canvas.DrawText(element.Value, coords, fontPaint);
I've seen examples of embossing by drawing the text twice with an offset, but this doesn't give the desired effect.
Any ideas of how I can work-around this issue with the image filter filling in the background?
I managed to get pretty close to what I'm wanting by using CreateMatrixConvolution.
float[] kernel = new float[25]
{
-1, 0, -.5f, 0, 0,
0, -1, -.5f, 0, 0,
-.5f, -.5f, 1.5f, .5f, .5f,
0, 0, .5f, 1, 0,
0, 0, .5f, 0 , 1
};
fontPaint.ImageFilter = SKImageFilter.CreateMatrixConvolution(
new SKSizeI(5,5), kernel, 1f, 1f, new SKPointI(1, 1),
SKMatrixConvolutionTileMode.Clamp, true);
This gives me the following result:
It's not exactly the same as what I was wanting, which is more like this:
But it's pretty close. If anyone has any suggestions on how I can get it closer to the example above, I'd love to hear it. Possibly tweaking the kernel might work, but I've already spent ages playing around with variations.
Related
I just started working on as3. I want to create a Rectangle but without color fill, so I can see what is behind it on stage. I love to draw on that Rectangle, but it never works without color fill.
var Canvas_sp:Sprite = new Sprite();
this.addChild(Canvas_sp);
//here i love Rectangle be without collor fill not whit(FFFFFF)e color
//i love see what behind the Rectangle and draw over it
Canvas_sp.graphics.beginFill(0xFFFFFF);
Canvas_sp.graphics.drawRect(0,0,550,400);
thx for all
If you don't want a fill, don't begin one.
Omit this line:
Canvas_sp.graphics.beginFill(0xFFFFFF);
To achieve the goal you want, you need to set the alpha parameter to 0, and maybe, to draw just a border of a Rectangle. You can see an example here: example
In your case, you can try something like this:
Canvas_sp.graphics.beginFill(0xffffff, 0);
Canvas_sp.graphics.lineStyle(0x000000, 0.1);
Canvas_sp.graphics.drawRect(0, 0, 550, 400);
Canvas_sp.graphics.endFill();
I'm playing with Open Flash Chart. Take a look at this chart:
http://teethgrinder.co.uk/open-flash-chart-2/line-solid-dot.php
As you can see, the rounded dot points look ugly. Some of them are more rounded, some of them less, they don't look the same, as they should. I don't know AS3 and have no idea what is the case. I checked the source code:
this.graphics.lineStyle( 0, 0, 0 );
this.graphics.beginFill( colour, 1 );
this.graphics.drawCircle( 0, 0, style.get('dot-size') );
this.graphics.endFill();
I tried to change the size or draw rectangles instead, but they still don't look the same. I guess the problem is somewhere else...
EDIT: I also noticed, that other elements also looks a little bit different (and they shouldn't) - for example axis ticks. My guess is that it is the quality problem. But when I right-click on the flash object, there is an option "quality" and the "high" is set (there is also a "medium" and a "low" to choose). Can I increase the quality level somewhere else?
From hollow dots, I came to realize there is something around each dot which separated each dot from the connecting lines & also produced blurry hollow dots.
Setting the attribute "halo_size" to 0 helped in this case.
I noticed the same gap in your sold dots examples as well. Maybe that's the problem.
To set stage quality, simply use:
stage.quality = "low";
stage.quality = "medium";
stage.quality = "high";
You may set it in the main class itself which happens to be the document class for this project.
I noticed that if the chart size is 400 x 400 these inconsistencies cease to exist. So the problem we see is a scaling problem & not at the place we think.
Besides, Setting line style allows a proper border around the circle. This will at least appear better.
this.graphics.lineStyle(1, colour, 1);
this.graphics.beginFill( colour, 1 );
this.graphics.drawCircle( 0, 0, style.get('dot-size') );
this.graphics.endFill();
I can't figure how to make drawImage work... It just does nothing (except that it throws an exception with an undefined description) :
layerCtx.globalAlpha = 0,2; // same thing with this line commented
layerCtx.drawImage(cvs, 0 , 0);
I have 2 canvas, one is a layer and the other is for drawing using the mouse. I want to save what the user has drawn on the first canvas to the layer and apply opacity...
I won't give you all the code but you have to know that the following code works :
layerCtx.putImageData(ctx.getImageData(0, 0, 800, 500), 0, 0);
but I can't use opacity with the previous, so as it is advised in other stackoverflow.com related questions, I'd like to use drawImage with a canvas element.
ctx is the context for my canvas cvs,
layerCtx is the context fort my canvas layer
You're gonna hate this: You wrote 0,2 instead of 0.2. That's why it isn't working.
I know a comma is used as a decimal in a lot of European countries, but 0.2 is what its gotta be for this.
Working example to check your code by:
http://jsfiddle.net/zC4Wh/
I'm using the AS3 drawRoundRect function as in the following snippet:
g.lineStyle(1, 0x808080, 1, true);
g.drawRoundRect(0, 0, 100, 24, 12, 12);
As you can see, pixel hinting is on.
The problem I'm having is corners being anti-aliased way too much, they are way too blurry and not even symmetrical on the above snippet. Frankly, the drawRoundRect function draws the ugliest rounded rectangles that I've ever seen.
Is there a way to make AS3 draw more crisp rectangles?
Thanks!
:)
fills are rendered much better than lines. as you can see here:
const thickness:Number = 1;
g.beginFill(0x080808);
g.drawRoundRect(0, 0, 100, 24, 12);
g.drawRoundRect(thickness, thickness, 100 - 2 * thickness, 24 - 2 * thickness, 12 - thickness);
g.endFill();
g.lineStyle(thickness, 0x080808, 1, true);
g.drawRoundRect(0, 50, 100, 24, 12);
well, it is not SOOOOOOOOOOO unincredibly better ... :-S ... but at least its symetric ... and the smudges on the corners are more like little beads ... :-D
greetz
back2dos
I've had similar problems in the past. It usually came down to one of the movieclips along the display path not being on an even pixel. Flash then tries to render fractional pixels, which it can't do, which caused distortion and blurriness.
So, make sure all your movieclips/sprites are on an even pixel (I know you're drawing the rect on even pixels, but if the displayobject it belongs to, or any of its parents aren't on an even pixel, it would be causing the problem).
I've had the same deal, as well. One hacky trick you could try is to apply a minor blur filter to the parenting object.
It looks like you're using the drawRoundRect method of the Graphics class.
If the object you're working with is a UIComponent, you could try using the drawRoundRect method of UIComponent. It takes an Object for the cornerRadius value, rather than setting ellipse width and height values. I'm not 100% sure that the cornerRadius value isn't converted into ellipse width and height, but it seems like it'd be something to try.
Also, you could try the GraphicsUtil class's drawRoundRectComplex. It takes a Number for each corner's radius. Again, not completely sure that it doesn't eventually use the same underlying mechanics as drawRoundRect.
When you using drawRoundRect set X to be half of thickness, and then thickness will be on rounded pixel. In this your case try:
g.lineStyle(1, 0x808080, 1, true);
g.drawRoundRect(0.5, 0.5, 99, 23, 12, 12);
I'm fading out a Bitmap in AS3 by repeatedly applying a ColorTransform every frame to its BitmapData;
_bitmap.colorTransform(_bitmap.rect, new ColorTransform(1, 1, 1, .9, 0, 0, 0, 1));
When applying the apparent reverse to fade it back in I get a discoloured image.
_bitmap.colorTransform(_bitmap.rect, new ColorTransform(1, 1, 1, 1.1, 0, 0, 0, 1));
The problem appears to occur only to fully faded-out images. If I only go part way it is recoverable.
fading out:
(source: ggpht.com)
faded back
(source: ggpht.com)
I would guess that this is due to destructively changing the bitmap data. Try retaining the original data, and applying your transform fresh on every frame, or alternatively wrapping the bitmap in a Sprite and applying the color transform onto that instead.