| View previous topic :: View next topic |
| Author |
Message |
ArielEnter Newbie

Joined: 11 Jun 2009 Posts: 4
|
Posted: Fri Nov 06, 2009 4:12 pm Post subject: Change Picture for OpenOffcie (BASIC) |
|
|
Change Picture is a macro I made for OpenOffice that lets you change the picture of an existing image in a document.
http://www.youtube.com/watch?v=DjmkDVyMmn4
http://extensions.services.openoffice.org/project/ChangePicture
Este es una macro que hice para OpenOffice que te permite cambiar la fotografiá de un imagen existente en un documento.
I want to thank james_h, if he wouldn't had encourage me to keep working on it I wouldn't have made the extension. Thanks man, I really appreciate your support and advising I'm really in debt with you.
I want to thank every body in this forum, since I was in a rush I didn't take note of all the post I had to go trough. I'll say there were more than 50 (I'm not a quick learner) and most of the time it was copy and paste and trying to understand the code. Thank you all.
Also I need to thank Paolo Mantovani for his BasicAddonBuilder - The Extension's packager is a great tool:
http://extensions.services.openoffice.org/project/BasicAddonBuilder
Hope you find this macro use full. Talking about that, it hasn't pass a day and I already have 284 downloads on my extension. This is the first time I get so mush attention in the Internet. Thank you all.
Last edited by ArielEnter on Mon Nov 23, 2009 1:58 pm; edited 19 times in total |
|
| Back to top |
|
 |
ArielEnter Newbie

Joined: 11 Jun 2009 Posts: 4
|
Posted: Fri Nov 06, 2009 5:46 pm Post subject: commented |
|
|
Deleted
Last edited by ArielEnter on Fri Nov 20, 2009 2:52 pm; edited 1 time in total |
|
| Back to top |
|
 |
james_h Super User


Joined: 05 Nov 2005 Posts: 859
|
Posted: Fri Nov 06, 2009 9:37 pm Post subject: Test if selection supports Service |
|
|
| Quote: | | One of the things I wish I could have changed is getting a better way to find out if the selected object is an image or not. |
Your code might be able to use the thisComponent.getCurrentSelection.supportsService("NameOfService") test to determine what has been selected. I haven't tested this snippet extensively, but you should get an idea from it.
| Code: | Sub testGraph
oDocument = thisComponent
oSelection = oDocument.getCurrentSelection()
if oSelection.supportsService("com.sun.star.text.TextRanges") then
MsgBox ("Selection is text")
else
MsgBox ("Selection is image")
end if
end sub | As far as I know, TextRanges are only applicable to writer documents. Also, any objects that are not text (for example, Drawing Objects, Embedded OLE Objects) are rated as images according to this snippet. What I have not yet determined is the name of a service that is unique to inserted jpeg, png, tif and gif images.
This looks like an interesting utility. When you've fine tuned it, maybe you should package it as an extension. |
|
| Back to top |
|
 |
ArielEnter Newbie

Joined: 11 Jun 2009 Posts: 4
|
Posted: Fri Nov 20, 2009 3:55 pm Post subject: |
|
|
One thing I was having troubles with was the concept of a Bitmap table. I haven't read about the matter, and I never got a lesson in school about that, so I may be wrong. For me, a bitmap table is variant that holds the picture itself in the document. So in order to embed an image to the document, instead of referring to a location in the file system of the OS (the hard drive location) you tell the image object to take the picture from the bit map table located inside the document it self.
While making the program, I was afraid of leaving in the bit map table images that were no longer necessary every time Picture changed, making the document unnecessarily bigger and bigger.
According to my personal conception of a bitmap table, if you delete a picture of the bitmap table, all images using that same picture will lost the ability to display that picture. But, by testing it my self, and as my Change Picture Extension shows, this is not true.
| Code: | oImg.GraphicURL = oBitmaps.getByName("Image") ' we give the image the location of the picture which is stored within the document
oBitmaps.removeByName("Image") 'once that we have given the image a picture we no longer need it inside of the oBitmap
|
The only thing I can thing of is that the Image object is capable of holding the picture itself. Now this is good, because it means a more efficient control over the size of the document.
If the image object is deleted, the picture is deleted too and no longer exist inside of the document. This will mean that the size of the document will decrease as is logical. And since all entries in the bitmap table are deleted right after they are used too, the bitmap table doesn't take any space in the document either.
Please, could someone tell me if I'm right in my concepts? I'll really appreciate it.
I have tested and the program works very well, and pictures are not lost when you move them to another computer if they were embedded and even if the bitmap talble is empty. |
|
| Back to top |
|
 |
james_h Super User


Joined: 05 Nov 2005 Posts: 859
|
Posted: Mon Nov 23, 2009 6:15 pm Post subject: Image - How to determine whether it is linked or embedded |
|
|
An image in an OpenOffice.org document can be either embedded in the document itself or a link to an external image. The OpenOffice.org help says:
| Quote: | Inserting Bitmaps
A bitmap image can be inserted in OpenOffice.org Writer, OpenOffice.org Calc, OpenOffice.org Draw and OpenOffice.org Impress documents.
1.Choose Insert - Picture - From File.
2.Select the file. In the File type box you can restrict the selection to certain file types.
3.Click the Link box if you want a link to the original file.
If the Link box is marked, whenever the document is updated and loaded the bitmap image is reloaded. The editing steps that you have carried out in the local copy of the image in the document are re-applied and the image is displayed.
If the Link box is not marked, you are always working with the copy created when the graphic was first inserted.
To embed graphics that were first inserted as links, go to Edit - Links and click the Break Link button.
4.Click Open to insert the image. |
ArielEnter wrote: | Quote: | | While making the program, I was afraid of leaving in the bit map table images that were no longer necessary every time Picture changed, making the document unnecessarily bigger and bigger. | The contents of an OpenDocument file can be extracted or viewed using a .zip archive utility. Assuming you have a zip archiving utility, the easiest way to see the contents of an OpenDocument file is to rename the OpenDocument file's extension to .zip and then double click it. The images are in the Pictures directory in the .zip file. |
|
| Back to top |
|
 |
ArielEnter Newbie

Joined: 11 Jun 2009 Posts: 4
|
Posted: Tue Nov 24, 2009 4:47 pm Post subject: Conclusion |
|
|
Once again, thanks James.
Well, my conclusion will be that OOo decides whether or not a picture is being used. If we delete all the records in the oBitmap variant the pictures are also deleted. But if a graphic object is also using one of the pictures, OOo doesn't delete it until this graphic object is deleted by the user. Well that solves everything.
I have tested already thanks to Jame's tip, and CangePicture (Mi macro) works perfectly without any waste of memory.
I'm so proud of the results, hope it helps a lot of people. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|