I wish to have an NSView with one side of it fading out to an alpha of 0.0f. What is the best practice for doing this? This effect is similar to that of feathering a selection in Photoshop or Pixelmator.
Give your view a backing store layer (check out the NSView wantsLayer and layer properties). Make a CAGradientLayer and set its your backing store layer's mask.
The most basic way to do this is to draw a gradient and, in your view's drawRect:, call CGContextClipToMask() to use the gradient image as a mask.
Make a .png image that starts from transparent and fades out to the color that you want to your NSView to fade out to.
Then add an image element that covers all the NSView and display the .png image that you made before.
That should do it.
Related
I am in the process of creating an app where I have a background image (a UIImageView with the frame set to the UIView's bounds and added as a subview).
I would like to now add a UIView that will be over the background image but will apply gaussian blur to the image behind, only over the area where the UIView is.
I have just tried to use GPUImage to create a blur, which looks good but it uses 2 UIImageViews (one large background and one behind the UIView, which is blurred). Unfortunately the image no longer matches up with the background.
Is there any way to get the UIView to blur only the area behind it? A bit like the UIView is frosting the image behind.
Thanks!
Try FXBlurView from here - https://github.com/nicklockwood/FXBlurView
It should work.
I hope that makes sense. I'll try to explain it.
I have a UIImageView on screen, and am wondering how I can take the area after "drawing" on it with a finger, and remove that section from the UImage, or, create a separate UIImage from the selection.
I'm not looking for code (unless you have it =] ), just an idea of how to go about doing it. If you have tips, I'd be very grateful, thanks.
If I understand your question,
I think I would add a transparent UIView as a subview over the top of the UIImageView. And draw on that. Then you can remove/hide the subview when your done.
you need to create a UIGestureRecognizer with target and a action like -imageIsPressed, in this -imagePressed method you can call something to make the image disappear. I would suggest placing the UIImage into a UIImageView and calling imageview.hidden = YES; to hide the image, and set it back to "NO" once its not held by the finger.
You'd need to implement something that captures the area the user 'selected' (maybe be creating a CGPath. Then you create a CALayer of the size of the imageView. In it you create, draw and fill the captured path with some arbitrary color while leaving the rest transparent. Finally you apply your generated CALayer as a mask to the UIImageView:
imageView.layer.mask = maskLayer;
Hope that gets you started.
For more info on how to draw that custom CALayer pls refer to Quartz Programming Guide
So basically you want to implement freehand erasing of an image? You will need to use core graphics and the various CGContext methods (with blend mode set to clear) to achieve this. There are two approaches, but both start with drawing your image as the first part of drawRect, and then
1) Store your strokes in an array, and stroke all of them over top of the image.
2) Stroke one stroke over the image and then store the resulting image into a UIImage. Use this UIImage as the next image that you draw in drawRect. This one is difficult for undo/redo functionality.
I recently implemented this myself and made the source available here. Basically I used the same methods described here with this change when setting up the graphics context:
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear);
I have a custom view for which I've (in the XIB) created a UIImageView as a subview. How can I make the image view appear in the background? (i.e. so that in the custom view I can create the hands of a clock that will appear over the top)
Do I need to make my background image have alpha areas for transparency? (if I have the terms correct) Or is it OK to have an image with it's background just set to white or black or whatever it needs to be (on the basis it will be in the background so this will be ok)
You can't: views are composited on top of their superviews, which means if your custom view is drawing in -drawRect:, it will always appear under the UIImageView.
The easiest way to achieve the effect you're looking for is to put the image view under your custom view in IB.
Background images generally do not need to have transparency (and there's a slight speedup if the PNG has no alpha channel).
An alternate approach to using UIImageView objects if you are drawing the rest of stuff in drawRect: is to use the image directly. Draw the image in drawRect: before you do any of the drawing.
Example
- (void)drawRect:(CGRect)rect {
[backgroundImage drawInRect:rect];
/* Do rest of your drawing */
}
Now this is only if you are using a complex image. If it is a texture, you would rather use UIColor's colorWithPatternImage: method to get a color from the UIImage object and set your custom view's backgroundColor. Remember that using the colorWithPatternImage: will not scale the image while drawing and will tile if the source image is smaller the frame of the view.
I have an image, that has transparent areas and a known backround. But wheh I set "image" property of the UIImage i see main view and not a color which i set in "background" property.
I think I tried that before and found no real solution. You could however put the uiimageview into an uiview with the same size and set the backgroundcolor to this view.
Had to create custom control with two UIImageViews bounded by obu UIView. It works, but i would prefer apple doing something about this behaviour
I have a translucent png image (made by turning down the opacity in Photoshop), and there's a UIImageView behind that translucent image. Is there any way to blur the parts of the UIImageView on the bottom that intersect with the UIImageView on top? Thanks!
Not aware of any code that will do that on its own, but you could 'fake it' by rendering the intersection of the views in a graphics context, then apply a blur effect to it. Then you could take the graphics context and insert a UIImageView with the resulting image in between the two views to simulate the effect. This method would not work very well if you have any sort of animation or otherwise changing the state of the images.
You may try setting alpha of the image to less than 1.