Delphi - floodfill with gradient? - delphi

Is there a way to use Canvas.FloodFill in D2007 to fill a custom shaped object with gradient colors. Going from white to a border color.
I couldn't google out anything useful.
Or just any other way of filling a custom shaped object with gradient colors?
Thank you.

I don't think so.
Floodfill takes uses whatever the current brush color is set to, you can't change it during the flood fill.
You could however use floodfill to set the color to something not already in the image, then loop over the pixels, check for that color of the pixel, and do a gradient fill that way. That would take care of the boundary detection for you.

Have you checked GDI+ already? You can make Shapes (Pathes) and gradient-fill them with GDI+. There are some Delphi-Wrappers around for GDI+ with examples:
Here is a starting point:
http://www.bilsen.com/gdiplus/index.shtml

Related

android: smooth out edges of random shape bitmap

I have an random shape bitmap cut out by user. I want to fade out its borders i.e. contours, so as to make it appear smooth. What should I do? To get the borders and color of every pixel in bitmap, I am traversing it pixel by pixel. It takes long time, still I am ok with it. Is openCV my only option? If yes, can anybody point me towards any tutorial or suggestion for logical approach?
You can just run a smoothing filter on your shape.
In opencv you can use the blur fnnction or gaussainBlur. Look at http://docs.opencv.org/2.4/doc/tutorials/imgproc/gausian_median_blur_bilateral_filter/gausian_median_blur_bilateral_filter.html.
You don't have to use opencv but i think it would be easier and faster.
If you still don't want can use any other code that implement smoothing an image.
In case you just want to effect the border pixels do the following:
Make a copy of the original image
Filter the entire image.
Extract the border pixel using opencv findContours.
Copy from the blurred image only the pixels in the border and in there neighborhood and copy them to the copy you did in step 1.

why resizableImageWithCapInsets's best performance is tiled by 1x1 rather than block by block

UIImage resizableImageWithCapInsets official document description are below.
During scaling or resizing of the image, areas covered by a cap are not scaled or resized. Instead, the pixel area not covered by the cap in each direction is tiled, left-to-right and top-to-bottom, to resize the image. This technique is often used to create variable-width buttons, which retain the same rounded corners but whose center region grows or shrinks as needed. For best performance, use a tiled area that is a 1x1 pixel area in size.
I don't understand why use 1x1 pixel tiled area is the best performance. I think tiled block by block, the performance is better than 1x1 area. In theory, block by block is fast than point by point, is that right? who can told me the implementation of this in machine?
#jhabbott makes a good guess in his comment on the accepted answer to the question How does UIEdgeInsetsMake work?
So, I think if the tiled area is just 1x1 pixel. Then, resizableImageWithCapInsets: can just use that pixel's color as the fill color. That way, it doesn't have to do any tiling at all. So, essentially, it's like setting view.backgroundColor = color. Have you ever written any drawing code? Basically, I think filling an area with a color is easier than tiling that area with a rectangle of pixels, since the latter probably takes more calculations, like where to position the next tile, etc. But, I'm just guessing here. But, if you try to write the drawing code to fill a rect with a color vs to tile a rect of pixels onto another rect, you'll see where I'm coming from.

"shape burst" stroke in iOS Core Graphics

Is there a way to create the following effect in Core Graphics by stroking a CGPathRef?
If it is possible, would it be more efficient to draw with Core Graphics vs. simply drawing a radial ellipse CGImageRef a whole bunch of times along the path?
Edit: to clarify: I want the central part of the stroke to be 100% opacity, and the edges to fade out from 100% opacity to 0% opacity.
Edit 2: also, I intend to use this drawing in an MKOverlayView to highlight a user's path... so not sure if a blur filter would be performant enough.
A round-capped, thick path with a shadow on it is probably the best solution for you. That would involve:
CGContextSetLineWidth()
CGContextSetLineCap()
CGContextSetShadowWithColor()
You'd want a zero offset shadow, and you'll need to experiment with the radius and blur parameters to get the effect you're after.

Fill polygon shape with color in Corona SDK

I need to draw shape filled with special color in Corona SDK.
I'm trying draw vector map, where shapes will be as buildings.
The problem is object retuned by display.newLine() don't have setFillColor() method.
So, vector shape is empty (I see background through it), only stroke color can be changed via line:setColor().
How can I fill polygon shape with color?
Thanks.
There are a few polygon fill algorithms.
Have a read here :
http://alienryderflex.com/polygon_fill/
http://www.siggraph.org/education/materials/HyperGraph/scanline/outprims/polygon6.htm
And there is a nice implementation in Code Exchange!
http://developer.anscamobile.com/code/polygon-fill-and-point-polygon-detection

Intersection Region Color

i have drawn two semitransparent circles which intersect each other. I have found that the intersection region is deeper in color than other regions. is there any way to make the whole shape as one semitransparent color (color shouldn't be deeper in one area than others)?
is it possible to send me any sample code to solve the problem?
right now in the draw method, i am using the following code:
spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
spriteBatch.Draw(textureCircle1, spritePositionCircle1, new Color(255, 255, 255, (int)(150)));
spriteBatch.Draw(textureCircle2, spritePositionCircle2, new Color(255, 255, 255, (int)(150)));
spriteBatch.End();
base.Draw(gameTime);
I'm not an XNA guy, so you might have to do some translation.
Could you perhaps render them off screen on as white on black monochrome, and take the resulting image, make the white the transparent color you want and the black completely transparent?
I'm not sure how you'd code that up, but that's the approach I'd research.
Check the alpha values of the pixels which you think are less transparent (you're drawing these onto their own surface, not directly to the backbuffer, right?). They may just seem less transparent because their combined color is darker.
If they truly are less transparent, change the transparency of every pixel on the surface to the same value (I'm afraid I don't know how to do this in XNA).
If they only seem less transparent, try drawing your sprites onto the surface completely opaquely (so one will completely overwrite the other), then again change the transparency of the surface as a whole.

Resources