2008-09-20 67 views
8

我想以编程方式在图像上创建光泽效果,有点像在Web更新至2.0 Beta时采用Apple设计的设计。创建一个闪亮的图形/光泽效果

本质上这:

example icons http://nhc.hcmuns.googlepages.com/web2_icons.jpg

现在,我在这里看到两种方法:我创建一个与光泽效果的Alpha通道一个图像,然后我就结合输入和光泽阿尔法图标创造这个。

第二种方法:在代码中创建Alpha Gloss图像,然后将其与输入图形合并。

我更喜欢第二种解决方案,但我不是一个图形人员,我不知道算法是如何创建这样的效果。有人能给我一些指针*为我实际上在这里看?有没有一个名字叫“光泽算法”?甚至是.net实现已经?

*不,不是指针的those type

+0

好指针玩笑。 – TonyOssa 2008-09-21 00:59:12

+0

这里是[一个Photoshop教程](http://www.redcultur.com/silkypixel/2008/01/11/tutorial-on-how-to-make-an-iphone-esque-gui-icon/),显示过程 – 2008-09-20 23:46:55

+0

您的第一个示例图片已损坏,链接已死? – rene 2016-06-01 13:35:34

回答

8

我可以用图解来解释这种效果。

  1. 在3 *图标的大小周围创建图像。

  2. 在此图片中,创建一个圆圈,其中(图标的高度)<半径< 2 *(图标的高度)。

  3. 用阿尔法混合/透明度(白色)例如10%填充圆。

  4. 将圆形图像裁剪成与您的图标大小相同的新图像,圆形的中心位于查看区域外侧,但向上移动了较小图像高度的1/2。

如果您然后将此图像叠加到原始图标上,效果应该与上面的图标大致相同。如果您热衷于此,应该可以使用imagemagick,或者您可以选择其中一种图形API,具体取决于您要使用的语言。从上面的步骤来看,它应该是直接编程式的。

17

谢谢德文!这是我的C#代码来实现你的建议。它工作得很好。把它变成一个社区拥有的Wiki帖子,如果有人喜欢添加一些代码,请随意编辑它。

example

(示例使用Alpha和不同价值观的曝光比下面的代码)

Image img = Image.FromFile("rss-icon.jpg"); 
pictureBox1.Image = AddCircularGloss(img, 30,25,255,255,255); 

public static Image AddCircularGloss(Image inputImage, int exposurePercentage, int transparency, int fillColorR, int fillColorG, int fillColorB) 
{ 
    Bitmap outputImage = new Bitmap(inputImage); 
    using (Graphics g = Graphics.FromImage(outputImage)) 
    { 
     using (Pen p = new Pen(Color.FromArgb(transparency, fillColorR, fillColorG, fillColorB))) 
     { 
      // Looks jaggy otherwise 
      g.SmoothingMode = SmoothingMode.HighQuality; 
      g.CompositingQuality = CompositingQuality.HighQuality; 
      int x, y; 

      // 3 * Height looks best 
      int diameter = outputImage.Height * 3; 
      double imgPercent = (double)outputImage.Height/100; 
      x = 0 - outputImage.Width; 

      // How many percent of the image to expose 
      y = (0 - diameter) + (int)(imgPercent * exposurePercentage); 
      g.FillEllipse(p.Brush, x, y, diameter, diameter); 
     } 
    } 
    return outputImage; 
} 

(约翰的建议后变了,我不能,虽然处理位图,这必须由完成函数的调用者)

3

响应C#代码......总体而言,做好成像工作。过去我必须使用我的一些应用程序来做类似的事情。

然而,一条建议是:.NET中的所有图形对象都基于Windows GDI +原语。这意味着这些对象需要正确的处理来清理它们的非内存资源,就像文件句柄或数据库连接一样。您需要稍微调整一下代码以正确支持该代码。

所有的GDI +对象都实现了IDisposable接口,使它们在using语句中起作用。同样考虑重写代码以下:

// Experiment with this value 
int exposurePercentage = 40; 

using (Image img = Image.FromFile("rss-icon.jpg")) 
{ 
    using (Graphics g = Graphics.FromImage(img)) 
    {  
     // First Number = Alpha, Experiment with this value. 
     using (Pen p = new Pen(Color.FromArgb(75, 255, 255, 255))) 
     { 
      // Looks jaggy otherwise 
      g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; 

      int x, y; 

      // 3 * Height looks best 
      int diameter = img.Height * 3; 
      double imgPercent = (double)img.Height/100; 
      x = 0 - img.Width; 

      // How many percent of the image to expose 
      y = (0 - diameter) + (int)(imgPercent * exposurePercentage); 

      g.FillEllipse(p.Brush, x, y, diameter, diameter); 

      pictureBox1.Image = img; 
     } 
    } 
} 

(请记住,不像大多数我的样本,我还没有机会来编译和测试这个...它意味着更多的结构化样本用于确保没有资源泄漏的代码,而不是作为成品,也许有更好的方法来抽象/结构化,并强烈地考虑这样做 - 把它抛弃在一个图形库DLL中,你可以在任何项目在未来需要这些功能!)