Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

images on Form

Status
Not open for further replies.

hjohnson

Programmer
Aug 1, 2001
90
US
How can I get images to be viewed in a form? (VFP 5.0) I can get BMP file to display just fine, but JPG or Tif files only show as icons. Is there such a thing as an activeX image viewer or is there a better way.

Thanks for your help

HJ
 
I'm not sure how you are doing it (VFP5.0), but I
1. create a blank form
2. Put a oleControl on the form
3. It brings up a window to allow me to select a file.
4. I select a .jpg file on my system and it show up on the form.
Mike Gagnon
 
Mike

This is not a trick question but the answer to it escapes me.

How do you then change the .DocumentFile property of the olecontrol to be able to view another .jpg?

It has a relevance to thread184-343510. HTH

Chris [pc2]
 
hjohnson

An alternative to an oleControl is to use the Kodak Image Edit Control which you will find in your list of ActiveX controls.

(Kodak Imaging can also be installed on XP)

The control has advantages over an oleControl in that you can select the zoom level, view .tiff files with multiple pages, (requires Kodak Image Thumbnail Control as well), etc.

THISFORM.oleImageEdit.DataField = path\filename

will set the 'picture' property. HTH

Chris [pc2]
 
Chris

I read the thread you pointed to but I don't see the relevance. IMHO if you need to change pictures often in a Control then OLEBoundControl is a better choice since it has a controlsource. Even to create a general field in a temporary cursor. OleControl is more for displaying pictures (like company logos). Although if you double-click on the control it "should" bring some kind of photo editor or paint program, it still doesn't allow you to change picture. But I suspect that (I have not tried this.) if you can re-create the conditions you could use this:
Code:
sys(1500,"_MED_INSOB","_medit")
To bring up the Insert object window.

Hope that helps
Mike Gagnon
 
Mike

The topic of Thread184-343510 is 'MS ActiveX controls as viewers'

The topic of this form is similar whereby hjohnson asks 'Is there such a thing as an activeX image viewer'

The relevance is that an olecontrol suggested by yourself and both the two ActiveX controls mentioned in the thread have the common property .DocumentFile.

This is read-only and so how do you programatically change the .jpg, .xls or .ppt file which is being displayed in the relevant control?

If this can't be done programatically, then I don't see the practicality of using an olecontrol to view an image especially if you were scrolling through a grid, FI, and wanting to view different images. HTH

Chris [pc2]
 
Chris

As I suggested in this thread, the only way I found to actually change the picture being shown in a OleControl is to insert another olecontrol. This will bring up the "insert object" window. So on theory if you wanted to change a picture in an OleControl you would do it somethign like this:
Code:
PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show
RETURN


	**************************************************
*-- Form:         form1 (c:\word letter\form1.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*-- Time Stamp:   08/30/02 07:36:06 AM
*
DEFINE CLASS form1 AS form


	DoCreate = .T.
	Caption = "Form1"
	Name = "Form1"


	ADD OBJECT command1 AS commandbutton WITH ;
		Top = 192, ;
		Left = 96, ;
		Height = 27, ;
		Width = 84, ;
		Caption = "Command1", ;
		Name = "Command1"


	ADD OBJECT ole1 AS olecontrol WITH ;
		Top = 12, ;
		Left = 36, ;
		Height = 145, ;
		Width = 265, ;
		Stretch = 1, ;
		Name = "Ole1"


	PROCEDURE command1.Click
		thisform.RemoveObject("ole1")
		thisform.AddObject("ole1","olecontrol")
		thisform.ole1.visible = .t.
	ENDPROC


ENDDEFINE
*
*-- EndDefine: form1
**************************************************
Mike Gagnon
 
Mike

Thanks - you've confirmed my suspicions, unless anyone else has an answer as to how change the viewed file programatically, that, for me, the oleControl and the two ActiveX controls mentioned in Thread184-343510 are only suitable for use as specific file viewers, not across a range of files.

The resolution to Thread184-343510 was to print the file to be viewed to a postscript file.

From there, you either convert it to a .pdf or to a .tiff, the former format enabling viewing in a VFP form with the Adobe ActiveX Control for Acrobat, the latter in the Kodak Image Edit Control combined with the Kodak Image Thumbnail Control in a VFP form - either viewer able to handle any Windows file type that will print.

Returning to hjohnson's question, he does have a couple of options with a third being an upgrade to VFP 6/7.0, whereupon the VFP image control will display .jpgs but not .tiffs.

Another option would be to convert the image to .bmp format and use what hjohnson currently has.
HTH

Chris [pc2]
 
ChrisRChamberlain

Chris,
I took me a while but I may have the solution to displaying any format pictures on a form (at least any that I have tried). And believe this should be an FAQ since it's been asked many times before. It requires the "Imaging.EditCtrl.1" Activex, that comes with Win95 and up.
Code:
PUBLIC frmImage
frmMyForm = CREATEOBJECT('images_demo')  && Create a Form
frmMyForm.SHOW()  && Display the form
READ EVENTS
DEFINE CLASS images_demo AS FORM
	AUTOCENTER = .T.
	TOP = 0
	LEFT = 19
	HEIGHT =450
	WIDTH = 485
	DOCREATE = .T.
	CAPTION = "Show picture demo"
	NAME = "Form1"
	ADD OBJECT command2 AS COMMANDBUTTON WITH ;
		TOP = 372, ;
		LEFT = 26, ;
		HEIGHT = 34, ;
		WIDTH = 431, ;
		CAPTION = "Select Image file to show", ;
		NAME = "Command2"
	ADD OBJECT optiongroup1 AS OPTIONGROUP WITH ;
		AUTOSIZE = .F., ;
		BUTTONCOUNT = 4, ;
		VALUE = 1, ;
		HEIGHT = 27, ;
		LEFT = 26, ;
		TOP = 339, ;
		WIDTH = 431, ;
		NAME = "Optiongroup1", ;
		Option1.CAPTION = "Best fit", ;
		Option1.VALUE = 1, ;
		Option1.HEIGHT = 17, ;
		Option1.LEFT = 5, ;
		Option1.TOP = 5, ;
		Option1.WIDTH = 55, ;
		Option1.AUTOSIZE = .T., ;
		Option1.NAME = "Option1", ;
		Option2.CAPTION = "Fit to width", ;
		Option2.HEIGHT = 17, ;
		Option2.LEFT = 98, ;
		Option2.TOP = 5, ;
		Option2.WIDTH = 76, ;
		Option2.AUTOSIZE = .T., ;
		Option2.NAME = "Option2", ;
		Option3.CAPTION = "Fit to height", ;
		Option3.HEIGHT = 17, ;
		Option3.LEFT = 215, ;
		Option3.TOP = 5, ;
		Option3.WIDTH = 81, ;
		Option3.AUTOSIZE = .T., ;
		Option3.NAME = "Option3", ;
		Option4.CAPTION = "Actual size", ;
		Option4.HEIGHT = 17, ;
		Option4.LEFT = 330, ;
		Option4.TOP = 5, ;
		Option4.WIDTH = 76, ;
		Option4.AUTOSIZE = .T., ;
		Option4.NAME = "Option4"
	ADD OBJECT label1 AS LABEL WITH ;
		AUTOSIZE = .T., ;
		CAPTION = "Height", ;
		HEIGHT = 17, ;
		LEFT = 254, ;
		TOP = 412, ;
		VISIBLE = .F., ;
		WIDTH = 38, ;
		NAME = "Label1"
	ADD OBJECT label2 AS LABEL WITH ;
		AUTOSIZE = .T., ;
		CAPTION = "Width", ;
		HEIGHT = 17, ;
		LEFT = 381, ;
		TOP = 410, ;
		VISIBLE = .F., ;
		WIDTH = 33, ;
		NAME = "Label2"
	PROCEDURE INIT
	THISFORM.ADDOBJECT('olecontrol1','OleControl','Imaging.EditCtrl.1')
	THISFORM.olecontrol1.TOP = 2
	THISFORM.olecontrol1.LEFT = 26
	THISFORM.olecontrol1.HEIGHT = 333
	THISFORM.olecontrol1.WIDTH = 431
	THISFORM.olecontrol1.NAME = "Olecontrol1"
	THISFORM.olecontrol1.VISIBLE = .T.

	IF !EMPTY(THISFORM.olecontrol1.IMAGE) AND FILE(THISFORM.olecontrol1.IMAGE)
		THISFORM.olecontrol1.DISPLAY
	ENDIF
ENDPROC

	PROCEDURE DESTROY
	THISFORM.REMOVEOBJECT("olecontrol1")
	DODEFAULT()
	RELEASE ALL
	CANC
ENDPROC

	PROCEDURE command2.CLICK
	LOCAL lcFile
	m.lcFile = GETPICT()
	IF FILE(m.lcFile)
		THISFORM.olecontrol1.IMAGE = m.lcFile
		THISFORM.olecontrol1.DISPLAY
	ENDIF
ENDPROC
	PROCEDURE optiongroup1.CLICK
	THISFORM.olecontrol1.FitTo(THIS.VALUE-1)
ENDPROC
ENDDEFINE
Mike Gagnon
 
Mike

'the latter in the Kodak Image Edit Control combined with the Kodak Image Thumbnail Control in a VFP form'.

We're both refering to the same control but using different names.

That was the resolution to Thread184-343510 as stated in my last post, the difference being if you run to a .tiff via a postscript file, you can use the combination of the two Kodak Image controls to view any printable windows file, irrespective of how many pages the document may have.

Using your code directly with image files does not allow the viewing of multiple paged .tiffs as you have no mechanism for page selection.

Tiff's shouldn't be understimated - its easy to forget they support pages, so should you want to preview a number of image files of different types, you can programatically create a .tiff from the various files and use the Kodak Edit/Thumbnail control combination as a viewer.

You either need a combination of/or a navigation toolbar, combo, spinner or the Thumbnail control to facilitate that.

Your code's worthy of a FAQ, but, IMHO, you're still a large lump missing before it becomes a generic image viewer! HTH

Chris [pc2]
 
ChrisRChamberlain

I would suggest then to add another command button to open up a seperate page.
Code:
ADD OBJECT command1 AS commandbutton WITH ;
    Top = 466, ;
    Left = 26, ;
    Height = 60, ;
    Width = 431, ;
    Caption = "Open a separate window ", ;
    Visible = .F., ;
    Name = "Command1"
PROCEDURE command1.Click
    frmImage = CREATEOBJECT("frmimages")
    frmImage.Caption = "Image "+Thisform.olecontrol1.Image
    frmImage.AlwaysOnTop = .T.
    frmImage.BorderStyle = 3
    frmImage.Top = 10
    frmImage.Left = 10
    frmImage.Height = ThisForm.Spinner1.Value 
    frmImage.Width = ThisForm.Spinner2.Value
 
    frmImage.Addobject('oImgView1','OleControl','Imaging.EditCtrl.1')
    frmImage.oImgView1.Top = 5
    frmImage.oImgView1.Left = 5
    frmImage.oImgView1.Width = frmImage.Width - 5
    frmImage.oImgView1.Height = frmImage.Height - 5
    frmImage.oImgView1.Image = Thisform.olecontrol1.Image
    frmImage.oImgView1.FitTo(ThisForm.Optiongroup1.Value - 1)
    frmImage.oImgView1.Display
    frmImage.oImgView1.Visible = .T.
  
    frmImage.Show()  && Display the form
    
  ENDPROC

Mike Gagnon
comp14.gif
 
Chris

Disregard my last post, I misread you statement:Using your code directly with image files does not allow the viewing of multiple paged .tiffs as you have no mechanism for page selection.



Mike Gagnon
comp14.gif
 
Mike

What I would suggest would be to create a top-level form, add a toolbar class, menu and the Image Edit ActiveX control.

This would give the viewer the look and feel of a standalone application.

The toolbar class would have the following controls

A set of 4 navigation buttons for page navigation and a read-only textbox displaying the page count. (If the file is not a .tiff, these controls would be disabled). The .FileType property of the olecontrol can be utilised for this.

A spinner to alter the zoom level, 4 graphical checkboxes for Best Fit, Fit to Width, Fit to Height, and Inch to Inch (Actual size). You could also add other preset zoom level graphical checkboxes as well.

The menu would duplicate the toolbar class with the exception of the spinner.

In the .Resize() event of the form, resize the olecontrol to be form width and height.

The properties for navigation are :-

PageCount
ActivePage

The zoom property is :-

Zoom

The .FitTo() method takes a parameter of :-

0 - Best Fit
1 - Fit to width
2 - Fit to height
3 - Inch to Inch (Actual size)

You now have a simple thumbnailless all purpose graphical image viewer, capable of viewing :-

TIFF
AWD
BMP
PCX
DCX
JPG
XIF
GIF
WIFF HTH

Chris [pc2]
 
Chris

The idea is comming along quite nicely. But I have one question, I haven;t really dealt with graphics (mostly data) over the years of programming too much but when you say:
A set of 4 navigation buttons for page navigation and a read-only textbox displaying the page count. (If the file is not a .tiff, these controls would be disabled). The .FileType property of the olecontrol can be utilised for this.

If it's a .tiff file, is ther a way within VFP (Or the activex itself ) to determine the page count?


Mike Gagnon
comp14.gif
 
Mike

Sorry, I wasn't very explicit.

'The properties for navigation are :-

PageCount
ActivePage'

The olecontrol has those two properties, so the .PageCount value would be the value of the read-only Textbox.

You could have another textbox indicating the .ActivePage if required.

The .ActivePage value can be any value from 1 to the .PageCount value - that then selects the page to display. So the navigation buttons work in the same way as they would for a table, being enabled, disabled etc depending on the .ActivePage value.

By removing the thumbnail control, it removes the complexity of the additional code required to make it all work, with the navigation buttons and textbox(s) replacing the functionality of the thumbnail control. Using a toolbar also maximizes the viewing area.

The .FitTo() method changes the view and is supplemented by the additional graphical checkboxes for preset zoom levels.

The spinner value would need to be determined by whichever checkbox had been selected so it becomes a natural progression up or down from that value, the .InterActive() change event of the spinner changing the zoom factor.

The menu isn't strictly necessary - it's just a personal thing. Combine top-level form, menu and toolbar together and you do get what appears to be a mini-app.

What it hopefully would do is encourage developers to use tiffs as described in earlier posts - FI, you could use it as a VFP report previewer by running the report to a .ps file and then to a .tiff. A multiple paged report produces a multiple paged .ps which produces a multiple paged .tiff.

If it's to be a useful FAQ, I think it needs to be simple enough implement straight away. HTH

Chris [pc2]
 
hjohnson

Apologies if it appears you are being ignored by the discussion between Mike and I! [sad]

That is not the case - between us, and anyone else who cares to contribute, I am hopeful we can produce a FAQ which will answer your original question, 'Is there such a thing as an activeX image viewer or is there a better way'. HTH

Chris [pc2]
 
hjohnson

As Chris has stated, you are not being ignores but questions (such as youra) sometimes get ideas rolling and eventually your question and hopefully other questions that others and you might have get answered in the "thinking process"

Chris

What it hopefully would do is encourage developers to use tiffs as described in earlier posts - FI, you could use it as a VFP report previewer by running the report to a .ps file and then to a .tiff. A multiple paged report produces a multiple paged .ps which produces a multiple paged .tiff.[


Using a Generic Adobe Postscript printer driver? And from there possibly a PDF file using GhostScript?


Mike Gagnon
comp14.gif
 
Hey, I am just a visitor here but you guys are great....

Love the dialog and the impressed by the interplay...the intellectual contribution is fantastic...

My contribution is to try and keep up..

Cheers

FoxEgg
Sydney, OZ
 
...and by the way... in VFP7 all I did was set the

picture property to any .jpg image from the properties selector........

and bingo... full screen mother-in-law or full screen pet dog or whatever ..

AND I can even put controls on top of it...

eg "Down Fido" (... that would be on the dog screen of course)

Foxegg
 
Mike

'Using a Generic Adobe Postscript printer driver?'

Yes - once you have a .ps file you can convert it to different formats using GhostScript, the best known being .pdf.

Converting to .tiff requires a similar GhostScript command line string.

The reason behind suggesting the viewer as a report previewer is that a user would only have to familiarise themselves with one VFP form, which, as currently constructed, should be fairly simple to understand.

If you had Word or Excel documents, as an example, they could also be viewed as a multipaged tiff.

Where we're heading, I hope, is towards a single generic VFP document viewer.

'And from there possibly a PDF file using GhostScript?'

Yes - simply run Ghostscript again on the original .ps file to convert to .pdf
HTH

Chris [pc2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top