Flutter - Hard color stop in linear gradient - flutter

I'm using CustomPaint to make a custom shape and I want to apply a color gradient but with hard color stops. Without color transitions.
PS:I cannot use different Paints instead of gradient because of the custom shape.
I checked the documentation and couldn't find anything. Is it impossible? Or is there any other workarounds? Thanks!

You could split your custom shape in smaller shapes and give each one its correct color. That would be one way to do it.

I have another idea. You could do it like so: Give the complete canvas of you custom paint a color, the color of your application's background. Give your custom shape Colors.transparent as its color. Then you make as many containers with the colors you want to have and put them below each other so that there overall size matches the size of your custom paint. You stack the custom paint onto these containers using Stack Widget and your custom shape will take the colors of these containers because its color is transparent. While the surrounding of your custom shape will have the color of the background of your application, because the whole custom paint is colored that way.

Okay I figured it out myself, I use Gradient.linear as the shader for custom paint. I noticed that it only blends colors when there is a big gap in stops. So I put my colors and stops like this.
Colors | Stop
Green 0.2
Green 0.201
Blue 0.5
Blue 0.501
Yellow 1
Now the color stops are hard.
Here's a preview of before and after |

Related

Broken outline image in Unity

I want to put an outline around images but on some of the images the outline is broken. Notice the corners in the attached image.
I'm using 5 as the X and Y on the outline. In addition if I use a color besides black, the outline seems to be trying to blend. For example if I set the color to EEC209FF. See 2nd image.
So, i'm trying to explain both of your questions:
Why is the outline shape broken?
That’s the way the default Unity Outline script works: It just draws your UI.Image 4 time with the defined offset behind your image, it 4 different directions, which is cheap performance trick that fits most needs, but obviously not yours.
You can take a look at the Outline script on bitbucket here.
Why is the outline color partially yellow?
Unitys Outline Script draws your image in the background and multiplies the color values with your custom color.
That’s why the white part of your image on the upper right edge become yellow in the outline (almost the color you definied EEC209FF).
The outline on the lower right stays greens since it the take the colors from your image edge, approximately 19B754 multiplied with EEC209 to 178B03, which is a slightly dark green.

How to add a debossed effect to text in a highly textured image using CG-methods in Swift

I have to write some text on a custom CGRect with a highly textured in a CGContext.
This has work for dark and for light images. The texture has to be visible at the debossed letters.
Current approach
calculate avg. color of background image
darken (related to the luminance) the color
CGRect.drawText... with the ID with color of 2.
add a darker ouster shadow to text
add a light inner shadow to text
done.
Problem
My current approach works for dark, slightly textured backgrounds but it does not work for dark strong textured backgrounds.
Example usecase
Render license plates with an embossed ID for a car app.
or
Dog tags (see wikimedia)
It was a rough play with background color of the material, background color of the embossed thing and 4 different shadows.
All in all I have (sorry for that) no 'how to do it' solution. Thanks for your help.

Iphone Set background image into text in uitextView?/

I have a uiimageView containing the text like this.
I want to set the image background of the text to look like this instead.
Please help me! Thanks!
You will need to combine an image of the text with the background image (the stuff that is supposed to fill the inside of the text) using compositing. Take a look at the various blend modes you can use, or look into the use of CIFilter.
http://developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CGContext/Reference/reference.html#//apple_ref/doc/c_ref/CGBlendMode
https://developer.apple.com/library/mac/#documentation/graphicsimaging/Reference/CoreImageFilterReference/Reference/reference.html
The thing in the background looks like it might be a gradient. Again, you can use a CIFilter to generate that gradient, or you can use Core Graphics. So you'll composite the drawn text with its fill image, then you'll draw that over a gradient.
instead of text in black solid color, make image with transparent text and outer region as the grey gradient you want and put this image over you background image, you will get the desired result.

how to fill color in image in particular area?

I want to fill the color in white area for Paint based application so please give me suggestion for how to do this work.
GPUImage is what you need there is a bunch of filters. In principle you need to point ios that it needs to change all whitecolors RGB(255.0,255.0,255.0) to some other color.

Coloring Image in iPhone SDK

i am developing a iphone app. i have a background image lets say an airplane with black color out lines and from color palette user can pick a color and fill the region of airplane....any help, code , suggestion will highly be appriciated
A simple fill algorithm should do. just expand from the point you are on until you meet region end pixels
see http://en.wikipedia.org/wiki/Flood_fill you can also try googling for Boundary Fill algorithm
My first though was to have a UIView and a mask image on top of that with the plane but this only works in certain situations. If the shape of the plane does not change you could also change the color and then "fill" the plan in during the drawRect using functions like CGContextAddArc and CGContextAddRect.