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

WIA.Imagecontrol 2

Status
Not open for further replies.

button71

Programmer
Nov 8, 2006
69
AU
I have successfully worked two of the image manipulation options into my application. As the code given in the help file is for VB some do not work straight off.

I'm looking for some help in converting a few lines in to VFP code.

1 Cropping
Code:
	IP.Filters.Add (IP.FilterInfos("Crop").FilterID)
	
	IP.Filters(1).Properties("Left") = (Img.Width)\4
	IP.Filters(1).Properties("Top") = Img.Height\4
	IP.Filters(1).Properties("Right") = Img.Width\4
	IP.Filters(1).Properties("Bottom") = Img.Height\4

this does not compile.

2 Adding an exif title

Code:
Img = CreateObject("WIA.ImageFile")
	IP = CreateObject("WIA.ImageProcess")
	v = CreateObject("WIA.Vector")

	myownpicture = justfname(mypicture)
	mypath = addbs(justpath(mypicture))
	Img.LoadFile(mypicture)
	
IP.Filters.Add (IP.FilterInfos("Exif").FilterID)
IP.Filters(1).Properties("ID") = 40091
IP.Filters(1).Properties("Type") = VectorOfBytesImagePropertyType

cMessageText = 'Overwrite any previous Exif Title?'

	nAnswer = MESSAGEBOX(cMessageText, 4+32 ,cMsgTitle)

if nAnswer =6

	v.SetFromString.value = "This Title tag written by PicWiz!" + mytitle
	
	IP.Filters(1).Properties("Value") = v
	Img = IP.Apply(Img)
	Img.SaveFile(mypicture)

endif

No title is written to the exif of the subject file.

Any clues anyone?

Thanks

William

 
In your cropping code, it looks like you've used "\" where you should have "/".

Tamar
 
Thanks Guys!

I took my code out of the WIA Help file.

I now have
Cropped
Resize
Rotate working.

BUT the Title code above doesn't work and I really want this one!

Anything further?

William
 
No title is written to the exif of the subject file.

There are a few problems with your code. You must be getting errors before the end of the code.
1. I take it the "mypicture" variable is declared somewhere else
2. You cannot use "VectorOfBytesImagePropertyType" in Foxpro, you need the numerical equivalent. In this case 1101
3. The "SetFromString" expects a value, not a string.


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
Mike,

Thank you very much.

No - the code compiled without error and ran - with no result.

I have searched the net extensively including the French language articles. I wonder where the list of 'numbers' like 1101 is?

The "SetFromString" expects a value, not a string.

I now find

Code:
v.SetFromString ( "This Title tag written by PicWiz!" + mytitle)

IP.Filters(1).Properties("Value") = v


Inserts the new string into the object but in the 'Extras' area of Exif rather than the title ?

Maybe another number than 1101?

I'm searching again for a list.

Regards

William
 
have searched the net extensively including the French language articles. I wonder where the list of 'numbers' like 1101 is?
Inserts the new string into the object but in the 'Extras' area of Exif rather than the title ?
I am not sure what area is "Extras". But if I use the code below, and I rightmouse on the newly created picture, and go to the summary tab, I see the title there. Please be aware that this requires Windows XP SP1.



Code:
Img = CreateObject("WIA.ImageFile")
IP = CreateObject("WIA.ImageProcess")
v = CreateObject("WIA.Vector")

Img.LoadFile( "e:\WINDOWS\Web\Wallpaper\Autumn.jpg")

IP.Filters.Add( IP.FilterInfos("Exif").FilterID)
IP.Filters(1).Properties("ID") = 40091
IP.Filters(1).Properties("Type") = 1101

v.SetFromString("This Title tag written by Windows Image Acquisition Library v2.0")

IP.Filters(1).Properties("Value") = v

Img = IP.Apply(Img)

Img.SaveFile("e:\WINDOWS\Web\Wallpaper\AutumnExif.jpg")


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
Mike,

I still can't see where my old code is incorrect but yours above has solved that problem.

Can you please tell me if the 'Convert to jpg' example should copy the picture with a changed extension?

I rewrite the file with a jpg extension after

Code:
Img = IP.Apply(Img)

But the saved image still has say bmp ident in the first chrs of the file.

Have you a working piece of code for that too?

Many thanks

William
 
I still can't see where my old code is incorrect but yours above has solved that problem.

Code:
IP.Filters(1).Properties("Type") = VectorOfBytesImagePropertyType

v.SetFromString.value = "This Title tag written by PicWiz!" + mytitle

Code:
IP.Filters(1).Properties("Type") = 1101

v.SetFromString("This Title tag written by Windows Image Acquisition Library v2.0")

Now do you see?

The "convert to jpg" example does not just change the extension. You have to specify the format in the filter. The format for jpg is "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}". Another point to take notice is the quality property, the code below will remove 95% of the quality of the original image. If you want 100%, change the value to 100.

Code:
Img = CreateObject("WIA.ImageFile")
IP = CreateObject("WIA.ImageProcess")
Img.LoadFile( "c:\WINDOWS\Web\Wallpaper\Bliss.bmp")
IP.Filters.Add( IP.FilterInfos("Convert").FilterID)
IP.Filters(1).Properties("FormatID").Value = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}" && JPG format
IP.Filters(1).Properties("Quality").Value = 5
Img = IP.Apply(Img)
Img.SaveFile( "c:\WINDOWS\Web\Wallpaper\BlissCompressed.jpg")


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
Hi Mike,

Thanks once again.

I _had_ put the 1101 in my code so lets leave it that it now works fine.

I have now ( with your help) completed the editing actions that I was trying for.

A thousand thanks - this will be a free utility.

Regards

Willam

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top