这几天折腾一个IOS应用的Icon,一个版本就要生成好几种规格分辨率的Icon,起初使用PS什么的一个一个生成,后来Icon改一版本又得重新生成一次,很是费劲,干脆自己写个程序来干这活得了,思路很简单,先导入一张大图(注意:这张图必须大于等于512*512),然后生成对应像素的小图,最后保存出来。
这里我使用C#来写,主要是考虑到C#里Bitmap类有一个GetthumbnailImage()方法很容易实现图像缩小,经过简单的包装实现图像裁剪的函数如下:
/// <summary> /// 获取等比例缩放图片的方法 /// </summary> /// <param name="imgPath">待缩放图片路径</param> /// <param name="savePath">缩放图片保存路径</param> /// <param name="format">缩放图片保存的格式</param> /// <param name="scaling">要保持的宽度或高度</param> /// <returns></returns> public bool Getthumbnail(string imgPath,string savePath,ImageFormat format,int scaling) { try { using (Bitmap myBitmap = new Bitmap(imgPath))//导入图像 { using (Image mythumbnail = myBitmap.GetthumbnailImage(scaling,scaling,() => { return false; },IntPtr.Zero))//生成小图 { mythumbnail.Save(savePath,format);//导出小图 } } return true; } catch { return false; } }
别的不多说了,直接上代码:
string path = "";//生成图片保存的路径 private voID btnopen_Click(object sender,EventArgs e)//打开图片按钮 { openfileDialog1.Filter = "PNG Image|*.png"; openfileDialog1.Title = "打开"; openfileDialog1.Multiselect = false; openfileDialog1.CheckfileExists = false; openfileDialog1.filename = string.Empty; openfileDialog1.ShowDialog(); txtPath.Text = openfileDialog1.filename; path = openfileDialog1.filename.Substring(0,openfileDialog1.filename.Length - openfileDialog1.Safefilename.Length); path = path + DateTime.Now.ToString("yyyyMMddhhmmss") + "\"; //txtPath.Text = path; } private voID btnBuilder_Click(object sender,EventArgs e)//生成按钮 { if (txtPath.Text.Equals("") || path.Equals("")) return; if (Directory.CreateDirectory(path) != null) { bool flag = true; flag = flag && Getthumbnail(txtPath.Text,path + "iTunesArtwork",ImageFormat.Png,512);//iTunesArtwork flag = flag && Getthumbnail(txtPath.Text,path + "Icon@2x.png",114);//Application Icon for iPhone (retina display) flag = flag && Getthumbnail(txtPath.Text,path + "Icon-72@2x.png",114);//Application Icon for the new iPad (retina display) flag = flag && Getthumbnail(txtPath.Text,path + "Icon-Small-50@2x.png",100);//Settings/Spotlight icon for iPad flag = flag && Getthumbnail(txtPath.Text,path + "Icon-72.png",72);//Application Icon for the iPad flag = flag && Getthumbnail(txtPath.Text,path + "Icon-Small@2x.png",58);//Settings/Spotlight icon for iPhone (retina display) flag = flag && Getthumbnail(txtPath.Text,path + "Icon.png",57);//Application Icon icon for iPhone flag = flag && Getthumbnail(txtPath.Text,path + "Icon-Small-50.png",50);//Settings/Spotlight icon for iPad flag = flag && Getthumbnail(txtPath.Text,path + "Icon-Small.png",29);//Settings/Spotlight icon for iPhone if (flag) { MessageBox.Show("ICON生成完毕!","成功",MessageBoxbuttons.OK,MessageBoxIcon.information); System.Diagnostics.Process.Start("Explorer.exe",path); } else { MessageBox.Show("出错啦!","错误",MessageBoxIcon.Error); } } }
运行效果图:
生成的Icon:
程序简陋不过最终实现了目的,欢迎拍砖,最后附上工具源码:http://download.csdn.net/detail/wangqiuyun/4510176
总结以上是内存溢出为你收集整理的IOS应用开发Icon规格自动裁剪器(C#)全部内容,希望文章能够帮你解决IOS应用开发Icon规格自动裁剪器(C#)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)