473,324 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Inserting and Resizing and image into Word

I have some images stored locally that i retrieve and insert into a word
document that is programatically created

im using the following code

If File.Exists("C:\Pic2.jpg") Then
myWordDoc.ActiveDocument.Bookmarks("PHOTO2").Selec t()
myWordDoc.Selection.InlineShapes.AddPicture("C:\Pi c2.jpg")
Else
myWordDoc.ActiveDocument.Bookmarks("PHOTO2").Selec t()
myWordDoc.Selection.Text = ""
End If

The problem I have is the jpeg i am inserting is likeley to be around
2500x1800 pixels, which is way too big for Word (i only need 500x300)

My end users cant be trusted to resize the images themselves so what i would
like to do is resize the image on the fly when inserting into word but ive
no clue how to do it

Thanks in advance

Mike Fellows

Jun 27 '08 #1
1 3734
On May 22, 5:59 pm, "Mike Fellows"
<mike.fell...@equityhouse.NO.SPAM.co.ukwrote:
I have some images stored locally that i retrieve and insert into a word
document that is programatically created

im using the following code

If File.Exists("C:\Pic2.jpg") Then
myWordDoc.ActiveDocument.Bookmarks("PHOTO2").Selec t()
myWordDoc.Selection.InlineShapes.AddPicture("C:\Pi c2.jpg")
Else
myWordDoc.ActiveDocument.Bookmarks("PHOTO2").Selec t()
myWordDoc.Selection.Text = ""
End If

The problem I have is the jpeg i am inserting is likeley to be around
2500x1800 pixels, which is way too big for Word (i only need 500x300)

My end users cant be trusted to resize the images themselves so what i would
like to do is resize the image on the fly when inserting into word but ive
no clue how to do it

Thanks in advance

Mike Fellows
Hi Mike,
You can resize images with manipulating bitmap object. There are some
samples on the net, however this will also works for you:

' Optional, Drawing is referenced by default in VS
Imports System.Drawing
'Declare source / old bitmap
Dim bitmap As Bitmap = New Bitmap("file_path")

'Declare new / target bitmap
Dim newbitmap As Bitmap = New Bitmap(CInt(width_here),
CInt(height_here))
'Declare graphic taken from new bitmap
Dim g As Graphics = Graphics.FromImage(newbitmap)

'Draw the new graphic
g.DrawImage(bitmap, 0, 0, newbitmap.Width, newbitmap.Height)

' Save the image with jpeg format
newbitmap.Save("path",imaging.imageformat.jpeg)

Hope this helps,

Onur Güzel
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mat | last post by:
Hi, I have a system that uploads images as BLOBs in a database. I also have a function that I use to resize uploaded images before saving as files. I would like to combine these two by resising...
2
by: Alex Hopson | last post by:
I'm using the code below to loop through some images and resize each image twice, once to create a thumbnail and once to create a small image. The page stops loading around the 38th image out of...
10
by: David W. Simmonds | last post by:
I have a DataList control that has an Image control in the ItemTemplate. I would like to resize the image that goes into that control. I have a series of jpg files that are full size, full...
1
by: Daniel | last post by:
I have looked everywhere on the web for an answer to this and the only thing I can find is converting the image format when the file is present on the local filesystem. What I want to do is use a...
2
by: Rick | last post by:
How do I go about doing this? Basically I have a field where the user inputs a doctors name, a field where the user inputs the doctors bio, and then a picturebox where they select an image from...
10
by: Roger Withnell | last post by:
I'm using ASP, VBScript and SQL Server. I'm also using UTF-8 character set and so my codepage is 65001 and SQL Server datatype nvarchar. I can insert unicode characters correctly into the...
1
by: Brian | last post by:
Using A2K I have an image control on a report and use code to set the image.picture to the required jpg. 3 of the jpgs resize properly but 2 do not - they display much smaller than the image...
6
by: tomasio | last post by:
Dear NG, years have passed and I am still more designer than programmer. I build a new version of my website which has a few nasty bugs, especially on my startpage: Resizing text brakes the...
10
by: mishrarajesh44 | last post by:
hii all, I am facing a problem currently.. i have a script for image uploading and resizing.. the image uploading takes place properly for every size images.. but, the resizing works for...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.