Zooming out on an image

Discussions about image processing and document imaging.
Post Reply
greenware
Posts: 16
Joined: Tue Jan 10, 2012 7:15 pm

Zooming out on an image

Post by greenware » Fri Feb 17, 2012 12:49 am

I have a GDViewer (overlaying a background image) and zooming out on the forground image to make the image smaller. I need to both pan the foreground image to position it over the background as well as save the image from the viewer.

I have no problem when zooming in on the image using the GetDisplayedArea and Crop and Resize methods but when I zoom out, GetDisplayedArea always returns 0 rather than go negative. and when you zoom out, using the mouse to pan the image does nothing when the image is smaller than the viewer.

Below is the code I use to resize the image from the viewer and save it when zoomed in.

Is there some way to save the image as displayed in the viewer when zoomed out?

thanks,

John

Code: Select all

Dim left as integer, top as integer, width as integer, height as integer
Dim MainImage As Integer = Imaging1.CreateGdPictureImageFromFile(gdViewer1.tag)

gdViewer1.GetDisplayedArea(Left, Top, Width, Height)

Imaging1.Crop(MainImage, Left, Top, Width, Height)
Imaging1.ResizeHeightRatio(MainImage, 2100, Drawing2D.InterpolationMode.HighQualityBicubic)

Imaging1.SaveAsJPEG(newimage, "C:\Temp\ImageTest.jpg")
Imaging1.ReleaseGdPictureImage(MainImage)

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

Re: Zooming out on an image

Post by Loïc » Fri Feb 17, 2012 5:21 pm

Hello John,

I do not understand at all your explanations. Especially here:
when I zoom out, GetDisplayedArea always returns 0 rather than go negative. and when you zoom out, using the mouse to pan the image does nothing when the image is smaller than the viewer.
Could you please give me some other explanations ? A standalone simple application attached to the thread should be a great help (if any, please zip it and remove license key).

Kind regards,

Loïc

greenware
Posts: 16
Joined: Tue Jan 10, 2012 7:15 pm

Re: Zooming out on an image

Post by greenware » Fri Feb 17, 2012 6:24 pm

Sorry, let me try to explain more clearly.

I have a gdViewer on a form with a picture in it.
ImageSrc = oGdPictureImaging.CreateGdPictureImageFromFile(sFileName)
gdViewer.ZoomMode = ViewerZoomMode.ZoomModeWidthViewer
gdViewer.MouseMode = ViewerMouseMode.MouseModePan
gdViewer.MouseWheelMode = ViewerMouseWheelMode.MouseWheelModeZoom
gdViewer.DisplayFromGdPictureImage(ImageSrc)

At this point, if I call "gdViewer.GetDisplayedArea(Left, Top, Width, Height)", Left and Top are both 0.
If I use the mouse wheel to zoom in on the picture and call GetDisplayedArea, Left and Top are some positive numbers specifying the left and top pixel within the image and I can crop to those values and resize as needed.
If I use the mouse wheel to zoom out on the picture so that the entire picture is now smaller than the viewer and call GetDisplayed Area, Left and Top are 0 - no matter how small the image gets.

My problem is that I need to make the loaded picture smaller than the viewer and be able to move the image around within the viewer.

For example, say I have a full length (from head to toe) picture of you taken on a green background and you take up the whole picture from top to bottom.
I also have a background image of a house with an open front door. I can overlay the picture of you on the background and remove the green showing the house behind you but you are way too big for the house. I use the mouse wheel to make you smaller to where you would fit nicely within the scene but the mouse does not let me move the scaled down picture to position you correctly. Also, I can't figure out how to save this composite image from the viewer to a file on my computer. (Note: I have no problem saving composit images where the forground image is equal to or larger than the viewer area). Also, it would be real nice to be able to save an image directly from a viewer or better yet save it directly to gdPictureImaging object where I could further manipulate it.

I hope that helps explain my needs better.

thanks,

John

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

Re: Zooming out on an image

Post by Loïc » Sat Feb 18, 2012 12:37 pm

Hello John,

I am really sorry but I am totally lost with your explanations. Maybe we should try to run "step by step".

Seems you are complaining about the returned values of the GetDisplayedArea method. Have you understood what is the purpose of this method ?
"Returns the coordinates in pixel of the visible area of the displayed document"
So if you can see the whole document in the viewer, it is normal to get (0,0) coordinates for the top-left point of the first visible point.

If you need to compute the position on the document within the viewer, you have to use the GetDocumentleft() & GetDocumentTop() methods.

Hope this helps a bit.

kind regards,

Loïc

greenware
Posts: 16
Joined: Tue Jan 10, 2012 7:15 pm

Re: Zooming out on an image

Post by greenware » Sun Feb 19, 2012 12:28 am

Sorry, didn't mean to sound like I was complaining. Very much the opposite as I'm very impressed with your product.

What I''m trying to ask is how do I perform a certain function - if possible.

So please forget everything else and I'll try again.

I have a need to scale down a foreground image to be placed over a background image. I have the foreground viewer embedded in the background viewer and everthing works fine until I scale the foreground image down and try to create a composite image of the two.

Attached is a picture that may help describe what I'm doing.

Question 1: How do I take an image that was scaled down to be smaller than the viewer, draw it onto the background image, and save it to a file?

Question 2: Is there a way to use the mouse to move the foreground image around? Currently, when the image is smaller than the viewer, you can no longer move the image.

I hope this helps.
Attachments
greenscreen2.jpg

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

Re: Zooming out on an image

Post by Loïc » Mon Feb 20, 2012 12:11 pm

Hello John,
Sorry, didn't mean to sound like I was complaining.
Hey no problem :) Maybe the word "complaining" is too hard. My bad. I'm just trying to point you in the right direction.

That said, I am starting to understand a bit what you are trying to do. And I am not sure your approach is the best one to achieve such overlaying task.

Question 1: How do I take an image that was scaled down to be smaller than the viewer, draw it onto the background image, and save it to a file?
I really suggest you to consider the annotation approach. By this way it should be easy to move the foreground with mouse action keeping full alpha blending support.
Other solution consists to implement your own overlaying support by moving a GdViewer object over another one. But this requires some code. And to save the result, you have to use the GdPictureImaging class to create a GdPicture bitmap from the main form handle. See CreateGdPictureImageFromHWND method.

Code: Select all

Question 2: Is there a way to use the mouse to move the foreground image around? Currently, when the image is smaller than the viewer, you can no longer move the image.
Hum this is not possible. Maybe a workaround can consist to resize the GdViewer object to fit the image size. And then, try to move the GdViewer object on your form by catching mouse events.

Hope this brings some lights.

Kind regards,

Loïc

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests