We are saving image as png file in swift as below
pngData().write(fileURL,atomic)
The file saved is lossy or lossless ?
I checked for any tools online but did not find answers.
PNG is lossless, check the official documentation image above.
Related
There is an image file named "5.jpg", in the Assets.xcassets named "5".
I wrote code UIImage *image = [UIImage imageNamed:#"5"]; to create the image but app crashes and outputs *** Assertion failure in -[_CUIThemePixelRendition _initWithCSIHeader:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/CoreUI/CoreUI-432.4/CoreTheme/ThemeStorage/CUIThemeRendition.m:3797 in the console.
I had this problem in the XCode 9 beta, running iOS 10 or below. It seems that Apple has dropped support for JPEG files in XCAssets. You can either use do as #Esha suggested and switch to PNG's or you can not use an XCAsset, put the image in your local directory, and refer to it by its URL.
It's possible that Apple did this intentionally (though if they did, I couldn't find any documentation for it) or that this is an XCode 9 bug. I have reported to apple and you can track the progress of the bug here.
Try puting .png images in the asset folder. jpg images will make this issue.
The line should be
UIImage *image = [UIImage imageNamed:#"5.jpg"];
If the file is in PNG format, it is not necessary to specify the .PNG filename extension. Prior to iOS 4, you must specify the filename extension.
From Apple Documentation
It is recommended that you use PNG or JPEG files for most images in your app. Image objects are optimized for reading and displaying both formats, and those formats offer better performance than most other image formats. Because the PNG format is lossless, it is especially recommended for the images you use in your app’s interface.
I want to extract bezier paths from a png like this.
sample image
potrace doesn't support reading PNG files natively. You'd need to convert PNG images to another supported format first. http://potrace.sourceforge.net/faq.html#formats
However potrace is licensed under the GPL so while it does compile for iOS you may not want to use it as part of an app. Is it possible to compile potrace for iOS? There is a non-GPL version of potrace available, but it isn't free.
Depending on the complexity of the PNG images you want to convert, you may get less than ideal results anyway.
If you update your question with more detail about what you are trying to achieve it might be possible to give a better answer.
I like to convert an .jpg or .png file to an .svg format that can be displayed in UIImageView. Is there a way to do this in Objective-C?
You shouldn't use SVG images in Xcode:
it is recommended that you use PNG or JPEG files for most images in your app. Image objects are optimized for reading and displaying both formats, and those formats offer better performance than most other image formats. Because the PNG format is lossless, it is especially recommended for the images you use in your app’s interface.
Also, there's an SVGKit that according to many devs is buggy so use it at your own risk.
SVG is an XML-based vector and in Xcode you can also use vectors but using a PDF format and follow this tutorial.
In a nutshell:
Generate PDFs With the #1x Asset (During compile time it will generate #2 and #3)
Set the Scale Factors to Single Vector:
Drag and Drop Your PDF Into the All, Universal Section
Refer to Your Image by Its Name, Like for any PNG File
[UIImage imageNamed:#”Home”]
Also, stackoverflow (perhaps) related answer
To convert PNG to SVG (Which is a very sensible and valid thing to do) you need an app or library called a "tracer". It will trace the outlines of shapes, gradients, etc and convert them into vector representations.
For simple cases, this is easy for a computer to do; for complex cases (e.g. gradients), this is a very hard AI / Computer-Vision problem and you'd need to spend $$$ on high-end coding solutions and/or find PhD-level research that solves the problem!
A free tracer that does a very good job is built-in to Inkscape (open-source) - google "inkscape trace" for tutorials on how to use it, and to generate a .svg file that you can use. This is a manual process.
To use this in-app, you need to find a tracing library for iOS. The libraries that Inkscape uses are all open-source, so you could try converting them to iOS - they're written in C, so it could be quite easy.
I have a large PNG that I want uncompressed to a file, but I don't have the memory capacity on the device to expand the PNG in memory, then to a file.
Is there a native iOS method to uncompress a PNG for each scan line? Alternatives?
Libpng - Reading image data - http://www.libpng.org/pub/png/libpng-1.2.5-manual.html#section-3.8
For non-interlaced PNGs
png_read_rows(png_ptr, row_pointers, NULL, number_of_rows);
As and idea how to start:
Take a look how is doing Java the png decompressing algorithm. Java should have open-source those files. Maybe has the iOS too idk. Just get the uncompress algorithm idea. It should be around 1k-5k lines of code.
When you know how to do it, than implement at iOS but read a chunk of file and than export to a file, read another chunk and process and export it. I know it is easy to say and at least theoretically it is working. Maybe is public in some site. Libpng can be a good starting point.
Png is a looseness compression like zip. There as I have remember runtime is built a data table. Those table depends how big is, maybe need to be swapped to to disk, which will makes longer the decompression process.
Good luck!
I was experimenting with JPEG2000 and WEBP through Imagemagick. They were both giving me much better compression levels than I had gotten from JPEG in GIMP, with WEBP doing better than JPEG2000. But when I changed the input image from a JPEG to a PNG, WEBP suddenly started creating output files that were even larger than the input. JPEG2000 showed no significant change. I tried to add options like -format webp and -define webp:lossless=fase, but they didn't help.
Also, my file manager and identify both insist that the resulting file is a PNG and not a WEBP. I later checked and found that the files converted from JPEG were also considered JPEGs, even though they were smaller than the fine-tuned JPEG2000s.
All images had the same quality level of 85. Imagemagick supposedly supports WEBP natively, and I also have libwebp installed. JPEG2000 is being handled by libJasPer.
What is going on?