当前位置: 代码迷 >> ASP >> aspjpeg 怎么把 gif 图片的背景色去掉?背景变成透明
  详细解决方案

aspjpeg 怎么把 gif 图片的背景色去掉?背景变成透明

热度:830   发布时间:2012-02-08 19:52:21.0
aspjpeg 如何把 gif 图片的背景色去掉?背景变成透明?
这个问题是我在另一个求助帖,总结思考后换了个思路提出。

就是一个 GIF 图片, 背景是纯色,比如: &Hffffff , aspjpeg 能把这个背景色去掉?变成透明的 GIF 吗?



原提是:
现有背景透明的GIF图片,因为网站需要,所以这个GIF需要背景透明,能显示再低一层的图片。
现在这个GIF图片,要批量加上文字,但是要保持GIF背景的透明。

我现在用aspjpeg来做,文字是加上了, 但是背景也变成了白色,不透明了。
网址:http://topic.csdn.net/u/20111226/21/b60db57c-53e1-4f95-9154-88bf75375eb0.html?seed=395661076&r=77082295#r_77082295


------解决方案--------------------
对你我真不知道该怎么说你,我上次告诉你那函数,叫你加上水印功能就好了,你自己不测试,就非说不能用,我就测试了下,才发现你根本就没动手去做,去测试

以下是我测试的代码,一点问题没有

VBScript code
<%
Function BuildSmallPic(m_path1, m_path2, n_MaxWidth, n_MaxHeight, n_Quality)
    Err.Clear
    'On Error Resume Next
    '检 查 组件是否已经注册
    Dim AspJpeg
    Set AspJpeg = Server.Createobject("Persits.Jpeg")
    If Err.Number <> 0 Then
        Err.Clear
        BuildSmallPic = "组件安装不正确!"
        Exit Function
    End If
    
    
    
    ' 按 比例取得缩略图宽度和高度
    Dim n_picWidth, n_picHeight 
    Dim n_newWidth, n_newHeight 
    Dim extn
   
    extn = split(m_path1, ".")
    select case extn(ubound(extn))
        case "jpg"
            AspJpeg.Open Server.MapPath(m_path1)
            n_picWidth = AspJpeg.Width
            n_picHeight = AspJpeg.Height
            
            if n_picWidth > n_MaxWidth or n_picHeight > n_MaxHeight then
                if n_picWidth/n_picHeight >= n_MaxWidth/n_MaxHeight then
                    AspJpeg.Width = n_MaxWidth
                       AspJpeg.Height = n_MaxWidth/(n_picWidth/n_picHeight)
                else
                    AspJpeg.Width = n_picWidth/n_picHeight*n_MaxHeight
                    AspJpeg.Height = n_MaxHeight
                end if
            else
                AspJpeg.Width = n_picWidth
                AspJpeg.Height = n_picHeight
            end if
            AspJpeg.Quality = n_Quality
            
            Gif.Save Server.MapPath(m_path2) '保存
            If Err.Number <> 0 Then
                Err.Clear
                BuildSmallPic = "Error_03"
                Exit Function
            End If
        
            Set AspJpeg = Nothing
        case "gif"
            Set Gif = AspJpeg.Gif
            Gif.Open Server.MapPath(m_path1)
            n_picWidth = Gif.Width
            n_picHeight = Gif.Height
            
            if n_picWidth > n_MaxWidth or n_picHeight > n_MaxHeight then
                if n_picWidth/n_picHeight >= n_MaxWidth/n_MaxHeight then
                    Gif.Resize n_MaxWidth, n_MaxWidth/(n_picWidth/n_picHeight)
                else
                    Gif.Resize n_picWidth/n_picHeight*n_MaxHeight, n_MaxHeight
                end if
            else
                Gif.Resize n_picWidth, n_picHeight
            end if
            Gif.DisposalMethod =2 
               Gif.PenColor = 235
               Gif.FontFamily = "Arial"  
               Gif.FontSize = 8 
               Gif.PrintText 20,10, "www.Chinmo.net"            
            Gif.Save Server.MapPath(m_path2) '保存
            If Err.Number <> 0 Then
                Err.Clear
                BuildSmallPic = "Error_03"
                Exit Function
            End If
        
            Set AspJpeg = Nothing
            Set Gif = Nothing
        case "png"
            AspJpeg.Open Server.MapPath(m_path1)
            
            n_picWidth = AspJpeg.Width
            n_picHeight = AspJpeg.Height
            
            AspJpeg.PreserveAspectRatio = True
            
            if n_picWidth > n_MaxWidth or n_picHeight > n_MaxHeight then
                if n_picWidth/n_picHeight >= n_MaxWidth/n_MaxHeight then
                    AspJpeg.Width = n_MaxWidth
                       AspJpeg.Height = n_MaxWidth/(n_picWidth/n_picHeight)
                else
                    AspJpeg.Width = n_picWidth/n_picHeight*n_MaxHeight
                       AspJpeg.Height = n_MaxHeight
                end if
            else
                AspJpeg.Width = n_picWidth
                AspJpeg.Height = n_picHeight
            end if
            
            AspJpeg.PNGOutput = True
            Gif.Save Server.MapPath(m_path2)
        case else
    end select
    
    
    If Err.Number <> 0 Then
        BuildSmallPic = "Error_Other"
        Err.Clear
    End If
    BuildSmallPic = s_BuildBasePath & s_BuildFileName
End Function
BuildSmallPic "yt/ceshi.gif", "images/ceshi.gif", 100, 100, 90
%>