在MATLAB中使用.gif动画进行一些测试时,我意识到我无法读取gif的透明度.
例:
如果我做
[img,cmap]=imread('Finnandjake.gif');
Run Code Online (Sandbox Code Playgroud)
img是4D,冗余的第三维(怪异).在挤压它之后(img=squeeze(img);),如果我显示它(imshow(img(:,:,30),cmap)):
透明度消失了,使用图像中的另一种颜色作为背景,从而删除了特征.然而
[img,cmap,alpha]=imread('Finnandjake.gif');
Run Code Online (Sandbox Code Playgroud)
返回一个空的alpha.显然alpha的信息在图像的某个地方,我怎样才能在MATLAB中读取它?
我已经建立了一个程序,可以通过它插入注释和图像的标题,System.Image.Drawing因此,我很难尝试用添加了注释和标题的文件覆盖现有的Jpeg文件,但是在遇到错误时删除文件,因此我不确定该如何处理该文件,但是由于这种情况我处理得太早了,所以我无法保存该文件,但由于现有文件名而无法保存没有被删除,所以我现在停留在中间。
这是我的代码:
public string EditComment(string OriginalFilepath, string newFilename)
{
image = System.Drawing.Image.FromFile(OriginalFilepath);
PropertyItem propItem = image.PropertyItems[0];
using (var file = System.Drawing.Image.FromFile(OriginalFilepath))
{
propItem.Id = 0x9286; // this is the id for 'UserComment'
propItem.Type = 2;
propItem.Value = System.Text.Encoding.UTF8.GetBytes("HelloWorld\0");
propItem.Len = propItem.Value.Length;
file.SetPropertyItem(propItem);
PropertyItem propItem1 = file.PropertyItems[file.PropertyItems.Count() - 1];
file.Dispose();
image.Dispose();
string filepath = Filepath;
if (File.Exists(@"C:\Desktop\Metadata"))
{
System.IO.File.Delete(@"C:\Desktop\Metadata");
}
string newFilepath = filepath + newFilename;
file.Save(newFilepath, ImageFormat.Jpeg);//error appears here
return filepath;
}
}
Run Code Online (Sandbox Code Playgroud)
显示的错误是:
System.Drawing.dll中发生类型'System.ArgumentException'的异常,但未在用户代码中处理
附加信息:参数无效。