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: 5592
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: 5592
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: 5592
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: 5592
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 179 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: 5592
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 :)

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest