| View previous topic :: View next topic |
| Author |
Message |
RPG Super User

Joined: 24 Apr 2008 Posts: 2696 Location: Apeldoorn, Netherland
|
Posted: Sat Aug 23, 2008 3:03 pm Post subject: |
|
|
Hello
I did found something. I have also added the code. I have found one thing i have to study more, It is for adjusting the size of the picture without disturbing. The code is with some comment but maybe it is difficult to understand, feel free to ask some question. I'm better with question and then explain thing. I donot use it for me own so I don't have a set of macros ready.
I hope it helps.
Romke
| Code: |
REM ***** BASIC *****
option explicit
dim oBeginofform
dim oBeginforms
dim oBeginform
Sub Main
End Sub
sub loadSpecialMacros
if not globalscope.BasicLibraries.islibraryloaded("Tools") then
' Load library if not loaded
globalscope.BasicLibraries.loadlibrary("Tools")
end if
end sub
sub howitworks
PictureAdjust "ImageControl",100,4000,9000,9000
end sub
sub init
oBeginofform=thiscomponent.drawpage
oBeginforms=oBeginofform.forms
oBeginform=oBeginforms.getbyname("Standard") 'The name of standard you can change
Graphic.loadSpecialMacros
end sub
Sub PictureAdjust(PictureName as string,x,y,h,w)
'The measure take place in 1/100 mm
' for 8 cm you must give 8000
'X position
'Y Position
'h =heigh
'w= width
'make variables
dim docCtrl
dim oPicture ' for handling the control how you see it in the database
dim oPictureShape ' is for handling the control hoe you see it as drawing
' For size you have to make special strucs
dim size as new com.sun.star.awt.Size
'dim maat as new com.sun.star.beans.PropertyValue
dim Point as new com.sun.star.awt.Point 'place where it comes
init
oPicture=oBeginform.getbyname(PictureName)
docCtrl = thisComponent.getCurrentController
' library moet geladen zijn
oPictureShape = GetControlShape(docCtrl.Model,PictureName)
oPictureShape.zorder=8
' Give now new size and position
size.height=h
size.width=w
Point.x=x
Point.y= y
oPictureShape.setsize(size)
oPictureShape.setposition(Point)
end sub
sub ScaleImage
dim Yourpicturename
init
'This two can also be set in the properties of the control
Yourpicturename="ImageControl" 'Here comes the name of your control for the picture
obeginform.getbyname(Yourpicturename).ScaleImage=not obeginform.getbyname(Yourpicturename).ScaleImage
'In the same way you can handle
'.Printable ' yes or no print of this control
end sub
|
|
|
| Back to top |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 2696 Location: Apeldoorn, Netherland
|
Posted: Tue Sep 02, 2008 3:36 am Post subject: howto scale picture |
|
|
Hello
It did promise to give something else.
This sub handle pictures
Romke
| Code: |
sub begintoon(oEv as object)
'RecordNavChanged oEv
' Call this macro every time when you load a new reord
' bind this to the form to the event go to new record
' this is not bound to the picture control
' The picture control has a empty date field
' This sub the format of the picture control
' As big as posible but not greater then max value you give
' It only change size the It does not disturb.
' It does not work for pictures who are in the table self
' Variable for form
dim beginform
dim docCtrl
dim PictureName,UrlField
dim oPicture ' for handling the control how you see it in the database
' Variables only for the picture for manupulation the size
dim oPictureShape ' is for handling the control hoe you see it as drawing
dim oPictureGraphic ' This is something from the picture itself
dim scalemin as integer ,scale as integer,scalemax as integer
' For size you have to make special strucs
dim size as new com.sun.star.awt.Size
dim Point as new com.sun.star.awt.Point 'place where it comes
' Here comes some names you can adjust as you need
beginform=oEv.Source
'beginform=thiscomponent.drawpage.forms.getbyname("Standard")
PictureName="ImageControl" 'Here comes the name of your control for the picture
UrlField="URL" 'Here comes the url of the pictue out of your data base
oPicture=beginform.getbyname(PictureName)
oPicture.ImageURL= beginform.getstring(beginform.findcolumn(UrlField))
oPicture.ScaleImage=true
' library must be loaded can be done outsides this macro
if not globalscope.BasicLibraries.islibraryloaded("Tools") then
' Laad nu de library
globalscope.BasicLibraries.loadlibrary("Tools")
end if
' Now we start working with the picture
'The measure take place in 1/100 mm
' for 8 cm you must give 8000
' Where must the picture be on the screen
dim x ,y,maxsize
x= 100
y=2000
maxsize=9000
'make variables
docCtrl = thisComponent.getCurrentController
oPictureShape = GetControlShape(docCtrl.Model,PictureName)
oPictureShape.zorder=8
oPictureGraphic=oPicture.Graphic
if isnull(oPictureGraphic) then exit sub
' Init Caculation
scalemin=0 ' Not lower as 0
scalemax = 100 ' Can as great as you want
' For an explanation of this algoritme look : http://en.wikipedia.org/wiki/Bisection_method
' start calculation
scale=(scalemax-scalemin)/2
do 'until
' Do the calculation for the given scale
size.height=oPictureGraphic.size.height*scale
size.width=oPictureGraphic.size.width*scale
if (scalemax=scale) or (scalemin=scale) then exit do
select case (size.height > maxsize) or (size.width > maxsize)
case true
' scale must smaller
scalemax=scale
scale=((scalemax-scalemin) /2 )+ scalemin
case false
'scale must bigger
scalemin=scale
scale=((scalemax-scalemin) /2) + scalemin
case else
exit do
end select
loop
' The calculation is done
' give all the values
Point.x=x
Point.y= y
oPictureShape.setsize(size)
oPictureShape.setposition(Point)
end sub
|
|
|
| Back to top |
|
 |
Steve Z1000 Newbie

Joined: 28 Oct 2008 Posts: 4
|
Posted: Wed Oct 29, 2008 4:30 am Post subject: I can`t get it running |
|
|
Hello Folks,
after searching in a lot of Forums i finaly foud this post, wich describes my problem.
After doing all the things you discribed in this Post - i still can`t get it running.
Surely i`m doing something wrong. My Link informations is in the ooBase Table wich is called Tabla1 (My OO is in spanish).
My Form is also called Tabla1. The Link field is called Link (Syntax file:///c:/users/stephan/documents/zbf%20catalogo%202008/zbf%202008/daten/6700001002.jpg ).
It`s not marked as Hyperlink in the Calc Tableand doesn`t show as Hyperlink in the Base Table.
I have inserted a un Formated Image Field in the OOFrom.
I have inserted the Macro in 1. My Macros/Standart/Module1/begintoon
I have inserted the Macro in 2.Tabla1/Standart/Module1/begintoon
I also do have a problem with asigning the Macro to point 13 renew Document (Can`t find it)
I think i looked every where in Design Mode and Normal Mode.
when i run the Macro in the edit mode it shows me: beginform=oEv.Source Error in argument - argument is not optional (Whatever that means).
Can anybody help me ?
Some of the descriptions on page one i simply do not understand the steps to do.
Might be because the spanish oo is different ?
I`m not a PRO i`m still a Beginner.
Maybe someone could Upload a Form wich works so i can copy from there ?
Thanx Steve  |
|
| Back to top |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 2696 Location: Apeldoorn, Netherland
|
Posted: Wed Oct 29, 2008 6:55 am Post subject: |
|
|
Hello
This post explains only the sub from:Tue Sep 02, 2008 3:36 am
resizing
This sub is made for pictures who are stored on the disk. Only the name is in the database.
If the picture is saved in the database then it will not work. I did have tried and I think it is possible but i did not succeed.
I'm sure it is working with jpg and jpeg files. I don't know if it is working with other kind of files.
I have made it with OOo2.41 and OOo2.3 and it is now working with OOo3.0. I don't know how it is working when you use it more then I do. I make it, but do not use it for me own.
How to bind the macro to an event
Go in edit mode of the form
select the picture click right mouse
select in the popup "form" 5 from top click mouse
select tab page events
Explanation
The macro must be bound to "After record changed" third from below.
When record is changed, going to an other record, then after the record is changed the url must be placed in the url field of the picture control. The data field of the picture control is not bound to the table, it is empty.
giving other names
It can be there is a problem with the name of the control and /or with the place of the control. In my form there is only one form as can see in the form navigator. The form navigator is some else as the normal navigator
| Quote: | | It`s not marked as Hyperlink in the Calc Tableand doesn`t show as Hyperlink in the Base Table. |
If you insert the name/url by hand in the url field of the picture control, is the picture displayed?
I think all information is here in this thread.
Before I will/can answer questions you must may be more clear about the problems you have.
Romke |
|
| Back to top |
|
 |
Steve Z1000 Newbie

Joined: 28 Oct 2008 Posts: 4
|
Posted: Thu Oct 30, 2008 1:12 am Post subject: |
|
|
Thanx to all of you !
I finally made it work ! |
|
| Back to top |
|
 |
Steve Z1000 Newbie

Joined: 28 Oct 2008 Posts: 4
|
Posted: Thu Oct 30, 2008 3:13 am Post subject: Set point of Image |
|
|
Where and how do i have to make changes to see the Image at the right side of my Form ?
I tried to change some values in the Macro but the picture only goes up or down.
' The calculation is done
' give all the values
Point.x=x here i changed up to 200
Point.y=y here i also chnged up to 200
oPictureShape.setsize(size)
oPictureShape.setposition(Point)
end sub
or is there a other place to set the point ?
How do i caculate the Point ? |
|
| Back to top |
|
 |
Steve Z1000 Newbie

Joined: 28 Oct 2008 Posts: 4
|
Posted: Thu Oct 30, 2008 8:39 am Post subject: |
|
|
Found it too !
Thanx |
|
| Back to top |
|
 |
jruiz5 General User

Joined: 12 Jan 2009 Posts: 11
|
Posted: Thu Feb 12, 2009 1:22 pm Post subject: |
|
|
| RPG wrote: |
Step 2
Bound this macro to the form event when going to a new record. It number 13 in the list.
Step 3
Control the names if theu correct.
I think this is all to display the picture.
I knew the capabillity of the picture control is not great. For printing I do not have a solution on this moment. You are not talking about it in this thread but in the first one talk about it and that can give more problems.
Romke |
I successfuly did step 2, but do not understand how I actually attach the link so the photos show up. I have a form with multiple fields on it and one is Photos, which I would like to put the pictures in. It is a image field (longvariable binary).
How do I actually get the photo do display using the link on the form? Do I need to be using a different type of field for the link?
Help would be greatly appreciated, thank you |
|
| Back to top |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 2696 Location: Apeldoorn, Netherland
|
Posted: Thu Feb 12, 2009 3:34 pm Post subject: |
|
|
Hello
| Quote: | | It is a image field (longvariable binary). | From this quote I understand that all the macros are not working for you.
For other readers. If you use OOo3.1 then it is maybe possible that you need no more the macro for resizing.
This macros are only working if you have a table with urls.
First I will explain what the different is.
With urls there is only a name of the picture in the database. The url points to the picture you want to display.
When you use a "longvariable binary" then you want have the picture in the database.The control must know which field it is.
When you use HSQLDB then
1) Your database can be grow fast
2) Your computer can be slow down.
3) All the picture must be in memory
I have only wrote this macros but I don't use them so I cannot say what the best methode is. But other people say, most of the time, the use of urls is the best methode. The macro for resizing does not work for pictures who are in the database.
summary
with url
1) table must have a field for an url, this is a textfield
2) picture control does not have a field in the data field
3) Only one picture is in memory
without url
1) table must have a field for picture
2) picture control must have the name of the field in the data field
3) The pictures of the current resultset are in memory
How to insert a picture
When you click on the picture then you can select a picture. This methode is when you want to insert the picture in the database.
I hope I have answer your question. I think all information is in this thread, but maybe some questions are not clear.
Romke |
|
| Back to top |
|
 |
jruiz5 General User

Joined: 12 Jan 2009 Posts: 11
|
Posted: Mon Feb 16, 2009 12:46 pm Post subject: How to display URL as picture |
|
|
What I cannot seem to figure out by reading the previous posts is this.
1. How do I display the picture I have entered URL’s for, in my forms and in my reports, so I can print them?
I am making a real estate database using OOBase 3, and would like to add a specific picture for each record using urls. (The database would get too big if I inserted the pictures individually) I cannot figure out how to get these URL’s to display a separate picture for each record. I am sorry if this was written in an earlier post, but I simply do not quite understand how a URL gets displayed as an image.
I did use the picture control on the form to insert a picture, but it just puts a picture on as part of the background for every record. I need to have a separate picture for each record.
I hope this is clear. Thank you very much for your help so far, Romke.
Again the question I have is.
1.Now that I have entered different URLs that associate with each record. How do I get my form and my report to display the URL as a picture? (Depending on which record I am looking at.)
Juan |
|
| Back to top |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 2696 Location: Apeldoorn, Netherland
|
Posted: Mon Feb 16, 2009 4:48 pm Post subject: |
|
|
Hello
I do understand your question that you don't understand the interaction of the url and the showing of the picture. If you don't understand this then it is difficult to understand the macro's and also difficult to make the database in the way you want.
This is only a little lesson, you can skip it.
I do assume you can make a picture box.
1) make an empty form in edit mode
2) make an image control in the form.
3) Right click on the image control
4) select in the popup the word control and click on the word
5) Select now the General tabpage
6) go to graphics five from below
7) click on the little square right.be a little patient
8 ) Now you can select a picture from your hard disk do this control.
9) If you select the picture by name click on OK
10 If all things are going good now you see the picture in the control.
11 in the tabpage you see the url.
12 The form is still in edit mode.
13 change the off edit mode.
14 click on the picture.
Now you can understand what the URLs are doing.
I understand that you have a table with URL.
The macro in this post :PostPosted: Mon Jul 21, 2008 4:22 am
takes care that every time you go to a other record the URL in that record is going to the image control. Normally a control is bound to a field but the image control is not bound to a field: It have an empty data field.
I did point to the first macro and not to the more difficult one. I don't know when you have ready your database but OOo comes with new capabilities in OOo3.1
http://wiki.services.openoffice.org/wiki/Base/New_features_in_3_1
If you want understand the power of the forms it is good to read the tutorials of Benitez. The link is in this thread.
I don't know if you can print the pictures in a report. I seldom use reports and ask it in a new thread if you can print pictures in a report. You can print picture in a word document.
I can understand it is not easy, Maybe not all things are clear but that is for the next step. Try to tell me where I have to start the next time.
I hope this helps and that we succeed
Romke |
|
| Back to top |
|
 |
jruiz5 General User

Joined: 12 Jan 2009 Posts: 11
|
Posted: Thu Feb 26, 2009 2:10 pm Post subject: Thank you |
|
|
Thank you Romke,
It seems everything is working well enough. I just need to look into getting the photos on reports.
Thanks again,
Juan |
|
| Back to top |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 2696 Location: Apeldoorn, Netherland
|
Posted: Sat Mar 07, 2009 12:52 pm Post subject: |
|
|
Hello
Some people did ask me thing and that makes I must look to the code. I notice that I can speed up some thing what I have done. The speedup is only when you change the size. Also I have tried to make the explanation a little more clear.
Romke
| Code: | sub begintoon (oEv as object)
' The calculation of the size doing in an other and faster way.
'RecordNavChanged oEv
' Call this macro every time when you load a new reord
' bind this to the form to the event go to new record
' this is not bound to the picture control
' The picture control has a empty data field
' Variable for form
dim beginform
dim docCtrl
dim PictureName,UrlField
dim oPicture ' for handling the control how you see it in the database
' Variables only for the picture for manupulation the size
dim oPictureShape ' is for handling the control hoe you see it as drawing
dim oPictureGraphic ' This is something from the picture itself
dim scale ' I need this value for the size on screen
' For size you have to make special strucs
dim size as new com.sun.star.awt.Size
dim Point as new com.sun.star.awt.Point 'place where it comes
' Here comes some names you can adjust as you need
beginform=oEv.Source
PictureName="ImageControl" 'Here comes the name of your control for the picture
UrlField="URL" 'The fieldname in your database. Where your url is
oPicture=beginform.getbyname(PictureName)
oPicture.ImageURL= beginform.getstring(beginform.findcolumn(UrlField))
oPicture.ScaleImage=true
' library must be loaded can be done outsides this macro
if not globalscope.BasicLibraries.islibraryloaded("Tools") then
' Laad nu de library
globalscope.BasicLibraries.loadlibrary("Tools")
end if
' Now we start working with the picture
'The measure take place in 1/100 mm
' for 8 cm you must give 8000
' Where must the picture be on the screen
dim x ,y,maxsize
x= 100
y=2000
maxsize=9000
'make variables
docCtrl = thisComponent.getCurrentController
oPictureShape = GetControlShape(docCtrl.Model,PictureName)
oPictureShape.zorder=8
oPictureGraphic=oPicture.Graphic
if isnull(oPictureGraphic) then exit sub
' This is a new way for the calculations. It is faster. The reason I do understand it now better
' Which side is the greater. The side who has the greatest made the scale
select case sgn(oPictureGraphic.size.height- oPictureGraphic.size.width)
case 1,0 : scale= maxsize / oPictureGraphic.size.height
case -1 : scale= maxsize/oPictureGraphic.size.width
end select
' Place the value in strucs
size.height=oPictureGraphic.size.height*scale
size.width=oPictureGraphic.size.width*scale
Point.x=x
Point.y= y
' Place the strucs in the object who I want display
oPictureShape.setsize(size)
oPictureShape.setposition(Point)
end sub |
|
|
| Back to top |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 2696 Location: Apeldoorn, Netherland
|
Posted: Tue Apr 28, 2009 1:35 pm Post subject: |
|
|
Hello
The most important thing I have add now: The url who belongs to the image can bestored in the database. You have to use the good events. This means with the image control you can select an image and when you go to a new record then the URL who belongs to the new records will be stored.
There seems to be one error: When I add a new record and only a new picture then the new record with only this picture in not stored even you will not be asked. This happens when you close the form without going to a new reocrd. I don't know if it is important to find a solution,
I do use now three events. These events are all bound to the form
When loading 'must be bound
Before record changed' Must only be bound when you want to change the pictures
After record changed ' Must be bound
I think but it is up to you that keep the form simple special when you use the possibility for insert new pictures. I did not test it intensive. What do I mean with simple: Have not a lot of fields in one (sub)form.
Romke
| Code: |
REM ***** BASIC *****
option explicit
' In the writer document I use only one form.
' Here are some constants.
' Do not change names before "=" but you can change the value after the "="
' If you have experience with programming change as much as you.
' When I use code from other people I change a lot and it learns me to understand.
' But I always kept the original save, until I understand it.
private const maxsize=12000 ' This is the maxsize of the image
private const sPictureName="ImageControl" 'Here comes the name of your control for the picture
private const sUrlField="URL" 'The fieldname in your database. Where your url is
private oBeginform as object' Form where the controls are
private oPicture ' This for the image control
' I do use now three events. This event are all bound to the form
' When loading
' Before record changed
' After record changed
' When loading this event is only run one time when the program is start. Maybe on other times
' It takes care for some thing who has only done one time and if it is good then it is ready
sub initroutine_when_loading(oEv as object)
' This routine must be called once when the form is load.
' I do it when for is loaded
obeginform=oEv.Source
oPicture=oBeginform.getbyname(sPictureName)
' This macro must be loaded
if not globalscope.BasicLibraries.islibraryloaded("Tools") then
' Load now the library
globalscope.BasicLibraries.loadlibrary("Tools")
end if
oPicture.ScaleImage=true
if 1=0 then
'Normal this is not used so don't change it
' I did use it for initing values only one time when designing a form
dim x ,y,docCtrl,oPictureShape
dim Point as new com.sun.star.awt.Point 'place where it comes
docCtrl = thisComponent.getCurrentController
oPictureShape = GetControlShape(docCtrl.Model,oPicture.name)
oPictureShape.zorder=8
'The measure take place in 1/100 mm
' for 8 cm you must give 8000
' Where must the picture be on the screen
x= 100
y=2000
Point.x=x
Point.y= y
' Place the strucs in the object who I want display
oPictureShape.setposition(Point)
end if
end sub
sub Before_record_change(oEv as object)
' This macro is called before the record is changed
' If the picture is changed then it takes care of that the the new url is placed in the desired field
' It must be bound to an event of the form : before record changed.
oBeginform=oEv.Source
with oBeginform ' Is to begin of form
if .implementationname= "com.sun.star.comp.forms.ODatabaseForm" then
if not .isbeforefirst then
'call Initroutine
oPicture=oBeginform.getbyname(sPictureName)
if ConvertFromURL(oPicture.ImageURL) <> .getstring(.findcolumn(sUrlField)) then
.updatestring(oBeginform.findcolumn(sUrlField),ConvertFromURL(oPicture.ImageURL))
if .isnew then
.insertrow
elseif .ismodified then
.updaterow
end if
end if
end if
end if
end with
end sub
'sub begintoon (oEv as object)
sub After_record_change (oEv as object)
' The calculation of the size doing in an other and faster way.
' Call this macro every time when you load a new record
' bind this to the form to the event go to new record
' this is not bound to the picture control
' The picture control has a empty date field
' Variable for form
' for handling the control how you see it in the database
obeginform=oEv.Source
oPicture=oBeginform.getbyname(sPictureName)
' Variables only for the picture for manupulation the size
oPicture.ImageURL= obeginform.getstring(obeginform.findcolumn(sUrlField))
MakeGoodSize oPicture ' Out commemt this call when you want not use resize
end sub
sub MakeGoodSize (oPicture as object)
dim docCtrl
' Variables only for the picture for manupulation the size
dim oPictureShape ' is for handling the control how you see it as drawing
dim oPictureGraphic ' This is something from the picture itself
dim scale ' I need this value for the size on screen
' For size you have to make special strucs
dim size as new com.sun.star.awt.Size
'const maxsize=9000
' Now we start working with the picture
docCtrl = thisComponent.getCurrentController
oPictureShape = GetControlShape(docCtrl.Model,oPicture.name)
oPictureShape.zorder=8
oPicture.ScaleImage=true
oPictureGraphic=oPicture.Graphic
if isnull(oPictureGraphic) then exit sub
' This is a new way for the calculations. It is faster. The reason I do understand it now better
' Which side is the greater. The side who has the greatest made the scale
select case sgn(oPictureGraphic.size.height- oPictureGraphic.size.width)
case 1,0 : scale= maxsize / oPictureGraphic.size.height
case -1 : scale= maxsize/ oPictureGraphic.size.width
end select
' Place the value in strucs
size.height=oPictureGraphic.size.height*scale
size.width=oPictureGraphic.size.width*scale
oPictureShape.setsize(size)
end sub
|
|
|
| Back to top |
|
 |
svdelst Newbie

Joined: 14 May 2009 Posts: 1 Location: Mexico
|
Posted: Wed May 20, 2009 9:16 am Post subject: Printing of images |
|
|
Thanks to all authors of posts in this thread, especially RPG. You guys have been extremely helpful to me integrating images in my database.
Regarding the printing I would like to comment that using the Report option is not an option for me, because somehow I have only been able to generate a report in a table like format, which looks horrible and is not appropriate for my data. Also I have not figured out how to display the pictures in the report.
However, using the Forms I have been able to design a nice looking form, that also enables me to display and print any picture, in any size I want.
I have been using OOo 3.1 on OSX PPC in German, because a Spanish or English function of the latest version was not available to me last month. By now they are. |
|
| Back to top |
|
 |
|