ios 删除图像中的 Alpha 通道
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26171739/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Remove alpha channel in an image
提问by zbz.lvlv
I have an app icon for iOS but Apple doesn't allow alpha to be in the image. How to remove this alpha channel? I only have the png image with me I don't have the source file as my friend did the image for me.
我有一个适用于 iOS 的应用程序图标,但 Apple 不允许图像中包含 alpha。如何删除这个 alpha 通道?我只有 png 图像我没有源文件,因为我的朋友为我做了图像。
采纳答案by danielquokka
Assuming you don't have another image editor, then you can open it in Preview on your Mac, and use the Export option to resave it in a different format- to ensure you get rid of the alpha channel, it might be best to export to JPG (best quality), then open that and export it as a PNG again.
假设您没有其他图像编辑器,那么您可以在 Mac 上的“预览”中打开它,并使用“导出”选项将其重新保存为不同的格式 - 为确保您摆脱 Alpha 通道,最好导出到 JPG(最佳质量),然后打开它并再次将其导出为 PNG。
Having said that, I suspect you're probably OK submitting an icon with a transparency channel as long as there's no actual transparency.
话虽如此,我怀疑只要没有实际的透明度,您可能可以提交带有透明度通道的图标。
回答by Mycah
The accepted answer to export to JPG, then back to PNG is not recommended.
不推荐导出为 JPG,然后返回 PNG 的公认答案。
- It's an extra step in the process (2 exports)
- JPG is lossy, so you will lose some image data
- 这是过程中的一个额外步骤(2 个出口)
- JPG 是有损的,所以你会丢失一些图像数据
Here's a super fast and easy way to do this without the extra export or saving to (lossy) JPG:
这是一种超级快速简便的方法,无需额外导出或保存到(有损)JPG:
Using Preview app (Mac):
使用预览应用程序 (Mac):
- Openthe image
- Command-Shift-Sto Duplicate (creates a copy)
- Command-Sto Save
- Deselect the "Alpha"checkbox
- Delete " copy" from filename(including the space)
- This will overwrite your original, if you want to keep the original, just leave "copy" in the name
- Save
- Click 'Replace'to confirm you want to overwrite the original
回答by Nikita Pushkar
if you need remove all alpha channel from directory with icons use this command:
如果您需要从带有图标的目录中删除所有 alpha 通道,请使用以下命令:
for i in `ls *.png`; do convert $i -background black -alpha remove -alpha off $i; done
if you have Mac OS Mojave and had "convert command not found"
如果您有 Mac OS Mojave 并且“未找到转换命令”
brew install imagemagick
To install Homebrew
安装 Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null
回答by Oscar
If you are using the Preview app, there's no need to export then re-export between jpg and png, just choose export and below the filetype (PNG) you will see an alpha checkbox, unset it and save.
如果您使用的是预览应用程序,则无需在 jpg 和 png 之间导出然后重新导出,只需选择导出,在文件类型 (PNG) 下方您将看到一个 alpha 复选框,取消设置并保存。
回答by Stefan
回答by Psychomentality
You can try imagemagick (also easily resize for different sizes):
您可以尝试 imagemagick(也可以轻松调整不同尺寸的大小):
convert in.png -background black -alpha remove -alpha off -resize 1024x1024 out.png
回答by Toland Hon
Just got the the following error when trying to upload my app to the iTunes app store:
尝试将我的应用上传到 iTunes 应用商店时出现以下错误:
iTunes Store Operations Failed
ERROR ITMS-90717: "Invalid App Store Icon. The App Store icon in the asset catalog in 'MyApp.app' can't be transparent nor contain an alpha channel."
iTunes Store 操作失败
错误 ITMS-90717:“无效的 App Store 图标。‘MyApp.app’资产目录中的 App Store 图标不能是透明的,也不能包含 alpha 通道。”
I confirmed that my app store icons did include the alpha channel by locating the asset in Finder and looking up its info (?+i). Underneath More info, it showed:
我通过在 Finder 中找到资产并查找其信息 (?+i) 来确认我的应用商店图标确实包含 alpha 通道。在更多信息下方,它显示:
Alpha channel: Yes
Alpha 通道:是
Found the solution above to use Preview to remove the alpha channel by exporting it with the Alpha checkbox unchecked, but figured a way to batch export them since I had 18 assets I needed to strip the alpha channel from.
找到了上面的解决方案,通过在未选中 Alpha 复选框的情况下导出它来使用 Preview 来删除 Alpha 通道,但是想出了一种批量导出它们的方法,因为我有 18 个资产需要从中剥离 Alpha 通道。
The way I got batch exporting to work was to select all my app icon assets in finder > right click > open (or open with preview)
我批量导出工作的方式是在finder>右键单击>打开(或打开预览)中选择我的所有应用程序图标资产
All of the assets will now appear in the same window. Select all (?+a), and then select File > Export Selected Images… > Expand Options > uncheck the Alpha checkbox > Choose (your destination folder)
所有资产现在都将出现在同一窗口中。全选 (?+a),然后选择 File > Export Selected Images... > Expand Options > 取消选中 Alpha 复选框 > 选择(您的目标文件夹)
Done! All your images are now exported with the alpha channel stripped off.
完毕!现在,您的所有图像都将在去除 alpha 通道的情况下导出。
回答by Hynek
To remove alpha channel from png:
要从 png 中删除 alpha 通道:
on Mac: Preview version 9.0 (macOS Sierra) can remove the alpha channel if you export or save the image.
在 Mac 上:如果您导出或保存图像,预览版 9.0 (macOS Sierra) 可以删除 Alpha 通道。
Preview version 10.0 (944.2) (macOS High Sierra) does not remove the alpha channel. Both Export and/or Save does not remove the alpha channel from the image.
预览版 10.0 (944.2) (macOS High Sierra) 不会删除 Alpha 通道。导出和/或保存都不会从图像中删除 Alpha 通道。
回答by Ali Nasserzadeh
Having run into the same problem in the context of Flutter applications, I have dedicated a simple website for this task where you can remove alpha channels of images:
在 Flutter 应用程序的上下文中遇到了同样的问题,我专门为此任务创建了一个简单的网站,您可以在其中删除图像的 alpha 通道:
Basically I run ImageMagick using Web Assembly directly in the browser, so none of your images are uploaded and you don't need any other tools like Gimp.
基本上,我直接在浏览器中使用 Web Assembly 运行 ImageMagick,因此您的任何图像都不会上传,并且您不需要任何其他工具,例如 Gimp。
回答by vboombatz
the alpha check box is no longer there in preview
预览中不再存在 alpha 复选框