2008-09-20 66 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中,你可以在任何項目在未來需要這些功能!)