powerpoint - Cropping a fixed area from a picture in VBA -


i create powerpoint vba script inserts pictures such cropped fixed size relative top , left of image. starting point, take following vba script:

sub insert_traverse_1()     dim opic shape     set opic = activewindow.view.slide.shapes.addpicture("\\nlamvfs00065\homes\nlkpec\newpic.png", false, true, 0, 0, -1, -1)         opic.pictureformat.cropleft = 110         opic.pictureformat.croptop = 85         opic.pictureformat.cropright = 16         opic.pictureformat.cropbottom = 55         opic.height = 7.5 * 72         opic.left = 0 * 72         opic.top = 0 * 72         opic.zorder msosendtoback end sub 

this vba script inserts picture 'newpic.png', represents screen grab of window, , crops fixed amount (representing borders of window) edges. works fine if want indeed entire window.

now, however, i'd make vba script inserts part of window, has fixed size , position relative top left of window. problem, however, "cropright" , "cropbottom" dependent on size of window. i've tried following:

sub insert_well_tie_tz()     dim opic shape     set opic = activewindow.view.slide.shapes.addpicture("\\nlamvfs00065\homes\nlkpec\newpic.png", false, true, 0, 0, -1, -1)         ppi = 72                    'points per inch (=72 always)         dpi = 96                    'dots per inch (=96 screen)         owidth = opic.width         'width of shape in pixels         oheight = opic.height       'height of shape in pixels         owidthpoints = owidth * ppi / dpi   'width of shape in points         oheightpoints = oheight * ppi / dpi 'height of shape in points         l = 182                     'number of points crop left         t = 394                     'number of points crop top          opic.pictureformat.cropleft = l         opic.pictureformat.cropright = owidthpoints - l + 665         opic.pictureformat.croptop = t         opic.pictureformat.cropbottom = oheightpoints - t + 318         ' opic.height = 7.5 * 72         opic.left = 0 * 72         opic.top = 0 * 72         opic.zorder msosendtoback end sub 

as understand it, "cropleft" etc. expressed in units of points (=1/72nd of inch) whereas ".width" , ".height" properties expressed in pixels; that's why i've included conversion factor of 72/96 convert width of picture pixels points.

the idea to, taking account width of image in amount crop right, part of image cropped should same regardless of size of window. find, however, not case, , have scaling factor wrong. can see problem?

if intent crop 182 points left, keep next 665 points, , crop else right, need change 1 sign, replacing:

opic.pictureformat.cropright = owidthpoints - l + 665 

with

opic.pictureformat.cropright = owidthpoints - l - 665 

the algebra is: owidthpoints = leftcrop + middle + rightcrop, so

rightcrop = owidthpoints - leftcrop - middle 

in similar fashion, replace:

opic.pictureformat.cropbottom = oheightpoints - t + 318 

with

opic.pictureformat.cropbottom = oheightpoints - t - 318 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -