我一张GIF的无背景图片,生成缩略图后,结果背景变成黑色了,
代码如下
oriImg = System.Drawing.Image.FromStream(picpath.PostedFile.InputStream); 
newImg = oriImg.GetThumbnailImage(intFeThumbWidth, intFeThumbWidth * oriImg.Height/oriImg.Width,null,new System.IntPtr(0)); 
请问有什么办法生成的缩略图还是的原图一样,没有背景色呀.

解决方案 »

  1.   

    <script language="VB" runat="server">
      Sub Page_Load(sender As Object, e As EventArgs)
      Dim image,aNewImage As System.Drawing.Image
      dim width,height,newwidth,newheight as integer
      Dim callb As System.Drawing.Image.GetThumbnailImageAbort
      '生成缩略图
      image=System.Drawing.Image.FromFile(Server.MapPath("classpic/"+"rs1.jpg"))
      width=image.Width
      height=image.height
      if width>height then
      newwidth=110
      newheight=image.height/image.Width*newwidth
      else
      newheight=110
      newwidth=image.Width/image.height*newheight
      end if
      aNewImage=image.GetThumbnailImage(newwidth,newheight,callb,new System.IntPtr())
      aNewImage.Save(Server.MapPath("smallpic/"+"rs1.gif"))
      image.Dispose()
      End Sub
      </script>
      

  2.   

    Public Sub GetThumbNail(ByVal UpFile As HttpPostedFile, ByVal iWidth As Integer, ByVal iheight As Integer, ByVal blnGetFromFile As Boolean, ByVal IcoPath As String)
            Try
                If UpFile.ContentLength = 0 Then
                    Exit Sub
                Else
                    Dim oImg As Image
                    Dim FileByteArray(UpFile.ContentLength) As Byte       '图象文件临时储存Byte数组
                    Dim StreamObject As Stream = UpFile.InputStream       '建立数据流对像  
                    '读取图象文件数据,FileByteArray为数据储存体,0为数据指针位置、FileLnegth为数据长度  
                    StreamObject.Read(FileByteArray, 0, UpFile.ContentLength)
                    If blnGetFromFile Then
                        oImg = oImg.FromFile(UpFile.FileName)
                    Else
                        oImg = oImg.FromStream(StreamObject)
                    End If
                    oImg = oImg.GetThumbnailImage(iWidth, iheight, Nothing, (New IntPtr).Zero)
                    Dim strFileExt As String = UpFile.FileName.Substring(UpFile.FileName.LastIndexOf("."))
                    '保存到本地
                    oImg.Save(IcoPath & strFileExt, GetImageType(UpFile.ContentType))
                End If
            Catch ex As Exception
                Console.WriteLine(ex.Message)
                Exit Sub
            End Try
        End Sub