zoukankan      html  css  js  c++  java
  • Applying a Color Wash to Images

    By Gavin Harriss

        最近看到了这篇文章 很有意思     能不能用这个来实现 用户自定义的网站风格呢   有时间做个试验
  • Download source files - 8 Kb
  • Download demo project - 27 Kb
  • Not coming from a graphics based background my method may not be the best solution, but it seems to work just fine.

    To apply a color wash a base RGB color value is decided upon as a reference point and an adjustment value calculated for the color wash’s RGB value to be applied. This adjustment is calculated for each of the red, green and blue components. Once this is done each of the image’s pixel’s red, green and blue components is adjusted by the calculated amount to produce the color wash.

    Each of the RGB components of a color can be represented by values from 0 to 255, so taking the mid point of 127 as the base reference point and taking the desired RGB component values of the color wash to apply we can calculate the adjustments to be made to each pixel.

    Adjusting red, green and blue component values can sometimes result in a value outside the allowed range of 0 to 255; in these cases we compromise and simply use the minimum or maximum value allowed as appropriate.

    The table below illustrates how values are adjusted:

      Hex Value Red Green Blue Color
     
    Base Color 7F7F7F 127 127 127
    Color Wash To Apply 1280AA 18 128 170
    Adjustment Value To Use   18 – 127 = -109 128 – 127 = 1 170 – 127 = 43  
     
    Example Pixel 1 Original Color A5A5A5 165 165 165
    Example Pixel 1 Washed Color 38A6D0 165 – 109 = 56 165 + 1 = 166 165 + 43 = 208
     
    Example Pixel 2 Original Color 545454 84 84 84
    Example Pixel 2 Washed Color 00557F 84 – 109 = -25 = 0 * 84 + 1 = 85 84 + 43 = 127
     
    Example Pixel 3 Original Color 2E2E2E 46 46 46
    Example Pixel 3 Washed Color 002F59 46 – 109 = -63 = 0 * 46 + 1 = 47 46 + 43 = 89
    * The value is less than the minimum allowed so we use the minimum instead.


    Using the Code

    To use this functionality in your projects simply download the source files accompanying this article, drop GavDev.Image.dll into the bin directory of your project then make a reference to the class library GavDev.Image.dll. There’s two interfaces provided for your convenience:

    The first interface accepts individual red, green and blue values:

    ColorWashImage(ByVal FilePathOriginal As String,
       ByVal FilePathNew As String,
       ByVal Red As Integer,
       ByVal Green As Integer,
       ByVal Blue As Integer,
       Optional ByVal Quality As Integer = 100,
       Optional ByVal Encoding As String = "image/jpeg")
    

    The second interface allows you to pass a single combined 6 digit hexadecimal RGB value in as the color wash value:

    ColorWashImage(ByVal FilePathOriginal As String,
       ByVal FilePathNew As String,
       ByVal HexRGBValue As String,
       Optional ByVal Quality As Integer = 100,
       Optional ByVal Encoding As String = "image/jpeg")
    

    Both interfaces expect parameters FilePathOriginal, the physical location of the original grayscale image and FilePathNew, the physical location to save the resulting color washed image. Optional parameters are also present to dictate the quality and encoding of the output images.

    Below is an example of the class being used as it is in the accompanying demo project:

    GavDev.Image.Manipulate.ColorWashImage(Server.MapPath("Images/Gav.jpg"),
     Server.MapPath("Images/Gav." & txtColorWash.Text & ".jpg"),
     txtColorWash.Text)
    
查看全文
  • 相关阅读:
    MySQL-07-新增数据
    MySQL-06-表结构修改
    LVM-创建与增容
    Zabbix-4.0.34-安装配置
    MySQL-05-约束
    lnmp(部署在一台上面)
    shell脚本概念和yum仓库的搭建
    awk命令基础和进阶
    shell
    awk
  • 原文地址:https://www.cnblogs.com/stone/p/117908.html
  • Copyright © 2011-2022 走看看