Random UIImage artefacts - ios

I have a very strange bug which appears randomly amongst users. In most cases, the same image loaded into a UIImageView shows perfectly, but occasionally has an artefact line running through it as in the pic attached. We cannot reproduce during testing on either the simulator or device. The image loaded is a simple png:
groupAvatarIV = [[UIImageView alloc] initWithFrame:CGRectMake(horizontalMargin, 5, 70, 70)];
groupAvatarIV.clipsToBounds = YES;
groupAvatarIV.layer.cornerRadius = 70 /2;
groupAvatarIV.image = [UIImage imageNamed:#"avatar"];
[contentV addSubview:groupAvatarIV];
I am really out of ideas how to debug this - any tips would be appreciated please.

It looks like the image contains data for a width greater than itself, so it keeps writing data in an address that becomes the next line down etc... (evidenced by the fact that it starts at the widest part of the circle)
maybe there is something wrong with the params on the image, or it might just be an apple bug...
if it is an apple bug, I would expect it to be with the behavior of clipToBounds
try to collect OS info from the users that experience it... also you could try to re-save the images using a different program, like use ffmpeg to save them as a tiff, then convert back to png (which should be a lossless route), so you know it had to re-interpret it...

Turned out the project which we took over contained multiple image files with the same name, which is what caused the artefacts.

You have mentioned that you have added the imageView in another view as a subview. It seems that the image view is not fit to the superview. You need to check the frame size of both views. Then you need to set the frame of the image view equal to or less than the superview.

Related

Image looks bad when testing, but original image file is looking just fine

Why does my image look awful when I'm testing the app on my 5s. It also looks awful when testing it on the simulator. My image has the same width as the 5s: 640px. It is saved as #2x. The UIImageView has the exact same size as the image: 640. The UIImageView is also keeping the view in ratio.
My result
I'm trying to archive the same quality result as shown in the second image, which is screenshotted from a random relevant app.
The quality I want
I can't add the original image file because I need 10 reputation for another link. But I can assure you that the original image file looks just fine. So somewhere in Xcode there is going something wrong?
Deleting the line below fixed it:
self.Aktau1?.layer.shouldRasterize = true
Without that line, my code now looks like this (to apply a shadow):
self.Aktau1?.layer.shadowColor = UIColor.blackColor().CGColor
self.Aktau1?.layer.shadowOpacity = 0.15
self.Aktau1?.layer.shadowOffset = CGSizeMake(0, 45
self.Aktau1?.layer.shadowRadius = 25

In iOS image from SOAP service set as NSData is cut. Which can be the reason?

I have SOAP service. I use sudzc.com generated wrapper to access the service. During the communication I receive an image (several different images) which I have to expose. I use NSData field saved in .plist file to store the image. My problem is that in some cases The image is cut on the right side. I use Aspect fit. I am almost sure that the image is cut inside my App, because we have similar App on Android and in that App image is ok. Also I use Right and the right side is also cut.
Any ideas how to manage that situation?
EDIT:
I tried with fixed image (as poojathorat suggested). The fixed image was shown ok.
I remove all constraints and widen the area of the image in the IB but it is still cut (even it is resized - the sizes of the parts of the image are bigger).
Set the content mode of image as scaleToFill.
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.clipsToBounds = YES;

iOS - jagged edges on text and image. Why? and how to fix?

Why are there jagged edges on some of the texts and images in the app i am developping?
I have tried to go through the frames, and i have not used a division to set a frame (so the 1.134234 is not an issue), and I have tried different antialiasing methods.
Does anybody have an idea?
See attached for an example.
EDIT:
The images become jagged, when downscaled. So either resize them to fit the size directly in the actual file, OR via code as suggested in other StackOverflow questions.
Now trying to figure out how to fix the text also! :)
EDIT EDIT EDIT EDIT
Answer will posted tomorrow (after 24 hours).
1) Image problem: Make sure the actual image size you are using is close to the size you are actually using it... (Feks 100 points with an image at #1x that is 100, #2x that is 200, and #3x that is 300, where 100,200, and 300 are the actual image file pixels). Or resize using code in the correct way to match.
When iOS is downscaling (as well as upscaling) an image, the pixels get disorted.
The problem in my case was using a too big an image.
2) As to the button, I don't know exactly why, but it got solved using attributedText for the title instead of the usual text. Method used is:
[button setAttributedTitle: forState:];
Solved it :D
1) Image problem: Make sure the actual image size you are using is close to the size you are actually using it... (Feks 100 points with an image at #1x that is 100, #2x that is 200, and #3x that is 300, where 100,200, and 300 are the actual image file pixels). Or resize using code in the correct way to match.
When iOS is downscaling (as well as upscaling) an image, the pixels get disorted.
The problem in my case was using a too big an image.
2) As to the button, I don't know exactly why, but it got solved using attributedText for the title instead of the usual text. Method used is:
[button setAttributedTitle: forState:];

Android onpreviewframe:Preview on image views shows green/pink image on tablet

I need to get preview from camera and show it on Imageview..
The code is done as follows
public void onPreviewFrame(byte[] data, Camera camera){
yuvimage = new YuvImage(data, parameters.getPreviewFormat(), width, height, null);
yuvimage.compressToJpeg(new Rect(0,0,parameters.getPreviewSize().width,parameters.getPreviewSize().height), 90, outstr);
bmp = BitmapFactory.decodeByteArray(outstr.toByteArray(), 0, outstr.size());
camera.addCallbackBuffer(data);
}
This code works fine, the if bmp passed to imageview the it displays clear color image on most of the devices, but on a tablet, it shows green/pink image..
If surfaceview is used to show preview directly then it shows clear color preview on all devices..
Any suggestion is appreciated..
If the image looks sort of correct, but just has a weird color to it, then I would guess
that the problem lies with the picture format. I would start is by trying to change parameters.getPreviewFormat() to ImageFormat.NV21 and see if that fixes the problem.
I have used basically the same code before, and never had a problem. (Although you should push the rendering to a separate thread, and probably use RenderScript to convert the pictures).

UIImage is somehow adding padding for me

I have an PNG image file foo#2x.png that is 128x128 pixels. My expectation is that when I load it on a retina device the resulting size will be 64x64 points. In fact though I am getting a UIImage* that is 100x100 pts, where the extra points (18pts on each side) are just empty (I confirmed by drawing a border in the containing UIImageView*).
I have tried loading the image via [UIImage imageNamed], [UIImage imageWithData], and [UIImage imageWithData:scale]. They all give back the same image, and I'm confused. Anyone able to explain where this extra space is coming from?
[EDIT] Per John's request,
[UPDATE] It seems this had to do with the simulator caching something from somewhere. Deleting the app from the simulator, doing a clean build, and re-running gives me the size expected. Not clear how this happened, since this isn't a changed or modified image file -- it's totally new and has never existed at 100x100 pts. Open to hearing how this could happen, but don't want to waste anyone's time chasing rabbits.
Answering my own question (see last UPDATE), somewhat bewildered but willing to move on with a healthy suspicion of what the simulator is doing.

Resources