Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Wednesday, May 14, 2008 5:51:22 AM(UTC)
Michaelo

Groups: Registered
Posts: 8


I have an jpg image 400 x 400 and printing it on A4 paper i would like to add a footer note at the bottom of the page. But i can only get the text to be in the bounds of the image. I'm using version 14.5 of Lead tools for .Net

private void AddPageFooter(IRasterImage image, AnnContainer container)
{
container.Bounds = new AnnRectangle(0, 0,
printDocument.DefaultPageSettings.PrintableArea.Width,
printDocument.DefaultPageSettings.PrintableArea.Height, AnnUnit.Millimeter);
container.UnitConverter = new AnnUnitConverter(image.ImageWidth, image.ImageHeight);

container.Name = "Container";
container.Visible = true;

AnnTextObject text = new AnnTextObject();

text.Text = string.Format("Document - {0} Revision {1} Date {2}", "TestDoc");
text.Pen = new AnnPen(Color.Red,new AnnLength(4)) ;
text.Brush = null;
text.EdgeMargin = AnnLength.Empty;
text.Alignment = StringAlignment.Center;
text.LineAlignment = StringAlignment.Center;
text.TextColor = Color.Black;
text.Font = new AnnFont(InvuRenderer.Instance.FontName, new AnnLength(12), FontStyle.Bold);
text.Bounds = new AnnRectangle(1, 0, printDocument.DefaultPageSettings.PrintableArea.Width, 5, AnnUnit.Millimeter);

container.Objects.Add(text);
container.Draw(image.CreateGdiPlusGraphics().Graphics);
}

 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Wednesday, May 14, 2008 10:58:57 AM(UTC)

jigar  
Guest

Groups: Guests
Posts: 3,034

Was thanked: 2 time(s) in 2 post(s)

What you have to do is, create an empty white
image that is A4 size with 400dpi, or whatever the image's DPI is. 
Then put the original image on top of the white image.  This will give you a new image.  Then you can add the text with your code above.

If
all of your images are 400dpi.  You could easily create a white image
in Photoshop or GIMP and load that image, instead of creating one
programmatically.  Let me know if you are unsure about anything or have questions.
 
#3 Posted : Wednesday, May 14, 2008 11:01:27 PM(UTC)
Michaelo

Groups: Registered
Posts: 8


Do you have an example of creating a image via code. As the image can be any size and dpi, as they are scan in. so creating the image by code would be the best way of doing it.

Thanks
 
#4 Posted : Thursday, May 15, 2008 5:37:59 AM(UTC)
Michaelo

Groups: Registered
Posts: 8


I have been able to create the new blank image to the size i need. Just a quick question how to i go about adding the other image on top of this one.
 
#5 Posted : Thursday, May 15, 2008 6:36:18 AM(UTC)

jigar  
Guest

Groups: Guests
Posts: 3,034

Was thanked: 2 time(s) in 2 post(s)

Hello,

You would use Leadtools.ImageProcessing.CombineCommand.  For the CombineCommand your DestinationImage is your white image.  The source image is your original image.  You would use the SourceCopy flag.  There are other properties you have to set, so you will have to look at the documentation for those properties.

Also the new image you create will be all black by default.  So you will have to use the FillCommand to make it all white, or any color you like.  Do you have any questions about creating a new image?
 
#6 Posted : Thursday, May 15, 2008 7:05:47 AM(UTC)
Michaelo

Groups: Registered
Posts: 8


hi thanks for that, Iwas creating the image using the following

int bitsPerPixel = image.BitsPerPixel;

//LEADTOOLS stores the image data scanlines in 32-bit padded lines
int stride = (((width * bitsPerPixel) + 31) >> 3) & ~3;

// Allocate the data
byte[] data = new byte[stride * height];

// Fill in the data
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width * 3; x += 3)
{
data[x + 0 + y * stride] = 255;
data[x + 1 + y * stride] = 255;
data[x + 2 + y * stride] = 255;
}
}
}

// Create a new IRasterImage object with user-defined data
IRasterImage footerImage = new RasterImage(RasterMemoryFlags.User, width, height, bitsPerPixel,
RasterByteOrder.Rgb, RasterViewPerspective.TopLeft, null, data);

Is this the best way of greating an image and how to i cope with BitsPerPixel not being 24 as the above code does not work if BitsPerPixel = 1

Thanks
 
#7 Posted : Thursday, May 15, 2008 11:01:37 AM(UTC)

jigar  
Guest

Groups: Guests
Posts: 3,034

Was thanked: 2 time(s) in 2 post(s)

Do this instead:  new RasterImage(RasterMemoryFlags.User, width, height, bitsPerPixel, RasterByteOrder.Rgb, RasterViewPerspective.TopLeft, null, null)

You pass null for the userdata.  Then run the FillCommand on that image.  This way you don't have to deal with the bits per pixel.  When you pass null, the userdata is all 0's, so it's all black.
 
#8 Posted : Thursday, May 15, 2008 11:27:48 PM(UTC)
Michaelo

Groups: Registered
Posts: 8


Hi

I have try the following but i get a System.NullReferenceException, any ideas?

Thanks

IRasterImage footerImage = new RasterImage(RasterMemoryFlags.User, width, height, image.BitsPerPixel,
RasterByteOrder.Rgb, RasterViewPerspective.TopLeft, null, null);

FillCommand fillCommand = new FillCommand();
fillCommand.Color = RasterColor.FromGdiPlusColor(Color.White);
fillCommand.Run(footerImage);

System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="Leadtools.Kernel"
StackTrace:
at Leadtools.Kernel.Memory.Copy(Byte& dest, Byte& src, UInt32 count)
at Leadtools.Kernel.KernelMethods.L_PutBitmapRowSegments(BitmapHandle pBitmap, Byte* pBuffer, Int32 nRow, Int32 nCol, UInt32* pSegments, UInt32 uSegmentCount, Boolean fPreserveAlpha)
at Leadtools.Kernel.KernelMethods.L_FillBitmap(BitmapHandle pBitmap, UInt32 crFill)
at Leadtools.ImageProcessing.FillCommand.Run(IRasterImage image, Object bitmap, RasterImageChangedFlags& changedFlags)
at Leadtools.ImageProcessing.RasterCommand.Run(IRasterImage image)
at INVU.Workbench.Core.Viewer.PrintProcessor.AddPageFooter(IRasterImage& image) in C:\Series\6\Invu6\INVU6\INVU.Workbench.Core\Viewer\PrintProcessor.cs:line 233
at INVU.Workbench.Core.Viewer.PrintProcessor.printDocument_PrintPageAnn(Object sender, PrintPageEventArgs e, AnnContainer myContainer) in C:\Series\6\Invu6\INVU6\INVU.Workbench.Core\Viewer\PrintProcessor.cs:line 151
at INVU.Workbench.Core.Viewer.PrintProcessor.printDocument_PrintPage(Object sender, PrintPageEventArgs e) in C:\Series\6\Invu6\INVU6\INVU.Workbench.Core\Viewer\PrintProcessor.cs:line 138
at System.Drawing.Printing.PrintDocument.OnPrintPage(PrintPageEventArgs e)
at System.Drawing.Printing.PrintDocument._OnPrintPage(PrintPageEventArgs e)
at System.Drawing.Printing.PrintController.PrintLoop(PrintDocument document)
at System.Drawing.Printing.PrintController.Print(PrintDocument document)
at System.Drawing.Printing.PrintDocument.Print()
at System.Windows.Forms.PrintPreviewControl.ComputePreview()
at System.Windows.Forms.PrintPreviewControl.CalculatePageInfo()
 
#9 Posted : Thursday, May 15, 2008 11:42:13 PM(UTC)
Michaelo

Groups: Registered
Posts: 8


Hi

I changed RasterMemoryFlags.User to RasterMemoryFlags.Managed and its seems to work now.

Thanks for all you help
 
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2020, Yet Another Forum.NET
This page was generated in 0.247 seconds.