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

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).

Related

Random UIImage artefacts

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.

CLKComplicationTemplateUtilitarianSmallRingImage not showing image

I'm having issues using CLKComplicationTemplateUtilitarianSmallRingImage with a central image.
I'm pretty sure that at one point the image I choose was showing up within the progress ring, but after relauncing a few times, the image disappeared. Oddly, when I've tried to use it in CLKComplicationTemplateUtilitarianSmallSquare and CLKComplicationTemplateUtilitarianSmallFlat the image shows up just fine.
For the life of me I cannot figure out what is going on.
Here is the code I'm using:
let smallRing = CLKComplicationTemplateUtilitarianSmallRingImage()
smallRing.imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "Complication/Utilitarian")!)
smallRing.ringStyle = .Closed
smallRing.fillFraction = 5 / 9
handler(CLKComplicationTimelineEntry(date: NSDate(), complicationTemplate: smallRing))
A few more details:
Not working on device or simulator.
My image is 14pt (28px), I have tried with PDF (single vector) and PNGs (non-interlaced).
Works as expected with any CLKComplicationTemplateUtilitarianSmall* that accepts images except CLKComplicationTemplateUtilitarianSmallRingImage.
Have tried using a Complication Image Set, just an image in the Catalog both Apple Watch and Universal...
Have tried not setting other properties on CLKComplicationTemplateUtilitarianSmallRingImage.
Crashes on targetting the incorrect image name, so I know it's loading the image when the name is accurate.
Tried with tint color and just changing around the image's default color to see if that's it. Nope. Would think it's the image if it wasn't working in other Templates!
I have to be doing something unusual though.
Looks like this was a bug with WatchOS 2.2.1!
Thankfully fixed in 2.2.2!

Toolbar button image suppressed

I have a viewcontroller with a toolbar with 2 bar button items. The image on one is a simple flat icon. The other is a complex image reduced to 28x28 pixels from a 256x256 image. The complex image shows up as a blob as shown below. The actual image is also show in the picture. It is not clear what I am doing wrong. The project code is available in the following link:
Project code
John Griffith on Apple Developer Forum provided this explanation which made a lot of sense. I need to redesign my icons if I want to proceed along this line:
Toolbar images are normally rendering mode "template" - only the alpha channel is used. Any non-transparent pixels are drawn in the bar's tint color. It may be possible to create a UIImage with rendering mode "always original" to preserve the look of your image, but then it won't respond to changes in tint color.
I have downloaded your project. The first thing you should do is to move your image files into the images.xcassets folder. Read here to understand why.
The image you are trying to display is actually just a red rectangle:
As you can see, opening in another program also just displays it as a red rectangle. Be sure to use the correct Image file. The problem lies not with your project but rather the image file you are using.

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:];

Uiactivty image Not Appearing in iOS

I am implementing UIActivtyViewController and I want to add whatsApp image to that. (http://a598.phobos.apple.com/us/r30/Purple/v4/fa/a8/02/faa80212-7d5b-f8a2-0e86-22d619ef6dc2/mzl.cmjuugpr.png) Adusted frame 60x60.
but I am not getting As I excepted, I am getting like following message.
what i have to do display correct image thanks in advance.
You can only play with transparency. Colors are ignored. That's why you are getting a solid rectangle. Documentation says:
The alpha channel of the image is used as a mask to generate the final
image that is presented to the user. Any color data in the image
itself is ignored.

Resources