Drawing Text

Discussions about image processing and document imaging.
Post Reply
mattewan
Posts: 33
Joined: Fri Apr 03, 2009 5:58 pm

Drawing Text

Post by mattewan » Tue Sep 01, 2009 2:42 pm

Hello,

I am trying to draw text on an image, but having problems.

Code: Select all

                    'Open Image
                    ImageID = imaging.CreateGdPictureImageFromFile(OneBatchItem.inFile)

                    'Add Border
                    imaging.AddBorderBottom(ImageID, 140, Color.White)

                    'Calculate Text Position
                    TextWidth = imaging.GetTextWidth(ImageID, Replace(My.Computer.FileSystem.GetName(OneBatchItem.inFile).Substring(0, Len(My.Computer.FileSystem.GetName(OneBatchItem.inFile)) - 4), "-", "/"), "Arial", 32, GdPicture.FontStyle.FontStyleRegular)
                    TextWidthPos = (imaging.GetWidth(ImageID) / 2) - (TextWidth / 2)

                    'Draw Text
                    imaging.DrawText(ImageID, Replace(My.Computer.FileSystem.GetName(OneBatchItem.inFile).Substring(0, Len(My.Computer.FileSystem.GetName(OneBatchItem.inFile)) - 4), "-", "/"), TextWidthPos, imaging.GetHeight(ImageID) - 120, 32, GdPicture.FontStyle.FontStyleRegular, Color.Black, "Arial", True)

                    'Convert Back to B&W
                    imaging.ConvertTo1Bpp(ImageID)

                    'Save
                    imaging.SaveAsTIFF(ImageID, OneBatchItem.outFile, GdPicture.TiffCompression.TiffCompressionCCITT4)

                    'Release
                    imaging.ReleaseGdPictureImage(ImageID)
Basically, if i run the above code it works, as long as i comment out imaging.ConvertTo1Bpp. I get an LZW File, colour, with a border added to the bottom with the text centered in that border.

However, when i uncomment the imaging.ConvertTo1Bpp it correctly saves to B&W Tiff Group4 but the border & text are not applied.

Using the latest version, or previous versions, they all perform the same results.

Thanks

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

Re: Drawing Text

Post by Loïc » Tue Sep 01, 2009 3:00 pm

Hi,

To reproduce your behavior I need an example of value of OneBatchItem.inFile & OneBatchItem.outFile

With best regards,

Loïc

mattewan
Posts: 33
Joined: Fri Apr 03, 2009 5:58 pm

Re: Drawing Text

Post by mattewan » Tue Sep 01, 2009 4:57 pm

Code: Select all

?OneBatchItem.inFile
"s:\matt\input\plan_0001.tif"
?OneBatchItem.outFile
"s:\matt\output\plan_0001.tif"

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

Re: Drawing Text

Post by Loïc » Tue Sep 01, 2009 5:02 pm

Hi,

All is working fine for me with or without the convention.

Which version are you using ?
Could you check the returned values of the GdPicture methods ?

Kind regards,

Loïc

mattewan
Posts: 33
Joined: Fri Apr 03, 2009 5:58 pm

Re: Drawing Text

Post by mattewan » Wed Sep 02, 2009 11:17 am

ok this is very strange..... I added some debug.print lines to vb to find out certain values as it runs,

Now, the code is still the same as above, with the convert to 1bpp commented out, and when running it i get this:

Code: Select all

clsWorkerThread.ProcessBatch() GDVersion: 6.4
### R:\Originals\HB1003-210.tif ###
clsWorkerThread.ProcessBatch() ImageID: 44929140
clsWorkerThread.ProcessBatch() Tiff Compression: 4
clsWorkerThread.ProcessBatch() Added Border
clsWorkerThread.ProcessBatch() Detecting Width & Position of text. Width:539, Position: 5138
clsWorkerThread.ProcessBatch() Drawing Text
### R:\Output\HB1003-210.tif ###
Releasing Handle: 44929140

### R:\Originals\HB1003-211.tif ###
clsWorkerThread.ProcessBatch() ImageID: 46671700
clsWorkerThread.ProcessBatch() Tiff Compression: 4
clsWorkerThread.ProcessBatch() Added Border
clsWorkerThread.ProcessBatch() Detecting Width & Position of text. Width:539, Position: 5138
clsWorkerThread.ProcessBatch() Drawing Text
### R:\Output\HB1003-211.tif ###
Releasing Handle: 46671700

### R:\Originals\HB1003-212.tif ###
clsWorkerThread.ProcessBatch() ImageID: 31904084
clsWorkerThread.ProcessBatch() Tiff Compression: 4
clsWorkerThread.ProcessBatch() Added Border
clsWorkerThread.ProcessBatch() Detecting Width & Position of text. Width:539, Position: 5138
clsWorkerThread.ProcessBatch() Drawing Text
### R:\Output\HB1003-212.tif ###
Releasing Handle: 31904084

### R:\Originals\HB1003-213.tif ###
clsWorkerThread.ProcessBatch() ImageID: 89200600
clsWorkerThread.ProcessBatch() Tiff Compression: 4
clsWorkerThread.ProcessBatch() Added Border
clsWorkerThread.ProcessBatch() Detecting Width & Position of text. Width:539, Position: 5138
clsWorkerThread.ProcessBatch() Drawing Text
### R:\Output\HB1003-213.tif ###
Releasing Handle: 89200600

### R:\Originals\HB1003-214.tif ###
clsWorkerThread.ProcessBatch() ImageID: 2028841
clsWorkerThread.ProcessBatch() Tiff Compression: 4
clsWorkerThread.ProcessBatch() Added Border
clsWorkerThread.ProcessBatch() Detecting Width & Position of text. Width:539, Position: 5138
clsWorkerThread.ProcessBatch() Drawing Text
### R:\Output\HB1003-214.tif ###
Releasing Handle: 2028841

### R:\Originals\HB1003-215.tif ###
clsWorkerThread.ProcessBatch() ImageID: 82752320
clsWorkerThread.ProcessBatch() Tiff Compression: 4
clsWorkerThread.ProcessBatch() Added Border
clsWorkerThread.ProcessBatch() Detecting Width & Position of text. Width:539, Position: 5138
clsWorkerThread.ProcessBatch() Drawing Text
### R:\Output\HB1003-215.tif ###
Releasing Handle: 82752320
This outputs colour LZW files (because i havent converted to B&W).

Now, this is the strange thing. If i re-run the app, WITH the convert to B&W method, this is what happens:

Code: Select all

clsWorkerThread.ProcessBatch() GDVersion: 6.4
### R:\Originals\HB1003-210.tif ###
clsWorkerThread.ProcessBatch() ImageID: 10297793
clsWorkerThread.ProcessBatch() Tiff Compression: 4
clsWorkerThread.ProcessBatch() Added Border
clsWorkerThread.ProcessBatch() Detecting Width & Position of text. Width:539, Position: 5138
clsWorkerThread.ProcessBatch() Drawing Text
clsWorkerThread.ProcessBatch() ConvertTo1Bpp
### R:\Output\HB1003-210.tif ###
Releasing Handle: 10297793

### R:\Originals\HB1003-211.tif ###
clsWorkerThread.ProcessBatch() ImageID: 81322424
clsWorkerThread.ProcessBatch() Tiff Compression: 4
clsWorkerThread.ProcessBatch() Added Border
clsWorkerThread.ProcessBatch() Detecting Width & Position of text. Width:539, Position: 5138
clsWorkerThread.ProcessBatch() Drawing Text
clsWorkerThread.ProcessBatch() ConvertTo1Bpp
### R:\Output\HB1003-211.tif ###
Releasing Handle: 81322424

### R:\Originals\HB1003-212.tif ###
clsWorkerThread.ProcessBatch() ImageID: 54590480
clsWorkerThread.ProcessBatch() Tiff Compression: 4
clsWorkerThread.ProcessBatch() Added Border
clsWorkerThread.ProcessBatch() Detecting Width & Position of text. Width:539, Position: 5138
clsWorkerThread.ProcessBatch() Drawing Text
clsWorkerThread.ProcessBatch() ConvertTo1Bpp
### R:\Output\HB1003-212.tif ###
Releasing Handle: 54590480

### R:\Originals\HB1003-213.tif ###
clsWorkerThread.ProcessBatch() ImageID: 47181124
clsWorkerThread.ProcessBatch() Tiff Compression: 4
clsWorkerThread.ProcessBatch() Added Border
clsWorkerThread.ProcessBatch() Detecting Width & Position of text. Width:0, Position: 5408
clsWorkerThread.ProcessBatch() Drawing Text
clsWorkerThread.ProcessBatch() ConvertTo1Bpp
### R:\Output\HB1003-213.tif ###
Releasing Handle: 47181124

### R:\Originals\HB1003-214.tif ###
clsWorkerThread.ProcessBatch() ImageID: 67060184
clsWorkerThread.ProcessBatch() Tiff Compression: 4
clsWorkerThread.ProcessBatch() Added Border
clsWorkerThread.ProcessBatch() Detecting Width & Position of text. Width:0, Position: 5408
clsWorkerThread.ProcessBatch() Drawing Text
clsWorkerThread.ProcessBatch() ConvertTo1Bpp
### R:\Output\HB1003-214.tif ###
Releasing Handle: 67060184

