I have a CIImage and I am trying to draw lines on mouse drag along the path. Can I do that ?
I am building an app for mac, and I am new to Core Image.
You need create a graphics context first and then retrieve your image from that. Here's a link that will answer your question. It's for the iPhone but Mac and iPhone are very similar.
How to create a UIImage from the current graphics context?
Related
I need to create a very simple image cropping interface for an OS X cocoa application, but I am not sure where to start. The user needs to be able to choose a crop size from a menu of presets, be presented with a cropping rectangle that can be resized preserving the ratio, and moved around the image until they finally apply the selected crop to the image.
I've done some searching for sample code and projects but not found anything too useful. Core Image fun house has some pointers but is a retired sample. There are lots of iOS examples, but I've not found an easy to follow Mac OS example.
Can someone point me in the right direction (or at a sample project or framework!!).
Thanks a lot.
Here is a project you can look at:
https://github.com/foundry/drawingtest
It's a little demo I made as I was trying to understand the relationship between the rects in this method:
- (void)drawInRect:(NSRect)dstRect
fromRect:(NSRect)srcRect
operation:(NSCompositingOperation)op
fraction:(CGFloat)delta
Note that the older compositeToPoint: methods are deprecated and should not be used for this sort of thing.
srcRect is the portion of the original image (in it's own coordinates) that you want to keep.
dstRect is the rect that you want that cropped area to draw into.
JMRect in the project is an NSObject representation of an NSRect - so that we can use cocoa bindings to tie the interface controls together.
For your UI, the cropping rectangle could just be a transparent subview view with a border that you push around and resize over the image you want to crop.
This is by no means a complete solution to your question, but it's something you can poke around with - it might help you to get started.
I am developing a iOS7 video recording application. The camera screen in our application requires to show a blurred backgound similar to the one shown in iOS7 control Center. While the video preview is being shown, we need to show the blurred control center.
As suggested in WWDC video 226, I have used the code provided below to get camera preview snapshot and then applying blur and setting this blurred image to my view.
UIGraphicsBeginImageContextWithOptions(_camerapreview.frame.size, NULL, 0);
[_camerapreview drawViewHierarchyInRect:rect];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lightImage = [newImage applyLightEffect]
Here _camerapreview is a UIView which contains AVCaptureVideoPreviewLayer. The *newImage obtained from the context is for some reason black.
However if i use [_camerapreview snapshotView] returns me a UIview with previewlayer content. But there is no way to apply blur on UIview.
How can I get a blurred image from the camera preview layer?
I would suggest that you put your overlay onto the video preview itself as a composited video layer, and add a blur filter to that. (Check the WWDC AVFoundation sessions and the AVSimpleEditoriOS sample code for compositing images onto video) That way you're staying on the GPU instead of doing readbacks from GPU->CPU, which is slow. Then drop your overlay's UI elements on top of the video preview within a clear background UIView.
That should provide greater performance. As good as Apple? Well, they are using some private stuff developers don't yet have access to...
Quoting Apple from this Technical Q&A:
A: Starting from iOS 7, the UIView class provides a method
-drawViewHierarchyInRect:afterScreenUpdates:, which lets you render a snapshot of the complete view hierarchy as visible onscreen into a
bitmap context. On iOS 6 and earlier, how to capture a view's drawing
contents depends on the underlying drawing technique. This new method
-drawViewHierarchyInRect:afterScreenUpdates: enables you to capture the contents of the receiver view and its subviews to an image
regardless of the drawing techniques (for example UIKit, Quartz,
OpenGL ES, SpriteKit, AV Foundation, etc) in which the views are
rendered
In my experience regarding AVFoundation is not like that, if you use that method on view that host a preview layer you will only obtain the content of the view without the image of the preview layer. Using the -snapshotViewAfterScreenUpdates: will return a UIView that host a special layer. If you try to make an image from that view you won't see nothing.
The only solution I know are AVCaptureVideoDataOutput and AVCaptureStillImageOutput. Each one has its own limit. The first one can't work simultaneously with a AVCaptureMovieFileOutput acquisition, the latter makes the shutter noice.
In some applications like Sparrow Mail are set two different application icons. The default icon used in dock, in icon view e cover flow. Then a second smaller for list view, column view and title bar. How do you set the icon smaller? In file.plist there is only this.
Thanks.
Xcode includes the Icon Composer.app application which allows you to create .icns (Icon Suite) files which support multiple resolutions like shown in the following image:
As you can see in the image above, the Get Info panel’s “proxy” icon (in the titlebar) is using the small 16 x 16 icon, while the lower icon is using one of the larger sizes. If you are used to the single-size-only ways of UIImage, how an NSImage works in OS X may be confusing at first. In iOS, a UIImage represents a single bitmap image, and is basically a wrapper around a CoreGraphics CGImageRef. An NSImage in OS X works at a higher level, and as such, is quite different than a UIImage. An NSImage contains one or more specifically-sized NSImageReps, which are more analogous to a UIImage. In the screenshot you provided, both the window title bar button’s image and the NSImageView’s image are set to the same instance of an NSImage. When that image is asked to draw itself, however, the image is choosing 2 different NSImageReps based on the size requested. For more information on how this works, see Cocoa Drawing Guide: Image Basics - How an Image Representation is Chosen.
If you’re using the all-in-one Xcode.app app bundle, launch Xcode and choose Xcode > Open Developer Tool > Icon Composer. If you’re using the older style of the Xcode tools, with multiple folders, it’ll be at <Developer Tools>/Applications/Utilities/Icon Composer.app.
I am fairly new in iOS programming and I am creating my first app.
I have been trying to use the following code to change the navigation bar background image (this is using the new iOS 5 method):
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"gradientBackgroundPlain.png"] forBarMetrics: UIBarMetricsDefault];
It works fine, but my image is 640 x 88 and it looks too big for the bar. It's like the system doesn't want to scale it, or do I need to do it manually? If I scale the image and create a smaller one it looks pixelated in the retina display.
Any thoughts on this?
Any help or response will be appreciated.
Thanks,
Jorge.-
Your image gradientBackgroundPlain.png should be 320x44, and create a second image named gradientBackgroundPlain#2x.png with a size of 640x88. Include the #2x image in your bundle, but continue to specify gradientBackgroundPlain.png for the name of the image. The platform automatically chooses the correct size image for use depending on whether there is a retina display present or not.
I am newbie in cocos2D But have developed several view based application.
So what I want to know is:
Is there any alternate ,for animationImages used for animating the images in imageview, in cocos2D?
I want to use the same thing i.e: Animate the images same as any gif file.
Thanks in advance....
Animation in Cocos2D is handled by the CCAnimation class, you can read the documentation here:
http://www.cocos2d-iphone.org/api-ref/latest-stable/interface_c_c_animation.html
There are a number of examples for animating sprites, using a Sprite Sheet, single Images, a Texture Cache, etc.
This is one of my favorite ones:
http://www.raywenderlich.com/1271/how-to-use-animations-and-sprite-sheets-in-cocos2d