I lang tid har samarbejdsbranchen fokuseret på at forbedre enhedsfunktioner – bedre kameraer, klarere lyd og smartere software. Men den virkelige forvandling handler ikke om funktioner.
Følgende funktion returnerer et resized billede, hvis du giver den billedet (pSourceBitmap), som skal resizes, samt den nye bredde (pNewWidth). Højden beregnes automatisk, så størrelsesforholdet bevares:
Public Function ResizeBitmap(ByVal pSourceBitmap As Bitmap, _ ByVal pNewWidth As Int32) As Bitmap Dim lNewHeight As Int32 lNewHeight = CType(pSourceBitmap.Height * (pNewWidth / pSourceBitmap.Width), Int32) Dim lResizedBitmap As New Bitmap(pNewWidth, pNewHeight) Dim lGraphics As Graphics = Graphics.FromImage(lResizedBitmap) lGraphics.DrawImage(pSourceBitmap, 0, 0, pNewWidth, pNewHeight) Return lResizedBitmap End Function
Her er en anden udgave, hvor du giver den højden, og bredden beregnes automatisk:
Public Function ResizeBitmap(ByVal pSourceBitmap As Bitmap, _ ByVal pNewWidth As Int32) As Bitmap Dim lNewHeight As Int32 lNewHeight = CType(pSourceBitmap.Height * (pNewWidth / pSourceBitmap.Width), Int32) Dim lResizedBitmap As New Bitmap(pNewWidth, pNewHeight) Dim lGraphics As Graphics = Graphics.FromImage(lResizedBitmap) lGraphics.DrawImage(pSourceBitmap, 0, 0, pNewWidth, pNewHeight) Return lResizedBitmap End Function
Argh! Jeg prøver lige igen. De skulle se således ud :o)
Public Function ResizeBitmap(ByVal pSourceBitmap As Bitmap, _ ByVal pNewWidth As Int32) As Bitmap Dim lNewHeight As Int32 lNewHeight = CType(pSourceBitmap.Height * (pNewWidth / pSourceBitmap.Width), Int32) Dim lResizedBitmap As New Bitmap(pNewWidth, lNewHeight) Dim lGraphics As Graphics = Graphics.FromImage(lResizedBitmap) lGraphics.DrawImage(pSourceBitmap, 0, 0, pNewWidth, lNewHeight) Return lResizedBitmap End Function
Her er den anden udgave:
Public Function ResizeBitmap(ByVal pSourceBitmap As Bitmap, _ ByVal pNewHeight As Int32) As Bitmap Dim lNewWidth As Int32 lNewWidth = CType(pSourceBitmap.Width * (pNewHeight / pSourceBitmap.Height), Int32) Dim lResizedBitmap As New Bitmap(lNewWidth, pNewHeight) Dim lGraphics As Graphics = Graphics.FromImage(lResizedBitmap) lGraphics.DrawImage(pSourceBitmap, 0, 0, lNewWidth, pNewHeight) Return lResizedBitmap End Function
Du kan angive dem som nu engang understøttes af .NET frameworket -- hvilke det helt præcis er, ved jeg faktisk ikke, men JPG er i hvert fald én af dem. Prøv dig frem :-)
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.