Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is an extension method in VB.NET for the Image Class</p> <pre class="lang-vb prettyprint-override"><code>Imports System.Runtime.CompilerServices Namespace Extensions ''' &lt;summary&gt; ''' Extensions for the Image class. ''' &lt;/summary&gt; ''' &lt;remarks&gt;Several usefull extensions for the image class.&lt;/remarks&gt; Public Module ImageExtensions ''' &lt;summary&gt; ''' Extends the image class so that it is easier to get a thumbnail from an image ''' &lt;/summary&gt; ''' &lt;param name="Input"&gt;Th image that is inputted, not really a parameter&lt;/param&gt; ''' &lt;param name="MaximumSize"&gt;The maximumsize the thumbnail must be if keepaspectratio is set to true then the highest number of width or height is used and the other is calculated accordingly. &lt;/param&gt; ''' &lt;param name="KeepAspectRatio"&gt;If set false width and height will be the same else the highest number of width or height is used and the other is calculated accordingly.&lt;/param&gt; ''' &lt;returns&gt;A thumbnail as image.&lt;/returns&gt; ''' &lt;remarks&gt; ''' &lt;example&gt;Can be used as such. ''' &lt;code&gt; ''' Dim _NewImage as Image ''' Dim _Graphics As Graphics ''' _Image = New Bitmap(100, 100) ''' _Graphics = Graphics.FromImage(_Image) ''' _Graphics.FillRectangle(Brushes.Blue, New Rectangle(0, 0, 100, 100)) ''' _Graphics.DrawLine(Pens.Black, 10, 0, 10, 100) ''' Assert.IsNotNull(_Image) ''' _NewImage = _Image.ToThumbnail(10) ''' &lt;/code&gt; ''' &lt;/example&gt; ''' &lt;/remarks&gt; &lt;Extension()&gt; _ Public Function ToThumbnail(ByVal Input As Image, ByVal MaximumSize As Integer, Optional ByVal KeepAspectRatio As Boolean = True) As Image Dim ReturnImage As Image Dim _Callback As Image.GetThumbnailImageAbort = Nothing Dim _OriginalHeight As Double Dim _OriginalWidth As Double Dim _NewHeight As Double Dim _NewWidth As Double Dim _NormalImage As Image Dim _Graphics As Graphics _NormalImage = New Bitmap(Input.Width, Input.Height) _Graphics = Graphics.FromImage(_NormalImage) _Graphics.DrawImage(Input, 0, 0, Input.Width, Input.Height) _OriginalHeight = _NormalImage.Height _OriginalWidth = _NormalImage.Width If KeepAspectRatio = True Then If _OriginalHeight &gt; _OriginalWidth Then If _OriginalHeight &gt; MaximumSize Then _NewHeight = MaximumSize _NewWidth = _OriginalWidth / _OriginalHeight * MaximumSize Else _NewHeight = _OriginalHeight _NewWidth = _OriginalWidth End If Else If _OriginalWidth &gt; MaximumSize Then _NewWidth = MaximumSize _NewHeight = _OriginalHeight / _OriginalWidth * MaximumSize Else _NewHeight = _OriginalHeight _NewWidth = _OriginalWidth End If End If Else _NewHeight = MaximumSize _NewWidth = MaximumSize End If ReturnImage = _ _NormalImage.GetThumbnailImage(Convert.ToInt32(_NewWidth), Convert.ToInt32(_NewHeight), _Callback, _ IntPtr.Zero) _NormalImage.Dispose() _NormalImage = Nothing _Graphics.Dispose() _Graphics = Nothing _Callback = Nothing Return ReturnImage End Function End Module End Namespace </code></pre> <p>Sorry the code tag doesn't like vb.net code.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload