Load JPG, rotate it, save it and then create thumb

Discussions about image processing and document imaging.
Post Reply
mschiff
Posts: 11
Joined: Mon Dec 01, 2008 10:49 pm

Load JPG, rotate it, save it and then create thumb

Post by mschiff » Mon Dec 01, 2008 11:07 pm

I am using Visual FoxPro 9 and am trying to load a JPG image into the imaging control, rotate it, then save it, and finally create a thumbnail for the rotated JPG as a separate JPG in a variable size that I specify.

I have instantiated the control with the name "imageviewer". pictoedit is a string variable with the full path and filename of the JPG file.

I am loading the file with:

THISFORM.imageviewer.CreateImageFromFile(pictoedit)

Then rotating it with

thisform.imageviewer.rotate(3) (or another number depending on what the user choose to do)

Then I am trying to save the image with

THISFORM.imageviewer.SaveasJPG(pictoedit,8)

However, I get an OLE error code 0x80020006: Unknown name error.

What am I doing wrong? Then how would I go about creating a thumbnail of a maximum side of "N" pixels?

--- Martin

mschiff
Posts: 11
Joined: Mon Dec 01, 2008 10:49 pm

Re: Load JPG, rotate it, save it and then create thumb

Post by mschiff » Tue Dec 02, 2008 12:01 am

I also tried this using

thisform.imageviewer.JPEGTransformRotate("c:\test\test.jpg","c:\test\newtest.jpg",16)

and I get the same OLE error.

-- Martin

mschiff
Posts: 11
Joined: Mon Dec 01, 2008 10:49 pm

Re: Load JPG, rotate it, save it and then create thumb

Post by mschiff » Tue Dec 02, 2008 4:58 pm

I created a new form with a single button that contains this code:


thisform.imageviewer.JPEGTransformRotate("c:\test\test.jpg","c:\test\newtest.jpg",16)

In the form's INIT method, I put in the registration string for the control.

I still get the same OLE error.

I really need a solution to this problem.


-- Martin

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Load JPG, rotate it, save it and then create thumb

Post by Loïc » Tue Dec 02, 2008 6:10 pm

Hi Martin,

The functions you are trying to call are into the Imaging class and not into the GdViewer class. This is because you have your error message.

Just load the image into the Imaging class and do what you need with it ;)

Best regards,

Loïc

mschiff
Posts: 11
Joined: Mon Dec 01, 2008 10:49 pm

Re: Load JPG, rotate it, save it and then create thumb

Post by mschiff » Tue Dec 02, 2008 8:17 pm

Loïc,

If you read my first message, you can see that I am using the image control. I just gave the object a name of imageviewer, but it is the imaging control that I have loaded on the form.

-- Martin

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Load JPG, rotate it, save it and then create thumb

Post by Loïc » Tue Dec 02, 2008 8:35 pm

Sorry Martin.


The reason of your error:

There is no method JPEGTransformRotate & SaveasJPG In the Imaging class.

Try instead:

SaveAsJPEG() and TransformJPEG().

Loïc

mschiff
Posts: 11
Joined: Mon Dec 01, 2008 10:49 pm

Re: Load JPG, rotate it, save it and then create thumb

Post by mschiff » Tue Dec 02, 2008 8:40 pm

Thanks Loïc, I had gone back and discovered my error with the method names. It works fine now. Sorry for the inconvenience.

-- Martin

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Load JPG, rotate it, save it and then create thumb

Post by Loïc » Tue Dec 02, 2008 8:43 pm

No problem Martin !

Best regards,

Loïc

mschiff
Posts: 11
Joined: Mon Dec 01, 2008 10:49 pm

Re: Load JPG, rotate it, save it and then create thumb

Post by mschiff » Tue Dec 02, 2008 10:56 pm

Loïc,

Will the transformJPEG method allow you to losslessly rotate a file to the same name?

as in:

object.transformJPEG("myfile.jpg","myfile.jpg",13)

-- Martin

mschiff
Posts: 11
Joined: Mon Dec 01, 2008 10:49 pm

Re: Load JPG, rotate it, save it and then create thumb

Post by mschiff » Tue Dec 02, 2008 11:06 pm

One more question.

I have a form with an imaging control and a viewer, and a radio button that lets the user choose what rotation to use for a group of files that was previously selected.

I want to be able to display in the viewer control each file as it is rotated, both before and after it is rotated, and I want to rotate losslessly using transformJPEG().

Right now, I load the JPG image into the imaging control, and then load the viewer from the imaging control. Then I call the transformJPEG to rotate the image, and then I re-load it into the image control and then to the viewer.

At that point I need to create a thumbnail file of the image of a size that is stored in my program. I have previously stored the height and width and adjusted those based on how it was rotated, so it should not be hard to do this from the imaging control with a resize, but it seems like I am doing too many reads and writes to accomplish this task. Basically all I want to do is losslessly rotate the images, but I would like to display what is going on if it won't slow things down too much.

Is there a better way to accomplish this?

-- Martin

mschiff
Posts: 11
Joined: Mon Dec 01, 2008 10:49 pm

Re: Load JPG, rotate it, save it and then create thumb

Post by mschiff » Wed Dec 03, 2008 9:41 pm

I figured out a better way that should have very little overhead. After I rotate the image in the imaging control, I rotate it by the same amount in the viewer control. That way I don't have to go back to the disk at all. Works well, and does not seem to have much overhead at all.

-- Martin

Naomi
Posts: 1
Joined: Thu Mar 08, 2012 10:48 pm

Re: Load JPG, rotate it, save it and then create thumb

Post by Naomi » Fri Mar 09, 2012 12:25 am

Do you know if there is a load blob picture data directly to the control using VFP? I have the picture in the blob field and I will have to create a temp file using strtofile to use DisplayFromFile method. I am wondering if we can somehow utilize any other method using the binary string with data from the blob field?

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest