SHARE
TWEET

Untitled

a guest Dec 9th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub ConstrainImage(filePath as String)
  2.     Dim img As Image = Image.FromFile(filePath)
  3.     Dim imgX As Integer = img.Width
  4.     Dim imgXLim As Integer = 350
  5.     Dim imgY As Integer = img.Height
  6.     Dim imgYLim As Integer = 100
  7.     Dim imgXdiff As Integer = imgX - imgXLim
  8.     Dim imgYdiff As Integer = imgY - imgYLim
  9.     Dim growFactor As Double
  10.     Dim shrinkFactor As Double
  11.     .PageSetup.DifferentFirstPageHeaderFooter = 0
  12.     With .Sections(1).Headers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Shapes
  13.         'Check to see if the image is too big
  14.         If imgX > imgXLim Or imgY > imgYLim Then
  15.             If imgXdiff > imgYdiff Then
  16.                 shrinkFactor = (imgXLim / imgX) - ((imgXLim / imgX) Mod 0.1) 'Decimal Floor
  17.             ElseIf imgYdiff > imgXdiff Then
  18.                 shrinkFactor = (imgYLim / imgY) - ((imgYLim / imgY) Mod 0.1) 'Decimal Floor
  19.             End If
  20.             imgX = imgX * shrinkFactor
  21.             imgY = imgY * shrinkFactor
  22.             'If the image isn't too big, check to see if it's too small
  23.         ElseIf imgX < imgXLim Or imgY < imgYLim Then
  24.             If imgXdiff > imgYdiff Then
  25.                 growFactor = (imgXLim / imgX) - ((imgXLim Mod imgX) / imgX) 'Floor
  26.             ElseIf imgYdiff > imgXdiff Then
  27.                 growFactor = (imgYLim / imgY) - ((imgYLim Mod imgY) / imgY) 'Floor
  28.             End If
  29.             imgX = imgX * growFactor
  30.             imgY = imgY * growFactor
  31.         End If
  32.         With .AddPicture(filePath)
  33.             .Width = imgX
  34.             .Height = imgY
  35.         End With
  36.     End With
  37. End Sub
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top