Click here to Skip to main content
15,885,546 members
Articles / Multimedia / GDI+

Color Scale Filter

Rate me:
Please Sign up or sign in to vote.
5.00/5 (6 votes)
17 Jul 2007CPOL4 min read 59.7K   2.2K   24  
Grayscale and color scale filters.
Imports System.Drawing
Imports System.Drawing.Drawing2D

Public Class ResizeFilter
   Inherits BasicFilter

   ''' <summary>
   ''' Width of new image.
   ''' </summary>
   Private _width As Integer = 0
   ''' <summary>
   ''' Height of new image.
   ''' </summary>
   Private _height As Integer = 0

   ''' <summary>
   ''' Get or set output image width.
   ''' </summary>
   Public Property Width() As Integer
      Get
         Return _width
      End Get
      Set(ByVal value As Integer)
         _width = value
      End Set
   End Property

   ''' <summary>
   ''' Get or set output image height.
   ''' </summary>
   Public Property Height() As Integer
      Get
         Return _height
      End Get
      Set(ByVal value As Integer)
         _height = value
      End Set
   End Property

   ''' <summary>
   ''' Execute resize of given image.
   ''' </summary>
   ''' <param name="img">Image to be resized.</param>
   ''' <returns>Resized image.</returns>
   Public Overrides Function ExecuteFilter(ByVal img As System.Drawing.Image) As System.Drawing.Image
      If ((img.Width <= 0) Or (img.Height <= 0) Or _
               (_width <= 0) Or (_height <= 0)) Then
         Return img
      End If
      Dim result As Bitmap = New Bitmap(_width, _height)
      Dim g As Graphics = Graphics.FromImage(result)
      g.InterpolationMode = Interpolation
      g.DrawImage(img, 0, 0, _width, _height)
      Return result
   End Function

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer
Slovenia Slovenia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions