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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract Image, View Image, Resize and Rename from a VFP form

Status
Not open for further replies.

codetyko

Programmer
May 26, 2001
73
MY
I am developing a software for a repossesed vehicles store yard operator where upon arrival, the repossessed vehicles are captured with a digital camera. I keep the image file references in a table and I'm able to show all the required images in my form (front view, side view etc). The problem is , the operator will take the pictures in a 4.0 megapixel camera with a resolution of 1600 x 1200 and more importantly, the name of the images taken will be controlled by the camera itself. As a temporary measure, I installed IrfanView in my client's pc to reduce the size to 400x300 (jpeg) and renaming the new file to be loaded into the pictures directory. The main purpose here is:

1) create form
2) create thumbnail view control
3) use getdir() to get the images loaded into the form possibly with thumbnail view
2) a dblclick() or click() method to select the required image for display.
3) a resize button to resize it to the required size.
4) a rename option to rename the file

the reason for the reduction is to reduce the jpg size since there are 8 photos altogether and the images will be compiled to a pdf format and emailed to the bank for fast reporting.

Any suggestion is greatly appreciated.
 
codetyko
Couple of comments and ideas

Unless space is a problem, reducing the size of the images is not important - thread184-602560 is relevant to this thread.

You can create a thumbnail viewer by using a grid and replacing the default textbox control with an Image control into the one and only column.

What is important is to set the .Picture property indirectly using the .DynamicCurrentControl property of the column. The .DynamicCurrentControl calls a new form method such as .mJpegName(), and the code for the method might be :-

THIS.grdIMAGES.Column1.Image1.Picture = ALLT(MYIMAGES.filename)

As you are using the .DynamicCurrentControl only images that are visible will be rendered - if you use any other method, all images in the table will be rendered and you will suffer performance problems.

If your form is resizable, you could resize the grid in the .Resize() of the form.

You could use the .AfterRowColChange() event of the grid to display the selected image in another Image control on your form at a large size.

FAQ184-2483 - the answer to getting answered.​
Chris [pc2]
 
chris,

what I am looking for is to find an activex control to resize the images as these images (8 of them) will be printed to a pdf file for email purposes. Therefore, size does matter. The Kodak Image ocx shipped with windows, does it have a function to resize the DIMENSION of the images. I would prefer incorporating it in a form instead of using an external program like Irfanview. Anyway, should the first option is not feasible, how do you "insert" for example,Irfanview in your form and send keystrokes through code? Is it possible?
 
codetyko

To create your pdf with its eight images, create a report with detail band only and detail band as large as you can make it.

Place 8 Picture/ActiveX Bound controls in the detail band and size and position them to suit.

Select the 'Scale picture, retain shape', ie isometric, option from the properties sheet for each Picture/ActiveX Bound control.

You can then run your report to a postscript printer and create your pdf.

As you are scaling the images in the report, resizing them becomes irrelevant.

FAQ184-2483 - the answer to getting answered.​
Chris [pc2]
 
Thank you chris for the suggestion. I have created the report and you are right, no overhead in file size. However, as I've mentioned before, there still exist a requirement to send the images through email. With a reduction to 400 x 300 pixels, 8 images of about 36KB to 40kb will have a combined size of at least 300kb which is acceptable even with dial up connection. Any suggestions? Thank you in advance.
 
Codetyko,

. The Kodak Image ocx shipped with windows, does it have a function to resize the DIMENSION of the images

Kodak can redeminsion images. However, it cannot write JPEGS or GIFs (it can only read and display them). Also, I had a lot of trouble with corrupted images when using the control under Win 98. (It was fine with Win 2000.)

Also, be aware that the Kodak controls don't come with XP. You have to install the entire Kodak imaging package separately (not sure if there is a cost).

Mike


Mike Lewis
Edinburgh, Scotland
 
codetyko

Convert them from their original sizes to pdfs either as individual images or concatenate the postscript files and create a single multipaged pdf.

This will reduce the file size.

FAQ184-2483 - the answer to getting answered.​
Chris [pc2]
 
how do you concatenate the postsript files? I am not familiar with the proper syntax to do it.
 
codetyko

A typical image file from a camera with resolution set at 1600 x 1200 pixels will be between 700 and 800 KB, and will have a size of approximately 22" x 16"

The same image when converted to a pdf will be approximately 150 KB.

You can scale raster graphics, ie bitmaps, down to 0% and up by probably only 15-25% depending on the image. You are always scaling down hence the suggestion resizing is a waste of time and effort.

As I don't know how you are going to create the postscript files, I suggested concatenation of the postscript files in case you were printing from a graphics editor.

The easiest way would be for you to create a report as previously outlined with a single full size image, and then loop through a table printing each image in turn to a single postscript file, which in turn would be converted into a multipaged pdf.

By adding a label control to the report, you could then identify each image.

FAQ184-2483 - the answer to getting answered.​
Chris [pc2]
 
thanks chris for the explanation. The issue of converting to pdf and the resulting file size is hereby resolved. Maybe I did not make my explanation of the resize requirement quite clearly. I have created a form that will extract files based on their datetime properties and the latest update made and export it to a list of tables. These tables will be compressed using a zip utility and then sent to another branch for updating. Upon receipt of the file, the branch will decompress the file and subsequently update their data accordingly. These files being transported also includes jpg images in accordance with its respective path in one of the fields. This is the reason why the resizing is important because we are sending the files to branches, not the pdf version of it even though it also available as an option (to the banks who require the report) If there is a way to do this natively in foxpro I would be delighted to have a go instead of having to use a third party program even though maybe through shellexecute it might be possible.
 
codetyko

There is another and somewhat convoluted way you could resize the images within VFP and use a single external programs

The methodology would be as follows

Add an image control to a form, size it to suit.
Take a screenshot of the image control only, which would create a .bmp.
Use a freeware command line image utility and convert the .bmp to .jpg.
Send the .jpgs.


FAQ184-2483 - the answer to getting answered.​
Chris [pc2]
 
codetyko,

Just so I understand, you need to be able to resize existing jpg files and save them to disk...that's basically what you need to make this all work?

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
codetyko,

I'm working on it and will have it done soon, don't know if I can get you example yet tonight, cause it is about 2:30am here now...depends on how well it goes. But it is possible and I will post an example if someone else doesn't beat me to it.

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
codetyko,

Well here's a first draft...I will work more on it when I have time. It is 3:30 in the morning and I need to go to bed for now...if nothing else this shows you that it is possible, but there is too much image degradation in this example...I think I may switch over to GDI+ tomorrow and have a go at it that way (GDI+ is freely available from Microsoft). I'm hoping I can figure out how to do all sorts of stuff with images and make a comprehensive FAQ on it before I'm through. We'll get it one way or another. Before running this example you will need to get the freeware GLABCORE component from:


(Cut-n-paste the code below into a prg file and run it from within VFP)

PUBLIC oForm
oForm = CREATEOBJECT("clsimages")
oForm.show()

DEFINE CLASS clsimages AS form

Top = 0
Left = 0
Height = 407
Width = 416
DoCreate = .T.
Caption = "Form"
Name = "clsimages"


ADD OBJECT command2 AS commandbutton WITH ;
Top = 361, ;
Left = 300, ;
Height = 27, ;
Width = 84, ;
Caption = "Save", ;
Enabled = .F., ;
Name = "Command2"


ADD OBJECT image1 AS image WITH ;
Stretch = 2, ;
Height = 300, ;
Left = 32, ;
Top = 32, ;
Visible = .F., ;
Width = 350, ;
Name = "Image1"


ADD OBJECT command1 AS commandbutton WITH ;
Top = 361, ;
Left = 216, ;
Height = 27, ;
Width = 84, ;
Caption = "Open", ;
Name = "Command1"


ADD OBJECT spinner2 AS spinner WITH ;
Enabled = .F., ;
Height = 24, ;
KeyboardHighValue = 100, ;
KeyboardLowValue = 0, ;
Left = 32, ;
SpinnerHighValue = 100.00, ;
SpinnerLowValue = 0.00, ;
Top = 361, ;
Width = 72, ;
Value = 100, ;
Name = "Spinner2"


ADD OBJECT label1 AS label WITH ;
BackStyle = 0, ;
Caption = "Scale", ;
Height = 17, ;
Left = 32, ;
Top = 344, ;
Width = 40, ;
Name = "Label1"


PROCEDURE Load
PUBLIC oGlab
oGlab = CREATEOBJECT("Glabcore.GlabPicture")
ENDPROC


PROCEDURE command2.Click
oGlab.store("C:\Mypicture.jpg")
MESSAGEBOX("Your picture was saved as C:\Mypicture.jpg")
thisform.release
ENDPROC


PROCEDURE command1.Click
LOCAL cGetfile

cGetFile = GETPICT()

IF FILE(cGetFile)
this.Parent.image1.Picture = cGetFile
oGlab.Picture = LOADPICTURE(cGetFile)
this.Enabled = .f.
this.Parent.spinner2.Enabled = .t.
this.Parent.command2.Enabled = .t.
this.Parent.image1.Visible = .t.
ENDIF
ENDPROC


PROCEDURE spinner2.InteractiveChange
LOCAL nWidth, nHeight

nWidth = 350 * this.Value / 100
nHeight = 300 * this.Value / 100
this.Parent.image1.Width = nWidth
this.Parent.image1.height = nHeight
oGlab.ScaleTo(nWidth, nHeight)
ENDPROC


ENDDEFINE


Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
codetyko

To answer your question about Irfanview, the basic code for resizing an image is :-

"C:\Program Files\IrfanView\i_view32.exe" "C:\My Documents\My Pictures\Input\*.jpg /resize=(300,0)" "/convert=C:\My Documents\My Pictures\Output\*.jpg"

The "0" parameter ensures the images are isometric with a width of 300 pixels.

IrfanView will run hidden for this type of conversion, so all you would need is the WinAPI call CreateProcess() or WSH to launch the process, both of which will then return control to VFP after Irfanview has completed its processing.

However, you will need to obtain appropriate licences from Irfanview if you were to distribute their product with your application.

FAQ184-2483 - the answer to getting answered.​
Chris [pc2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top