How to make a torch (iPhone) with colored light in swift? - iphone

I have tried to read AVFoundation documentation and I can't find anything about colors. Is it possible to change the color to red, green or blue? I think I have seen colored torch apps.
Would it be very hard to write your own code that controlled color hue or lumen of the flashlight?

While there are apps that get around this by display a brightly colored screen, the flash on the iPhone is has a single LED element.
You do, via AVCaptureDevice, have the ability to change the intensity of torches on some models. Take a look at the torchLevel property.
You could always try an easy hardware hack.

Related

Swift - Colour appears washed on device

Using XCode's assets to store my colours and for some reason the actual colour on my device when I run the build of the app, is a really washed colour! No matter what I do, it doesn't look like it is meant to.
It colour doesn't seem to come out right. I have put in the hex value in the color set and all.
It doesn't look as good as I want it to and I don't understand why it looks crappy on my device which is an IPhone XS Max. But this screenshot below looks a bit better? I am a bit lost. Any help would be appreciated.
When I screenshot it, it looks normal. Like this
This is how I set my colours.
Did you maybe check which color profile are you using? Maybe try using different profiles. You can change the color profile by clicking the gear icon on the color picker next to the "color type" dropdown.
What you want to achieve is to user the same color profile as the source of the color (the program where you are copying the colors).
Good options are usually P3 or sRGB. Be sure to set reset the color after changing the profile. Usually the color is updated with the color profile (color looks the same, but the hex/rgb value changes).
Play around with different values and see if it fixes the issue.
The image below demonstrates how to change the color profile.

Photoshop magic wand-like action in an iOS app

Is there a way to use a magic-wand tool (like in Photoshop) in Xcode for iPhone? What I want to do is to cut out the background of an image (a person standing in front of a white background) to make the background transparent.
Edit:
i think i was not specific enough, sorry. I would like the iPhone or iPad app to automatically remove the background of an image just taken with the camera. Thus, i can't use Photoshop for it and need a function or so to do this. I was thinking about a "flood fill" kind of solution similar to this:
http://www.codeproject.com/Articles/16405/Queue-Linear-Flood-Fill-A-Fast-Flood-Fill-Algorith
but was hoping that there is a more convenient solution especially for "cutting" out custom shaped areas of an image.
Thanks!
Floodfill assumes a uniform background color; on a real life photo, it won't ever be uniform. What you need is a Chromakey algorithm. See here:
Green screen / chroma key iOS

iOS - color on Xcode simulator is different from the color on device

