I have a small question.
I am making a painting/drawing app for the iPhone. In my app you can draw on backgrounds and photo's. But i can't find the solution for a eraser. Because most of the eraser samples are white colored paint. So on a non-white background it is just making white "lines". Any solutions for a (sort of) transparant eraser that will erase only draw "lines" and not the background?
Thnx for your help!
Instead of drawing using a blend mode of kCGBlendModeNormal with a white coloured paint, you will want to draw using a kCGBlendModeDestinationOut when the eraser is on. (This assumes the background is in a layer behind the drawing layer.)
For example:
<pre>
if (eraser == TRUE) // Erase to show background
{
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeDestinationOut);
}
else // Draw with color
{
CGContextSetBlendMode(UIGraphicsGetCurrentContext(),kCGBlendModeNormal);
}
</pre>
You might also like to view this CGBlendMode reference that shows the effect of different blend types including explanations, originally posted at: http://ericasadun.com/CookbookTest/Blending.pdf
Alternative link to document: http://www.docdroid.net/xt0b/blending-kcgblendmode.pdf.html
Related
I'm working on a report project and would like to avoid making a separate image for each indicator color. Ideally, I like to put a transparent circle in a white rectangle. I have Snag-It available and general Windows tools.
My plan is to put the Image in a table cell and change the color of the circle by dynamically assigning the background color of the cell. I think it would be much easier to embed this one image, rather than creating a bunch of different colored circles that all have to be embedded.
Any suggestions on how I can do this in Snag-It or Paint, or any tools that are free for commercial use that you can recommended for this?
This sounds like a good workaround to get an indicator with whatever color you want.
Paint.net is a free image editor that you could create this in. Start with a white square. Use the Ellipse Select tool to select a circle in the middle. Press the Delete key to make it transparent. Save it as a .PNG file and embed it in the report.
I've been trying to find some info on how to fix this, but I'm clearly typing the wrong stuff into google.
Basically imagine you have canvas in Photoshop.
You press the brush tool to paint a horizontal red line with your Wacom pen.
But instead of painting a red horizontal line, the screen pans to the right.
No red line, just moved the slider over to see the right of the screen.
I don't want that. I want to paint. I don't want to move the slider.
Also - every time I hold down the pen, a little dialog pops up that lets me change the brush settings. I don't want that either. If I hold the pen harder on the tablet, I'm trying to push down to make the stroke thicker. But instead of a thicker stroke, I get brush settings.
WTF Wacom?
Last Windows update caused this. Here's how to fix this: https://forums.adobe.com/thread/2398372
I was on the way of making a picasa like photo viewer and later an image editor.i used JFrame and alpha channel to set background transparent.but while moving or zooming in/out ,as i had to draw it on different location and clear the previous image i used clearRect and faced the problem.
the oracle documentation says it clears the rect and restores the background color.
on some trials the clearRect clears the area to background color.But while continuous events like mouse-dragging its turning the color of cleared area to black and causing this:
`
thnx
.i used JFrame and alpha channel to set background transparent.
Don't use alpha for complete transparency. Instead just use:
panel.setOpaque( false );
If you are using semi transparency then check out Backgrounds With Transparency. It will explain the problems with transparent background and provide a couple of solutions.
The basic problem is that transparency breaks the painting contract with Swing components because the background is not cleared entirely before child components are painted.
I am trying to build a windows phone live tile. I want some text on the tile that is the accent colour. What this means is that I need to draw some text on the tile that is transparent. I don't seem to be able to write in the transparent colour.
I have a User Control which is 173 by 173 pixels which I save as a png file. I use this png as the image for the live tile. The transparent bits of the image come out in the current accent colour.
Any ideas how to write in the transparent colour in xaml?
This behaviour is to be expected. In your original question you are effectively saying "Write invisible text on top of the image", and that's what you're getting (imagine writing in invisible ink on a photograph). You effectively need to do one of two things.
1) Figure out which pixels are part of the text you're writing, and "remove" them from the image so the background colour shows through, or
2) Write text in the background colour ({StaticResource PhoneAccentBrush})
EDIT
You can probably achieve what you need using an Opacity Mask. Apologies for only providing that as a link as I haven't done this myself.
What i need is a bit difficult to explain. Let's try...
I need to write a text in my app, and that text will gradually change color from left to right.
I think i could say it's a similar effect to what you see in a karaoke screen.
For instance. I draw a text line, in blue color, and gradually, using a timer, the color from left to right changes to red. But i don't want it to change letter by letter, but gradually. That would require that at some moment, the same letter can have a part in red and a part in blue.
I've been reading about core drawing, and maybe it's the solution, but i really don't know how to start. I was thinking about using a background layer and in top of it draw a transparent text (only with border), but i am not very sure how to do it.
any ideas would be appreciated.
You can probably do the job with a CGLayer.
Best of all you should be able to use your existing code to draw the characters (or anything else) in to the CGLayer.
Here's some rough code:
// first, make a CGLayer...
CGLayerRef yourDrawingPad =
CGLayerCreateWithContext(UIGraphicsGetCurrentContext(),etc..
CGContextRef yourRef = CGLayerGetContext(yourDrawingPad);
// now, draw to yourRef .. draw your various typography (or anything)
// use your current drawing code.
// all done drawing, now make an image mask...
UIGraphicsBeginImageContext(CGLayerGetSize(yourDrawingPad));
CGContextRef temp = UIGraphicsGetCurrentContext();
CGContextDrawLayerAtPoint(temp, CGPointZero, yourDrawingPad);
CGImageRef anAlphaMask = CGBitmapContextCreateImage(temp);
UIGraphicsEndImageContext();
You now have a nice mask you can use:
CGContextSaveGState(UIGraphicsGetCurrentContext()) ...
CGContextClipToMask(UIGraphicsGetCurrentContext(), self.frame, anAlphaMask);
So just mask it in to an image of a gradient, or whatever works.
(Conceivably: perhaps you will have to construct a bitmap image offscreen, and then use that as the mask?)
Footnote: Don't forget it is very likely you will have to paint upside down! Fortunately that is simple to deal with. Where it says "now, draw to yourRef" before drawing save your state and add the two lines of code:
CGContextTranslateCTM(refForMask, 0, self.frame.size.height);
CGContextScaleCTM(refForMask, 1.0, -1.0);
Hope it helps
I have an idea of how this could be done, but it is kind of complex. You could create an NSBezierPath and add the glyphs for each character. Then, set that as the clip and draw a NSGradient. Then you would just have to change the offset of the colors in the NSGradient to move the color along.