View Full Version : Image Object Huge file size problem
asystole0
10-15-2010, 07:46 AM
Hi
I have a toolbar which allows the user to select an image from a specified folder and display the one they wish to use in the document. Ive used an image from the control toolbox and specified the sizes etc in the settings.
This all works fine. When the template is saved without an image present it is around 400kb but when an image is selected and the document saved it goes to around 50mb! ive checked all the pictures and none of them are even close to 1MB!
Can you help this is really annoying!
Image1.Picture = LoadPicture(fPath & ListBox1.Value & ".jpg")
fpath = C:\Photos
Listbox1.value = image1
asystole0
10-15-2010, 08:08 AM
code i used to actually put the image in the image box is this:
ActiveDocument.Image1.Object.Picture = LoadPicture(fPath & ListBox1.Value & ".jpg")
Tinbendr
10-15-2010, 01:54 PM
try
ActiveDocument.InlineShapes.AddPicture FileName:= _
fPath & ListBox1.Value & ".jpg", LinkToFile:=False, SaveWithDocument:=True
David
asystole0
10-18-2010, 12:40 AM
Hi David
Thanks for your reply, though the code works perfectly its not exactly what I need. :(
The image object in the word doc is static and its location never changes, your code seems to insert the image straight to the top of the document.
Any ideas?
Tinbendr
10-18-2010, 05:31 AM
First things first. Did it, in fact, reduce the document size?
The code inserts the photo at the cursor location.
I'm still not exactly sure where the picture is. Is it in the userform, or on the document?
Could you provide a sample document?
asystole0
10-18-2010, 07:01 AM
Yes, document size was dramatically reduced.
The image object is in the word document itself.
find attached document, youll need to create a folder "C:\pics" and dump some jpegs in.
open the template, click on "choose photo" on the new toolbar which comes up.
many thanks
fumei
10-18-2010, 09:13 AM
David, there is no userform. There is an ActiveX Image control.
asystole0, could you please post your code? Your file is a docx, and as I do not use 2007, all code is removed by the converter. I can not see any code, nor does any toolbar come up (no code).
asystole0
10-18-2010, 09:57 AM
Gerry,
I dont have word 2007 either so im not sure whats happening when your downloading it! When I download and open its still in .dot format and opens fine in 2003.
Ive attached the exported .frm file, im not entirely sure if this is what your looking for but let me know what i need to do to get the correct info extracted and ill do it.
fumei
10-18-2010, 12:29 PM
Sorry. my bad. I opened the wrong file.
OK.
1. You need to put the "\" back with your test code. The .jpg is stripped off, and then of course the LaodPicture fails.
2. the image DOES go into Image1.
I would use explicit naming. You have TWO controls, both named Image1. true they are different places (one on th euserform, one in ThisDocument), but get into the habit of explicit names.
I would also NOT use .Hide.
PicSelector.Hide ' Close window once finished
This does NOT unload the userform. It is still in memory. if you are done with it, explicitly unload it.
As you are in the userform code module, using btnComplete1_Click(), you can use:
Sub btnComplete1_Click()
...yaddda yadda
Unload Me
End Sub
Or you can use
Unload PicSelector
asystole0
10-18-2010, 12:37 PM
Thanks Gerry.
I quickly changed it so the file path wasn't pointing to a location that didn't exist on another computer!
BUT the problem is not that I cant get the image to load but that the file size becomes huge once the image has been loaded, Did you manage to replicate with an image of your own?
fumei
10-18-2010, 12:43 PM
Sorry. my bad. I opened the wrong file.
OK.
1. You need to put the "\" back with your test code. The .jpg is stripped off, and then of course the LaodPicture fails.
2. the image DOES go into Image1.
I would use explicit naming. You have TWO controls, both named Image1. true they are different places (one on th euserform, one in ThisDocument), but get into the habit of explicit names.
I would also NOT use .Hide.
PicSelector.Hide ' Close window once finished
This does NOT unload the userform. It is still in memory. if you are done with it, explicitly unload it.
As you are in the userform code module, using btnComplete1_Click(), you can use:
Sub btnComplete1_Click()
...yaddda yadda
Unload Me
End Sub
Or you can use
Unload PicSelector
fumei
10-18-2010, 12:56 PM
Hmmmmm.
Original file (of the .dot) 277K
Added image file 208K
File size...4,249K
Hmmmmmm.
fumei
10-18-2010, 01:15 PM
Interesting. Still trying.
asystole0
10-19-2010, 12:05 AM
Interesting. Still trying.
Thanks Gerry, if you use an image size like i was using 2Mb the file size of the doc becomes over 50Mb.
Very annoying, let me know how you get on!
Tinbendr
10-19-2010, 05:47 AM
Is the image you have on the template a Bitmap object? If so then, that's the problem. Word is converting whatever you put into the object into a bitmap.
I think you should insert a bookmark, then insert the inlineshape at the bookmark.
David
fumei
10-19-2010, 10:21 AM
David, they are NOT inserting an inlineshape. They are using the Picture property of an image control (which is admitedly itself an inlineshape). But that control is already there.
Yes, it is a bitmap ( a .jpg file). I do not think there is any converting going on.
Tinbendr
10-19-2010, 08:37 PM
But that control is already there. Yes, I realize that.(I did d/l the file.) I just couldn't figure out where the 'box' came from. I can't seem to get to a properties page for it.
Yes, it is a bitmap ( a .jpg file). No, I'm thinking *.bmp format, not just a graphic file.
I do not think there is any converting going on.
From the picture property help page.
Remarks
While designing a form, you can use the control's property page to assign a bitmap to the Picture property. While running a form, you must use the LoadPicture function to assign a bitmap to Picture. Is my interpretation too literal?
asystole0
10-20-2010, 02:14 AM
Hi
I have tried changing files from .jpg to .bmp and re loading the image using the same code but the problem is still present.
Can I manipulate my code to insert at a bookmark rather than an image control?
asystole0
10-20-2010, 03:09 AM
Hi
I have tried changing files from .jpg to .bmp and re loading the image using the same code but the problem is still present.
Can I manipulate my code to insert at a bookmark rather than an image control?
Guys, thanks for the help ive managed to peice together some code tinbendr previously recomended in a post regarding replacing multiple bookmarks with images.
The code does exactly what i need it to do without the huge file sizes!
Dim BmkNm As String
Dim BmkRng As Range
BmkNm = "mainpic"
With ActiveDocument
If .Bookmarks.Exists(BmkNm) Then
Set BmkRng = .Bookmarks(BmkNm).Range
BmkRng.InlineShapes(1).Delete
.Bookmarks.add BmkNm, BmkRng
Dim WrdPic As Word.InlineShape
Set WrdPic = BmkRng.InlineShapes.AddPicture(fPath & ListBox1.Value & ".jpg", False, True)
With WrdPic
.ScaleHeight = 37
.ScaleWidth = 37
End With
End If
End With
Tinbendr
10-20-2010, 05:10 AM
Asystole0,
Glad you've got it worked out.
Another thing to consider is the picture resolution. Anything over ~75 is wasted on a monitor. You say the picture you're inserting is ~1M. You could reduce the resolution and get a much smaller file size. (But if printing is your goal, then you may need the original file size.)
But that adds more work for you. :)
Cheers!
asystole0
10-20-2010, 05:49 AM
Asystole0,
Glad you've got it worked out.
Another thing to consider is the picture resolution. Anything over ~75 is wasted on a monitor. You say the picture you're inserting is ~1M. You could reduce the resolution and get a much smaller file size. (But if printing is your goal, then you may need the original file size.)
But that adds more work for you. :)
Cheers!
Thanks, Ill reduce the file sizes once this goes into production.
After having played about with the bookmark code I was struggling to get it to work just as I needed it.
I had a quick look at labels, inserted one and noticed i could change the background image! I un-commented my code and changed from "image1" to "label1" and the picture is displayed exactly how i want it to AND the file size remains at a normal level!
Can you see any problems using a label rather than image control?
ThisDocument.Label1.Object.Picture = LoadPicture(fPath & ListBox1.Value & ".jpg", , , Default)
</IMG>
asystole0
10-20-2010, 06:20 AM
Thanks, Ill reduce the file sizes once this goes into production.
After having played about with the bookmark code I was struggling to get it to work just as I needed it.
I had a quick look at labels, inserted one and noticed i could change the background image! I un-commented my code and changed from "image1" to "label1" and the picture is displayed exactly how i want it to AND the file size remains at a normal level!
Can you see any problems using a label rather than image control?
ThisDocument.Label1.Object.Picture = LoadPicture(fPath & ListBox1.Value & ".jpg", , , Default)
Forget that, it doesnt work, i resized the pics and used an image which was resized with a filesize of 43KB which made it look like it was resolved.
:doh:
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.