Overview
The background color of my iPhone app in the simulator (iMac) looks different from the color on the device (iPhone 3GS).
EDIT (following section has been added)
The following are all different:
story board color (xib file)
simulator color
device color
I suppose I should go with how it looks on the device.
Questions
Is this is a common problem other developers face and is there a way to match the colors (systematic procedure) ?
will the color look different on different versions of iPhone (3gs / 4 / 4s) or all the color ?
Am I missing something, is there any specific color profile I should use ?
Is there something like a rule of thumb where RGB values vary by a certain percentage ?
In iPhone 4 and 4S, do the color match the simulator ? ( I don't have a iPhone4 and 4S, so I am not sure.)
Credit goes to #jtbandes for suggesting to send screenshots which led to the solution
I am just answering the question for completeness.
Steps I followed:
Take a screenshot of image in storyboard
Take a screenshot of image in device (use mail / photo stream back to your mac)
Use color picker (part of mac OS color palette) to pick the same spot on both the screenshots
Note down the RGB values (available on the mac OS color palette) of spots chosen in step 3
compare both the RGB values and see the difference
add the RGB offset to match the color.
My RGB offset (not be followed blindly)
based on my experience, i added the following RGB values to get the color I wanted, it is only rough and worked for me:
Red +12
Green +19
Blue +16
Different angles (best to keep it horizontal)
Holding the phone in different angles also gives different shades, keeping it horizontal did give the color
As others have pointed out, this is an issue of Color Spaces.
Two tasks need to be performed:
Get the source color using the sRGB color space.
Set the color in Interface Builder, using the sRGB color space.
Task 1
You can use Apple's Digital Color Meter app to sample the required color, using the Display in sRGB option, but the output is very limited.
Another option is to use an app like SipIt (available free on the App Store, last I checked). Make sure you are sampling in the correct color space by performing:
Preferences -> General -> Color Profiles -> sRGB
You can also set your output format (e.g. hex string).
Task 2
In Interface Builder, open the Color window, choose the the second pane, choose "RGB Sliders". Then click on the cog icon to choose the sRGB color profile.
Once done, paste your color value in to the Hex Color # field
You're done! Your colors should now match.
I am not affiliated with SipIt in any way. But I've been using it for a few years and it is very handy. I'd recommend it to any designer.
The current (as of 3/17/14) CGColorSpace reference includes the following text, which says that sRGB is the native device color space for iOS.
Color Spaces and iOS: iOS does not support ColorSync, so all assets should be provided in the native device color space: sRGB.
It's about color spaces.
Make sure you are picking the color from an sRGBcolor space, and replicating its RGBA values on Interface Builder by selecting sRGB IEC61966-2.1 from the dropdown menu.
If you pick a color in one color space, and generate it in a different color space, it will look different, in spite of having replicated the same RGBA values.
Also, have in mind that when you generate a color through code, using UIColor(red:green:blue:alpha:), it's generated on the sRGB color space by default. That's why it's so convenient to use this one (instead of Adobe RGB, P3, or any other). Besides, sRGB is the standard that's most used in the industry currently.
Fun fact: That UIColor constructor I mentioned above creates colors in the sRGB space since Xcode8. Before, that function used to create them within the Generic RGB space instead. That's why it might cause confusions too.
Here is a resource that extends on the topic: https://medium.com/#volbap/working-efficiently-with-colors-in-xcode-bc4c58b16f9a
iPhone does use color space management so if you want a more "scientific" solution you can create your own color space for example with CGColorSpaceCreateCalibratedRGB. It's on Core graphics level though.
The better way to convert the RGB values to sRGB is using "Digital Color Meter" tool in mac, simply check the "Display in sRGB"
then use the sRGB values in your code instead of RGB
using this tool you can find out generic RGB color and set it directly to xcode as RGB values
One more simple solution when working with image files in your app. Firstly, set your color space in Xcode to sRGB IEC61966-2.1 and apply your colors. Then, before you import any pictures to your app, match your images to sRGB IEC61966-2.1 profile using ColorSync Utility on Mac.
Worked perfectly for me and my background now perfectly matches my imported images. Hope this helps someone.
I had a similar problem, especially with the greens in my project. My issue turned out to be that some of the assets I had were created in illustrator, and the color was set to CMYK instead of RGB. I'm not sure if this was your issue or not, but it might be helpful for those who stumble onto this question in the future. I changed the illustrator "Document color mode" to RGB and all is well.
You can use this webPage for different decks of colors in Xcode.
for example Generic and Device Colors are different a little bit.

iPhone, what background colors should I use for a personal finance app?

I know this question might be considered better on Stack UI, but I wanted some opinions from fellow app developers.
I've designed my app with black opaque navigation bars, and dark colored backgrounds. I've produced some radial gradient backgrounds in my paint program. I have three different images (plus a second set for retina). One has a dark green to black gradient, another dark yellow to black and a dark blue to black gradient.
So my app looks quite dark.
I didn't think this was a problem.
However me colleague thinks this is a very bad idea, that it will make people think their money will disappear into a black hole.
I'd like to use different colors backgrounds as I have one view I use in edit and add mode, to differentiate them. Also it makes each screen more distinctive.
I've also had a look round to see if you can buy sets of backgrounds, but I've only seen wallpaper sites for users to use.
I want to make my app seem cool, thats why I've gone for a dark scheme. But I'm now a little worried that it will affect sales.
I'd like some opinions please. I don't really want to post any of my screens as I haven't released my app / idea yet.
See http://www.noupe.com/showcases/showcase-well-designed-banking-and-investment-websites.html
IMO, Go with light Grey
#eee
Also see http://www.mybanktracker.com/
I would agree that a dark scheme probably isn't the best but have you looked at other apps? Mint uses a nice contrast of dark headers with white (or light) content areas. They even have a nice textured background if you drill to the transaction view. I'm using a very light green in an app I'm working on that could go really well with dark nav bars and a dark green-ish/black font. It could at least be a nice background color bumping up against dark borders.
[UIColor colorWithRed:196/255.0 green:218/255.0 blue:173/255.0 alpha:1.0]
However, I will say that it's difficult to recommend a color scheme without seeing what kind of ui you're dealing with (how many elements and of what type, etc).
good luck...
I think using the banks colours is best for brand recognition, the National Bank iBank app does this well.

Mapping CoreGraphics Blend Modes to Porter-Duff

I have an iPhone app that does image manipulation via blending two UIImage objects via CoreGraphics, specifically CGContextSetBlendMode. I am currently researching porting it to Android. I've gone through the process of combining to Bitmap objects on Android using PorterDuff modes. However, I want much more complicate compositing. For example, I'm using kCGBlendModeHardLight for many blends:
Either multiplies or screens colors,
depending on the source image sample
color. If the source image sample
color is lighter than 50% gray, the
background is lightened, similar to
screening. If the source image sample
color is darker than 50% gray, the
background is darkened, similar to
multiplying. If the source image
sample color is equal to 50% gray, the
source image is not changed. Image
samples that are equal to pure black
or pure white result in pure black or
white. The overall effect is similar
to what you’d achieve by shining a
harsh spotlight on the source image.
Use this to add highlights to a scene.
But don't know of anyway (if it's even possible) to emulate this via Porter-Duff. Does Android not support better Image Manipulation algorithms out of the box? Is it possible to use Porter-Duff in some way to emulate more advanced blend modes?
In addition to the 12 Porter-Duff blending equations, Android supports Lighten, Darken, Multiply, Screen and soon Overlay. Unfortunately this means HardLight is not available and you would have to implement it yourself.