Cappuccino - Load images from disk to a CPImageView - cappuccino

I am looking for a way to load an image from my disk into a CPImageView. Is this possible?

To upload an image to a server, you could either use a normal file upload button such as what is implemented by FileUpload. Or, if you're not afraid of some potentially very tricky cross browser problems you could try to use my fork of Deep Drop Upload which allows drag and drop upload.
In either case, once the image is on your server you need your server to return the URL of where the image can be viewed. Let's say this URL is http://example.com/uploads/image101.png. Then you can display it in a CPImageView the normal way:
var imageView = [[CPImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[imageView setImage:[[CPImage alloc] initWithContentsOfFile:"http://example.com/uploads/image101.png"]];

Related

How to save background as UIimage from uiimagepickercontroller

I have a View to get and set image from photo gallery.
I want to call the image from another view and set the uiimage as background.
What is the best method to make the image stay as a background like iPhone default background feature?
My codes are modified version from here: http://blog.hanpo.tw/2012/01/uiimagepickercontroller-and-simple.html
The best way is to use a UIImageView :
UIImageView *myImageView = [[UIImageView alloc] initWithImage:[UIImage imageWithContentOfFile:#"path/of/myImage.png"]]
You can pass the path to your image as an argument and store it or copy the file under the name "background.png" for example, and each time you change it you delete the file and create the new "background.png".

Image maps in iPhone app

I want to impliment a clickable pie chart in iphone app. I have an image for this but i want to know how can i specify clickable areas using UIImageView or any other component. I don't want to use HTML image map.
A simple solution could be to add transparent buttons on top of your image.
UIButton *transparantButton = [UIButton buttonWithType:UIButtonTypeCustom];
transparantButton.frame = CGRectMake(100, 100, 50, 50);
[transparantButton addTarget:self action:#selector(clicked) forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:transparantButton];
You can probable try by placing custom buttons over the areas you want or detect touch and based on the location of touch u can perform necessary actions.
Note: The method using buttons is better if the number of such clickable regions is small.
you can create image map for iphone using jquery mobilymap: Jquery Map

Background image in view controller result in memory increase + UIColor colorWithPatternImage

I tried 2 different methods of creating a background image for a view controller.
I have researched this before and came to the conclusion that for good memory practice you should use this method:
NSString *path = [[NSBundle mainBundle] pathForResource:#"controllerBackground" ofType:#"png" inDirectory:#""];
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:path]]];
When using the other method:
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"controllerBackground.png"]]];
This is not as efficient as using the imageWithContentsOfFile:path method.
However when testing both these methods using the performance tools "leak" monitor, I observed a very unusual thing happening.
While using the imageWithContentsOfFile:path method, the problem was that when going back and forth within a navigation controller loading the view controller, the memory would keep increasing within the vicinity of approximately 1mb every time the view controller loads.
This problem is also only observed in the new iOS 4.1 and 4. It does not seem to happen in the iOS 3.0 or 3.2.
Here's a fix that worked for me.
UImage *image = [UIImage imageNamed:#"name.png"];
self.view.layer.contents = (id) image.CGImage;
You have to import QuartzCore, now i don't have 2MB memory increase every time i go that view.
Allan, I faced the same problem and found that colorWithPatternImage and initWithPatternImage is taking large memory than expected. Here is a link which explains the same.
http://www.cocoabyss.com/coding-practice/colorwithpatternimage-abusive-memory-usage/
Better to avoid both methods for background images.

How to overlap (superimpose) an image over a file icon using Cocoa?

I have to make a prototype application where I superimpose a small image over the file icons of a given folder.
Let's say I have a folder /MyDocuments/
and there are three files /MyDocuments/Doc1.rtf /MyDocuments/Doc1.pdf and /MyDocuments/Doc1.jpg
and I have an image myicon.png, now I have to superimpose this image myicon.png over the file icons of all the three files present in /MyDocuments/
I understand that I can use the methods in NSWorkspace sharedWorkspace to get and set the file icons for these files, but I have no idea how to use the image myicon.png and superimpose it over the existing icons of these files.
If anyone has seen the Dropbox application (dropbox.com), then it is similar to the way you see changed icons in your dropbox folder
I assume it would be done using NSImage but I have no idea how to do it.
Note: the image myicon.png will only occupy the top left part of the original icon of these files i.e. the image should not completely overlap with the existing icons but only the 1/4th portion on the top left should be occupied.
Lock focus on the file icon, then draw the badge icon, then unlock focus. You may want to do this to a copy of the file icon, and hang on to the unbadged original.
If the badge is one of the standard badges that come with Mac OS X, don't copy the badge into your app—it'll look outdated if Apple ever changes it. The standard badges are named in IconsCore.h; you can wrap any of those types in a string using the NSFileTypeForHFSTypeCode function, then pass that string to NSWorkspace's iconForFileType: to get the standard badge as an image, from which point you can do the above.
As a supplement to Peter Hosey's answer, here is some slightly modified example code from:
http://cocoadev.com/forums/comments.php?DiscussionID=221
NSImage *origImage = [sourceImage copy]; // Copy to avoid modifying the original.
NSSize previewSize = NSMakeSize([origImage size].width / 4.0, [origImage size].height / 4.0);
NSImage *previewImage = [[NSImage alloc] initWithSize:previewSize];
[previewImage lockFocus];
[origImage drawInRect:NSMakeRect(0, 0, previewSize.width, previewSize.height)
fromRect:NSZeroRect // Draws full image.
operation:NSCompositeSourceOver
fraction:1.0];
[previewImage unlockFocus];

Getting a CGImageRef from IKImageBrowserView

I feed the image browser view with image filenames and it manages loading them.
Is there a way to retrieve the CGImageRef of those images from the browser after it loads them? I'd like to do some Core Animation with them when the user clicks on an image.
Probably the simplest way to do this is to use the NSView method
-bitmapImageRepForCachingDisplayInRect:
to build an NSBitmapImageRep for the area, then
-cacheDisplayInRect:toBitmapImageRep:
to draw into it, then NSBitmapImageRep's
-CGImage
method to get a CGImageRef.

Resources