473,382 Members | 1,648 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,382 software developers and data experts.

Resize and Insert Image Into Word

3
Hi

There was a previous post on this but I cannot find it...

The previous post showed resizing using the graphics object:
Expand|Select|Wrap|Line Numbers
  1. 'Declare source / old bitmap
  2.             Dim bitmap As Bitmap = New Bitmap(patientPic)
  3.  
  4.             'Declare new / target bitmap
  5.             Dim newbitmap As Bitmap = New Bitmap(CInt(250), CInt(200))
  6.             'Declare graphic taken from new bitmap
  7.             Dim g As Graphics = Graphics.FromImage(newbitmap)
  8.  
  9.             'Draw the new graphic
  10.             g.DrawImage(bitmap, 0, 0, newbitmap.Width, newbitmap.Height)
  11.  
But having gotten g, how do you insert the resized image into a Word doc and make sureit is inline - I was trying to use inlineshapes but just can't get it to work.

Any ideas gratefully received.

Jerry
Jan 20 '09 #1
4 15567
Frinavale
9,735 Expert Mod 8TB
You need to save your picture to the hard drive so that you can use the AddPicture method in order to add the image to your Word Document. Check out this article for more information on how to add a picture to a Word Document.


The following code will add the saved image to an existing Word Document file.

Expand|Select|Wrap|Line Numbers
  1. 'Declare source / old bitmap            
  2. Dim oldbitmap As Bitmap = New Bitmap(patientPic)           
  3.  
  4. 'Declare new / target bitmap           
  5. Dim newbitmap As Bitmap = New Bitmap(CInt(250), CInt(200))
  6.  
  7. 'Declare graphic taken from new bitmap
  8. Dim g As Graphics = Graphics.FromImage(newbitmap)           
  9.  
  10. 'Draw the new graphic
  11. g.DrawImage(oldbitmap, 0, 0, newbitmap.Width, newbitmap.Height)
  12.  
  13. Dim pathToSavedImage As String ="C:\myTempImage.jpg"
  14. Dim pathToDocument As String = "C:\MyDocument.doc"
  15.  
  16. newbitmap .Save(pathToSavedImage )
  17.  
  18. 'Cleaning up image resources
  19. oldbitmap .Dispose()
  20. newbitmap.Dispose()
  21. g.Dispose()
  22.  
  23. 'Opening the Word Document
  24. Dim objApp As New Microsoft.Office.Interop.Word.Application
  25. Dim objWordDoc As New Microsoft.Office.Interop.Word.Document
  26.  
  27. objWordDoc = objApp.Documents.Open(pathToDocument)
  28.  
  29. 'Adding the image to the Word Document
  30. Dim ObjPic As Microsoft.Office.Interop.Word.InlineShape = objWordDoc.InlineShapes.AddPicture(pathToSavedImage)
  31.  
  32. 'Saving the Word Document
  33. objWordDoc.SaveAs(pathToDocument)
  34.  
  35. 'Cleaning up
  36. objWordDoc.Close()
  37.  
Jan 20 '09 #2
jcrick
3
Frinavale

Thanks.

Unfortunately saving to disk and reloading is not ideal because there will be plenty of images in a single doc which means that performance will be poor. What I really want to do is load the image from file, resize in memory and then place the in-memory image into the Word doc.

Any help gratefully appreciated.

Jerry
Jan 20 '09 #3
Frinavale
9,735 Expert Mod 8TB
From what I can tell you cannot save an image from memory into the Word Document. You could just write over the same file once you have added the InlineShapes to the Word Document.....
Jan 20 '09 #4
jcrick
3
Frinavale

Thanks. I guess I'll have to do that for now and see if I can find a better solution later.

Thanks again.

Jerry
Jan 20 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Giovanni | last post by:
Hello, I need to insert a resized image in a html page. I know that using the html IMG tag it is possible to set the height and width attributes, with no need of php (or server-side...
2
by: Charles Packer | last post by:
From one of the online Javascript tutorials, I learned how to open a new window and set its size. I'm building a page that has several small photographs, and I want to let the viewer examine...
9
by: Don | last post by:
Does anyone know where I can find a client-side function I can reference from within an HTML/JavaScript web page? I'm currently using a core PHP function to do this, but I'd rather do it on the...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
4
by: joe | last post by:
how to resize an upload image and then change to binary & insert to db
0
by: madval | last post by:
hi, i'm inserting some images in a word document, and i want to separate this images with a carriage return, but when i insert new lines they are inserted at the end of document. i want to insert:...
0
by: avisekrishi | last post by:
Hi , I have 100 image . I need to follow the following steps 1. Open a word document 2. Click on Insert -> Picture -> File and then open the image file 3. The Image gets opened in Word.
0
by: getpunith | last post by:
Hi all, How can export or insert an Image to MS WORD 2007. Doc.InlineShapes.AddPicture() needs an Image file stored on disk space, But I dont have Image file.What I have is an Image object. ...
22
by: simon2x1 | last post by:
i have an image which width is 213 and height is 200 when i echo the image and i resize it echo "<img src='company/$present' width='70' height='68'/>"; the image was not as clear as when it was...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.