Create cloned image area!

Discussions about image processing and document imaging.
Post Reply
Vxvx
Posts: 8
Joined: Wed Feb 03, 2010 11:48 am

Create cloned image area!

Post by Vxvx » Thu May 20, 2010 9:56 am

Hi!

After I display pdf, I need to select area on the displayed image and save only selected area as new bmp image. This is the code that I use:

Code: Select all

   Public Sub show()
        Dim TempFile = System.IO.Path.GetTempPath & Now.Ticks & ".bmp"
        Dim npdfID, imageid As Integer
        Dim GdPictureImaging As New GdPictureImaging
        npdfID = GdViewer1.PdfRenderPageToGdPictureImage(220, GdViewer1.CurrentPage)
        Dim LeftArea, TopArea, WidthArea, HeightArea As Integer
        If GdViewer1.IsRect Then
            Call GdViewer1.GetRectCoordinatesOnDocumentInches(LeftArea, TopArea, WidthArea, HeightArea)
            imageid = GdPictureImaging.CreateClonedGdPictureImageArea(npdfID, CInt(LeftArea), CInt(TopArea), CInt(WidthArea), CInt(HeightArea))
            GdPictureImaging.SaveAsBMP(imageid, TempFile)
        Else        
        End If
    End Sub
With this code I am able to save new bmp image but saved image does not have content of displayed image, it's just white.
What I am doing wrong? Thanks!

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

Re: Create cloned image area!

Post by Loïc » Thu May 20, 2010 3:50 pm

Hi,

On a hand you are working in inches coordinates & on another in pixels :)

Just replace GetRectCoordinatesOnDocumentInches by GetRectCoordinatesOnDocument

Kind regards,

Loïc

Vxvx
Posts: 8
Joined: Wed Feb 03, 2010 11:48 am

Re: Create cloned image area!

Post by Vxvx » Fri May 21, 2010 10:36 am

Hi Loïc!
Thanks for answer! Now I am able to save image, but the problem is that saved image is not zone that I select from the displayed image!
I think that I am doing some thing wrong with coordinates!
This is the code that i am using now:

Code: Select all

Public Sub Imageshow()
        Dim TempFile = System.IO.Path.GetTempPath & Now.Ticks & ".bmp"
        Dim npdfID, imageid As Integer
        Dim GdPictureImaging As New GdPictureImaging
        npdfID = GdViewer1.PdfRenderPageToGdPictureImage(220, GdViewer1.CurrentPage)
          Dim LeftArea, TopArea, WidthArea, HeightArea As Integer
        If GdViewer1.IsRect Then
           Call GdViewer1.GetRectCoordinatesOnDocument(LeftArea, TopArea, WidthArea, HeightArea)
            imageid = GdPictureImaging.CreateClonedGdPictureImageArea(npdfID, LeftArea, TopArea, WidthArea, HeightArea)
           GdPictureImaging.SaveAsBMP(imageid, TempFile)
        Else
        End If
    End Sub

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

Re: Create cloned image area!

Post by Loïc » Fri May 21, 2010 10:56 am

Hum...

Seems you are not displaying the npdfID image on the viewer.

So here another solution for you (not tested but should work):

Code: Select all

Private Const PDF_DPI_RENDERING = 200 'You can change it

Public Sub Imageshow()
        Dim TempFile = System.IO.Path.GetTempPath & Now.Ticks & ".bmp"
        Dim npdfID, imageid As Integer
        Dim GdPictureImaging As New GdPictureImaging
        npdfID = GdViewer1.PdfRenderPageToGdPictureImage(PDF_DPI_RENDERING, GdViewer1.CurrentPage)
          Dim LeftArea, TopArea, WidthArea, HeightArea As Single
        If GdViewer1.IsRect Then
           Call GdViewer1.GetRectCoordinatesOnDocumentInches(LeftArea, TopArea, WidthArea, HeightArea)
            imageid = GdPictureImaging.CreateClonedGdPictureImageArea(npdfID, LeftArea*PDF_DPI_RENDERING/72, TopArea*PDF_DPI_RENDERING/72, WidthArea*PDF_DPI_RENDERING/72, HeightArea*PDF_DPI_RENDERING/72)
           GdPictureImaging.SaveAsBMP(imageid, TempFile)
        Else
        End If
    End Sub


Let me know if it is working.

Loïc

Vxvx
Posts: 8
Joined: Wed Feb 03, 2010 11:48 am

Re: Create cloned image area!

Post by Vxvx » Fri May 21, 2010 12:27 pm

Hi! I change GetRectCoordinatesOnDocumentInches to GetRectCoordinatesOnDocument from your code, but it's still not working fine.
Now when i change zoom ratio for displayed image and then select area for clone, i am getting different image from selected are.

I really don't know what is the problem!

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

Re: Create cloned image area!

Post by Loïc » Fri May 21, 2010 12:29 pm

OK let me some minutes I will write you a demo application.

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

Re: Create cloned image area!

Post by Loïc » Fri May 21, 2010 12:39 pm

Hi,

Please try attached sample:

- Open a PDF
- Switch to area selection mode for left click
- Select an area
- Click Option/Save selected area to image

Enjoy !
Attachments
demo.zip
(14.31 KiB) Downloaded 539 times

Vxvx
Posts: 8
Joined: Wed Feb 03, 2010 11:48 am

Re: Create cloned image area!

Post by Vxvx » Fri May 21, 2010 2:41 pm

It's work perfect!

Thank you so much!

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

Re: Create cloned image area!

Post by Loïc » Fri May 21, 2010 2:43 pm

You are welcome dude :)

rlagrange
Posts: 30
Joined: Tue May 02, 2017 5:51 pm

Save selected area in rotated documents

Post by rlagrange » Tue May 23, 2017 5:41 pm

Hi,

I'm in a similar position than here : viewtopic.php?f=30&t=2558
but my documents are rotated.

The only way I found is to Render the page to picture, cancel the rotation by applying an inverse rotation of the effective one, then crop the picture with the RectCoordinatesOnDocuments.
This work well, but the rotation is done on the whole page before crop, which take time.

But i'm unable to find a way to crop the picture before rotating it, I'm always lost in coordinates references whatever i'm doing :
RectCoordinateOnDocument is without the rotation
RenderPageToGdPictureImage is always rotated
RectCoordinateOnViewer, always rotated, doesn't solve the issue as we can't know the margin into the viewer to fit the page

Could you provide a sample demonstrating that ?
Thanks

jamesin8
Posts: 2
Joined: Mon Jan 14, 2019 3:15 am

Re: Create cloned image area!

Post by jamesin8 » Mon Jan 14, 2019 3:23 am

The example is no longer a valid download link. Could you please provide an updated example of this functionality?

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

Re: Create cloned image area!

Post by Loïc » Tue Jan 15, 2019 3:40 pm

Hi,

there is now an example in the reference guide for such purpose:
https://www.gdpicture.com/guides/gdpicture/web ... Image.html

Kind regards,

Loïc

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest