Transparent color works on the simulator but becomes black on the iPhone - iphone

I am trying to draw an image that has some transparent regions.
I load the image using
image = [UIImage imageNamed:#"testimage.png"];
and draw it using
[image drawAtPoint:CGPointMake(0,0)];
The UIView on which I draw the image is not opaque (and it has a transparent background color).
The problem is that everything works fine on the simulator, but when I run the app on my iPhone the transparent color becomes black! Can anyone pinpoint my error?

I had the same problem today with a picture of mine. I've created the picture my self in GraphicConverter.
My solution was to add an alpha channel to the picture. I did this with GraphicConverter using the command found in Picture => Alpha Channel => Create Alpha Channel with transparency . It could be that the command has a different name for you as I use the app with a german language setting.
Hope this helps.

The correct answer to this problem is the .PNG format you are saving your image with. If you save as PNG-8, you will run into this problem more often that not, since it only supports 1 transparent color. If you open your .PNG file and then re-save it as a 24-bit format, you will gain genuine transparency.
Reference this thread for discussion and clarification.
EDIT: Just to be clear, .PNG does not have an 'alpha channel', so Chris' answer is misleading. Just be sure to save in 24-bit format with transparency enabled.

I solved my problem by loading it into colorsync and then saving it.

Related

generate png24 asset with a transparent background

I am using file->generate->image assets command in photoshop cc to generate a png file out of a layer.
I have tried myfile.png8, myfile2.png24, myfile3.png32, myfile4.png.
then I noticed that only the *.png24 file doesn't have a transparent background, while all the other files do.
why is it and how can I fix it?
Please check the attached image. Did you uncheck the body background layer? If not then try it and find other layers which is covering the full background. Then press ctrl+alt+shift+s to save the image for web where you will find png24 along with other format. Also confirm that you check the transparency button before saving. Hope it will work for you. Please confirm it worked.

How to remove background of image during runtime in iPhone sdk

I have an image in UIImageView. Those images are generally of clothes or accessories captured from camera on plain backgrounds. Now, I have to give a functionality to users so that they can remove the background from the actual image which is being shown. Something like what is shown in the picture here. As the slider will move the background will start getting removed more and more. Something like the 'instant alpha' brush in the Preview application available in Mac OS X. I wish to do this in native iPhone app.
I know I'll require some algorithm for image processing to do this. Does anyone have anything helpful which I can refer or use in order to get this done? Thank you so much in advance.
You can render your image in some context, than change all points you need to the color you want, get image from your context and display it again.
This link should help you to get color of a pixel in context.
Note, that this method is too slow, so I think you should remember all positions of pixels you
need to change to make your app a bit faster.

UITabBarItem images just appear as a grey block

I have created .png icons 20 x 20 and when I set the image property in the nib they just appear grey blocks.
Any ideas?
UPDATE: Here is one of the icons!
The standard tabbar icons in iOS are rendered solely from the alpha channel. Colors are ignored completely. Instead of colors you can use different alpha values that lead to a different shade of gray (or blue if selected)
Make the background of your icons transparent.
Download these attached images and pass them to your designer and ask him to just create images like these (when you open them in PS you'll know the difference)
This happened to me in iOS 5, I got around it by setting UIImage Outlet property in the Xib to 'Custom' and then set the label programmtically so : imageOne = [UIImage imageNames#"Dog.png"];
Try saving the file as png interlaced. In photoshop at least it gives you an option of interlaced or normal.

How to create image contains a text for UITabBarItem

I am trying to put an image that contains a text on UITabBarItem.
I went to our Graphics designer and asked him to create an image for me that contains a text "Summary".
He actually did. ( a png image).. but when I put inside the app, I saw a horrible look..
The Image:
How it look in the app:
To create an image for a tab bar or toolbar item, you or your designer must work in the image's alpha channel. The colors in the image don't matter at all, the OS only is interested in the alpha channel. In your case, the background of your image should be fully transparent instead of black.
It is absolutely possible for you to use custom colors and images instead of the ones provided to you by Apple's own UITabBarController. I used the code explained in this (really thorough) tutorial - works great.

CALayer or UIView backgroundColor UIImage on iOS 4

Good day all;
I am not sure what has changed to prevent this from working. On iOS 3 SDK, the following code worked fine in a CATiledLayer class:
- (void)drawInContext:(CGContextRef)context {
UIImage* image = [[ResourcesManager sharedResourcesManager] getUIImageFromArray:Image_Cell_Background Index:[mazeCell zone]];
UIColor* color = [[UIColor alloc] initWithPatternImage:image];
[self setBackgroundColor:[color CGColor]];
[color release];
However, compiling for iOS 4 and executing on simulator fails to render the image. I am baffled especially since images added as sublayers render just fine. Only the background doesn't render.
OK after spending a few days on this I have come up with a work-around.
Firstly, I tried doing this in a UIView and still had the same issues. I then tried other types of GUI components that have a backgroundColor property.
They all produced the same issue. From what I can tell, this appears to be a bug and something to do with the new image loading / caching process implemented that interprets whether or not to use HD or SD graphics.
Basically, the workaround it to load the background image as subview or sublayer (depending on your implementation) and either send it to the back (bottom of the hierarchy) or load it first before any other subview/sublayer.
Perhaps backgournd images in IOS 3 wherey doing this within the view/layer and that perhaps Apple decided not double handle the background image versus subview/sublayer and removed support for it.
However, at least you can set the background to a color or even a transparent color. I have verified this.
At any rate, use this workaround until either apple explains why they made this decision or fix the SDK so that it does handle it. I am keen to learn what the apple developer forums have said about this issue (I am certain it has been raised). I am not part of the program just yet as I am still in the alpha stage, once I get to beta, I will register.