How to erase line from image (for example CIImage or NSImage or bitmap) by painting it? Just like eraser. I wonder how to do that with Core Graphics?
This is definitely a dupe (I even answered the dupe!) but I cant find it at the moment due to the phone searching being a little fiddly. So, apologies for that, here is the gist of the other answer:
You can do this, assuming your lines are drawn on a separate, equally sized view on top of the image view, by setting the drawing colour to colorWithPatternImage:, using the image view image. Lines drawn with this colour "erase" whatever was previously on the view by effectively drawing small sections of the underlying image on top of your existing drawn lines.
Related
I couldn't find an example of a block of text not rendered to a rectangular area.
Ideally, it would be nice if ID2D1HwndRenderTarget.DrawText() would let me provide a polygon Geometry instead of a rectangle.
I've tried adding a Direct2D Layer with contentBounds, thinking it might skip rendering text within those layers. It didn't work as expected, it just blocked render to the area still emulating text underneath.
I've also tried applying a rectangular area to hwnd window itself. It too blocked render but didn't shift text.
IDWriteTextLayout only supports rectangular layouts, but DirectWrite supports any shape you can think of by using the lower level functions (text analysis, glyph measurement, glyph shaping). It's no easy task to write your own text layout from scratch, but I wrote a Windows 7 SDK sample containing a "FlowLayout" that demonstrates a circle and a few other simple shapes. It doesn't take arbitrary geometry, but you may be able to adapt it to your needs (see FlowLayoutSource::GetNextRect for computing the width of each line).
https://github.com/pauldotknopf/WindowsSDK7-Samples/tree/master/multimedia/DirectWrite/CustomLayout
DirectWrite only supports rectangular layouts, so you can't get anything more complicated automatically. You'll have to implement layout functionality yourself if you want it to work differently. Clipping arguments, like you already observed, have nothing to do with text layout.
Kind of a weird question for you today. I was requested to take a IMAGE like the following (small portion of a rather big diagram)...
And make it into an editable diagram. I was wondering if there was anyway to decompose into PowerPoint shapes to be able to edit the lines, text, color of boxes, etc. The diagram was created in PowerPoint, then was created into a image, while the PowerPoint diagram was deleted.
Thanks for your time!
I had to do this exact thing for another reason. The closest I could get was to import the image into Photoshop or Adobe Acrobat. These programs can detect the text. Sometimes Acrobat detected text better, but to change the shapes it still had to go to Photoshop. Then, I put the text on its own layer. Next, I redrew the shapes on top of the original. Finally, I deleted the original image, leaving me with the text layers on top of the shape layers on top of a background layer(I prefer it to be alpha channel). Then any edits can be made as desired.
I am new in Unity2d creating animation via series of images of the player and images are very clear but when i add them in my animation they are getting distortion.
I am following this tutorial:
http://www.41post.com/4742/programming/unity-animated-texture-from-image-sequence-part-2
and it working perfectly for it's own images, Note: my images has empty spaces (as png pics has) and only that part of the images getting distortion while tutorial images has no empty spaces.
The Print Screen of my problem: Image sample
Didn't went through the entire tutorial line by line. What I suspect though is that you are overlapping your textures by just looking at the screenshot.
Imagine you are drawing pictures on the only piece of paper you have at hand. Suppose there are 1, 2, ..., k images, you draw the first image i1 on the piece of paper. Now, you wanna draw the second one i2. Since you have only one piece of paper, you have to rub away your previous drawing first. Without clearing the drawings on your paper, your new drawings will always overlap the old ones. Unless you are using a new piece of paper everytime, of course.
Back to the question. If the images used in the animation are fully opaque (not even a single pixel), then of course you will not notice the difference even if you draw new paintings over the old ones. But in your case, there are many transparent areas in the images. If the canvas is not cleaned everytime before drawing a new painting, it is obvious that the results will be something similar to what you have in the screenshot.
The images used in the tutorial are fully opaque, I suppose.
I'm looking for some advice on how to proceed.
I'm working on a cocoa program (Objective-C) where I want to be able to draw over top of a bitmap image, defining areas that I can use to get information from the underlying image.
As an example, I'd like to create a box (or oval) and be able to get the average pixel value from the underlying image. Ultimately I want to designate a number of such regions where I am sampling the underlying image to provide various statistics.
Currently I'm using an NSImage class to draw my image but I'm not sure how to go about drawing an NSBezierPath over that image. Would I be better off using something other than NSImage?
Do I simply override the NSImage drawRect method so that it draws a series of NSBezierPath objects?
I would like to be able to save these outlined regions as a layer so that they are available in the future.
You can use a CGBitmapContext (for the bitmap), CGImageMasks (for the masking), and CGPaths or CGContext* drawing primitives for the lines and curves.
A complete answer would be quite long, but that gives you a starting point.
I'm looking to replicate with Cocoa/Core Graphics the process which seems to occur on iOS when setting an image for a UITabBarItem. When the tab bar item is selected, the image is overlayed with a gradient.
For example,
becomes...
I'm unsure exactly what I should be doing to achieve this effect. It seems like the image is masking the gradient. Any pointers in the right direction (or code!) would be much appreciated.
You can use a monochrome CGImage with alpha channel (like most iPhone tool-/tabbar icons) as a mask. Basically, you'd use CGContextClipToMask with your monochrome image. Then you'd draw the gradient which is then clipped to the mask image. You might also want to have a look at the code of UMEKit, which implements this effect on Mac OS X (haven't looked at how exactly they do it, there are probably several ways).