### R:\Originals\HB1003-215.tif ###
clsWorkerThread.ProcessBatch() ImageID: 24231780
clsWorkerThread.ProcessBatch() Tiff Compression: 4
clsWorkerThread.ProcessBatch() Added Border
clsWorkerThread.ProcessBatch() Detecting Width & Position of text. Width:0, Position: 5408
clsWorkerThread.ProcessBatch() Drawing Text
clsWorkerThread.ProcessBatch() ConvertTo1Bpp
### R:\Output\HB1003-215.tif ###
Releasing Handle: 24231780
Notice how, after the 3rd image, it stops detecting the width of the text it wants to draw. Also, the first 3 images are STILL colour (as if the convertto1bpp is failing) then after the 3rd image they do start converting to b&w but the method used to detect the width of text starts returning 0.

this is very strange.

All the images are group4fax to start with.

this is my code

Code: Select all

        Debug.Print("clsWorkerThread.ProcessBatch() GDVersion: " & imaging.GetVersion())

                    'Open Image
                    Debug.Print("### " & OneBatchItem.inFile & " ###")
                    ImageID = imaging.CreateGdPictureImageFromFile(OneBatchItem.inFile)
                    Debug.Print("clsWorkerThread.ProcessBatch() ImageID: " & ImageID)

                    Debug.Print("clsWorkerThread.ProcessBatch() Tiff Compression: " & imaging.GetTiffCompression(ImageID))
                    imaging.AddBorderBottom(ImageID, 140, Color.White)
                    Debug.Print("clsWorkerThread.ProcessBatch() Added Border")
                    TextWidth = imaging.GetTextWidth(ImageID, Replace(My.Computer.FileSystem.GetName(OneBatchItem.inFile).Substring(0, Len(My.Computer.FileSystem.GetName(OneBatchItem.inFile)) - 4), "-", "/"), "Arial", 32, GdPicture.FontStyle.FontStyleRegular)
                    TextWidthPos = (imaging.GetWidth(ImageID) / 2) - (TextWidth / 2)
                    Debug.Print("clsWorkerThread.ProcessBatch() Detecting Width & Position of text. Width:" & TextWidth & ", Position: " & TextWidthPos)

                    imaging.DrawText(ImageID, Replace(My.Computer.FileSystem.GetName(OneBatchItem.inFile).Substring(0, Len(My.Computer.FileSystem.GetName(OneBatchItem.inFile)) - 4), "-", "/"), TextWidthPos, imaging.GetHeight(ImageID) - 120, 32, GdPicture.FontStyle.FontStyleRegular, Color.Black, "Arial", True)
                    Debug.Print("clsWorkerThread.ProcessBatch() Drawing Text")

                    imaging.ConvertTo1Bpp(ImageID)
                    Debug.Print("clsWorkerThread.ProcessBatch() ConvertTo1Bpp")
                    Debug.Print("### " & OneBatchItem.outFile & " ###")
                    imaging.SaveAsTIFF(ImageID, OneBatchItem.outFile, GdPicture.TiffCompression.TiffCompressionCCITT4)
                    Debug.Print("Releasing Handle: " & ImageID)
                    imaging.ReleaseGdPictureImage(ImageID)
                    Debug.Print("")
Maybe if you can't reproduce this, its something with my image files, but they open and convert in any image editing program

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

Re: Drawing Text

Post by Loïc » Wed Sep 02, 2009 11:26 am

Hi,

As I said, you need to check the returned value of the GdPicture methods. Maybe you have an outofmemory status or something like that.

In you code you need to check:

AddBorderBottom()
ConvertTo1Bpp()
DrawText()


Also, check you are getting a non empty string from

Code: Select all

Replace(My.Computer.FileSystem.GetName(OneBatchItem.inFile).Substring(0, Len(My.Computer.FileSystem.GetName(OneBatchItem.inFile)) - 4), "-", "/")
With best regards,

loïc

mattewan
Posts: 33
Joined: Fri Apr 03, 2009 5:58 pm

Re: Drawing Text

Post by mattewan » Wed Sep 09, 2009 12:24 pm

Hello Loic,

After doing what you said, i have outputted the status of the functions and as you expected, after the first few images i started getting outofmemory return codes.

What i dont understand is that im releasing the image at the end of each image file, is there something else i can do? or will i have to completly destroy the gd object each time?

Thank you.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest