Using vectors in iOS - objective-c

I'm working on a simple iOS game that's always drawing 5 to 10 layers of 32bit png images which requires enough memory to crash on the ipod touch 4g when retina enabled. On other devices it works just fine. I'm not even getting memory warnings. So I was trying with lower quality images, like RGB5_A1 format, but it looks really bad because I need alpha transparency and lots of gradients.
Since all the images are exports from Illustrator I was thinking that maybe i could just export a vector image and draw in on iOS. From what i was researching hardly anyone tried this and the only option I've come across was to implement a SVG parser for Quartz.
Did I miss anything?
Also I'm worried about performance, but I couldn't find any benchmarks.

Without knowing specifics of your game, I'm going to make a few assumptions based on normal use...
You are not going to want to use straight vector graphics for this. Stick with your raster graphics.
If you are talking about 32 bit color space for your PNG images, then you need to scale back. iOS uses 24 bit images and that includes 8 bits each for red, green, blue, and alpha. As it stands, you have an extra byte for every pixel shown.
If you are using Adobe products, import the Illustrator file into Photoshop and use the "Save for Web..." option. Choose PNG-24 and you'll be all set.

Related

Is there any way I can enlarge a stimulus in #psychopy without losing image quiality?

I'm importing my stimulus from a folder. I would like to make them bigger *the actual image size is 120 pix (height) x 170 pix (width). I've tried to double the size by using this code in the PsychoPy Coder:
stimuli.append(visual.ImageStim(win=win, name='image', units='cm', size= [9, 6.3],
(I used the double number in cms) but this distorts the image. Is it any way to enlarge it without it distorting, or do I have to change the stimuli itself?
Thank you
Just to answer what Michael said in the comment: no, if you scale an image up, the only way of guessing what is in between pixels is interpolation. This is what psychopy does and what ANY software would do. To make an analogy: take a picture of a distant tree using your digital camera. Then scale the image up using all kinds of software. You won't suddenly be able to see the individual leaves since the software had no such information as input.
If you need higher resolution, put higher resolution images in your folder. If it's simple shapes, you may use built-in methods such as visual.ShapeStim and it's variants: visual.Polygon, visual.Rect and visual.Circle. Psychopy can scale these shapes freely so they always stay sharp.

How to auto generate Retina and Non-retina images from psd

I have a PSD file for my App Interface that was designed for Retina iPhones with a resolution of 640 x 1136. I want to add support for non-retina devices and and add all image assets with both a retina and non-retina version. I find the process of resizing every ui component on photoshop individually very tedious. Does anyone know how I can auto-generate Non-Retina images from the Retina images I have already exported? Thanks
If you have Photoshop CC, you can use Adobe Generator (especially nice when paired with Russell Brown’s free Layer Namer extension). Adobe Generator automatically exports any layers whose names end with .png, and can also export multiple resolutions.
There are also some great posts on this topic by Marc Edwards on the Bjango blog; specifically: Exporting from Photoshop. His articles deal with creating a slice sheet that you export semi-automatically with scripts.
I have used both of these workflows in production. Each has its quirks, but they can both probably be made to do what you’re after.
A tip: I prefer to design at 1x and then scale up. If you design and scale down, you might make an asset an odd number of pixels wide, which could look bad when scaled down. But many graphic designers I've worked with prefer to design at 2x.
For images i am using Resizer .Quite nice and fast application.
If you're able to work from the original .psd then the free SuperExport Photoshop script might be of use. It allows you to export flattened crops (not just entire layers) at multiple resolutions by careful naming of groups and layers. Documentation is here, and an updated version that also supports 3x is here (I'm the author of the - small - 3x modification).
The benefits, as pointed out in the docs, of using the original .psd are that you can see your design in context while selectively (and easily) regenerating assets with a single click.

iOS: how to reduce size of large PNG files

I'm currently optimizing my iOS app for the new iPad. Unfortunately by adding launch images for the iPad retina display the size of my ipa grows from 1.2MB to 5.5MB, mainly because of the two PNG images in 1536 x 2008 (portrait) and 2048 x 1496 (landscape). The size of these images are respectivly 1.9MB and 1.7MB.
The portrait can be seen here: http://uploads.demaweb.dk/iPadPortrait.png.
As you may notice, the background is a fixed pattern but sadly it seems that this is not very compressible. I've further tried to compress the images using ImageOptim, but it does not make any difference after Xcode has compressed the images during the archive. Searching the web I've noticed, that some people are dissuading to turn off PNG compressing in Xcode.
Are there anything I can do? It is not a solution to change the pattern in the image to a solid color, as it should look like the background in my iOS view. But it seems odd, that supporting the new iPad increase the size by ~4MB.
I was able to get it down to 633KB with pngquant (64 colors with slight dithering, which is barely noticeable on regular screen, and should be absolutely invisible at Retina resolution) and ImageOptim.
Yes, you will need to disable Xcode's conversion to avoid Xcode inflating files by converting them to ARGB.
NB: the article quoted in the accepted answer provides no benchmarks at all for the claimed speed difference.
It also contains correction that it is possible to optimize images with ImageOptim for iOS apps.
I'm using a great tool called ImageOptim
It incorporates a number of tools inside which crush your png files significantly (in my case it was between 25% to 50%).
One thing to remember is to disable Xcode's PNG optimization (as explained on the website)
EDIT:
Simply drag the images to the imageOptim window and the optimization will start automatically
Ive struggled with this too, unfortunately not much can be done.
In an effort to dramatically increase drawing performance of iOS apps,
Xcode re-compresses PNG files as it builds. It premultiplies the alpha
channel and byte swaps the red, green and blue channels to be
sequenced blue, green and red. The result is optimised for iOS’s
purpose, but as a side effect, ImageOptim’s work gets undone…
Source

Vector art on iOS

We've now got 4-resolutions to support and my app needs at least 6 full-screen background images to be pretty. Don't want to break the bank on megabytes of images.
I see guides online about loading PDFs as images and custom SVG libraries but no discussion of prectically.
Here's the question: considering rendering speed and file size, what is the bet way to use vector images in iOS? And in addition, are there any practical caching or other considerations one should make in real world app development?
Something to consider for simple graphics, such as the type of thing used for backgrounds, etc., is just to render them at runtime using CG.
For example, in one of our apps, instead of including the typical repeating background tile image in all the required resolutions, we instead draw it once into a CGPatternRef, then convert it to a UIColor, at which point things become simple.
We still use graphic files for complex things, but for anything that's simple in nature, we just render it at runtime and cache the result, so we get resolution independence without gobs of image files. It's also made maintenance quite a bit easier.

Managing resources in a universal ios app

I am developing a cocos2d game. I need to make it universal. Problem is that I want to use minimun amount of images to keep the universal binary as small as possible. Is there any possibility that I can use same images I am using for iphone, retina and iPad somehow? If yes, how can I do that? What image size and quality should it be? Any suggestion?
Thanks and Best regards
As for suggestions: provide HD resolution images for Retina devices and iPad, provide SD resolution images for non-Retina devices. Don't think about an all-in-one solution - there isn't one that's acceptable.
Don't upscale SD images to HD resolution on Retina devices or iPad. It won't look any better.
Don't downscale HD images for non-Retina devices. Your textures will still use 4x the memory on devices that have half or even a quarter of the memory available. In addition, downscaling images is bad for performance because it has to be done by the CPU on older devices. While you could downscale the image and save the downscaled texture, it adds a lot more complexity to your code and will increase the loading time.
There's not a single right answer to this question. One way to do it is to create images that are larger than you need and then scale them down. If the images don't have a lot of fine detail, that should work pretty well. As an example, this is the reason that you submit a 512x512 pixel image of your app icon along with your app to the App Store. Apple never displays the image at that size, but uses it to create a variety of smaller sizes for display in the App Store.
Another approach is to use vector images, which you can draw perfectly at any size that you need. Unfortunately, the only vector format that I can think of that's supported in iOS is PDF.