Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / May 2008

Tip: Looking for answers? Try searching our database.

Inserting and Resizing and image into Word

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike Fellows - 22 May 2008 15:59 GMT
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").Select()
   myWordDoc.Selection.InlineShapes.AddPicture("C:\Pic2.jpg")
Else
   myWordDoc.ActiveDocument.Bookmarks("PHOTO2").Select()
   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
kimiraikkonen - 22 May 2008 16:20 GMT
On May 22, 5:59 pm, "Mike Fellows"
<mike.fell...@equityhouse.NO.SPAM.co.uk> wrote:
> I have some images stored locally that i retrieve and insert into a word
> document that is programatically created
[quoted text clipped - 19 lines]
>
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.