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, January 21, 2009 2:43:05 AM(UTC)

RaYWoLF  
RaYWoLF

Groups: Registered
Posts: 22


Hello, I'm using the Raster Imaging Pro v15 version. I have to add a header to an image but I don't know how to do it (or if it is possible).

The effect I want to obtain is something like this (add a black header an write some text):

The original image:


The image with the header:


Is there any way of doing this?

Thanks in advance.
 

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, January 21, 2009 6:56:20 AM(UTC)

Adnan Ismail  
Guest

Groups: Guests
Posts: 3,022

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

One way to do that is to use the AddBorder function to add a space above the image, then draw the text in that space by obtaining a GDI HDC or Graphics object of the image and using GDI text drawing functions.

The exact details depend on the LEADTOOLS programming interface (DLL API, C++ Class Library or .NET Classes) you are using.

 
#3 Posted : Monday, January 26, 2009 5:13:03 AM(UTC)

RaYWoLF  
RaYWoLF

Groups: Registered
Posts: 22


Thanks for the answer. I'll take a look to that function.

Anyway, the programming interface I use are the .NET Classes.
 
#4 Posted : Tuesday, January 27, 2009 8:03:03 AM(UTC)

Adnan Ismail  
Guest

Groups: Guests
Posts: 3,022

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

The AddBorder function does not currently have a .NET implementation. However, what you need can be easily achieved using the following steps:
1. Create a new RasterImage object that has the same properties of the original image but with a slightly larger height. You can use the New operator to do that.
2. Fill it with a suitable background color using the FillCommand class.
3. Copy the bitmap data from the original image to the new image using the CombineFastCommand Class.
 
#5 Posted : Wednesday, January 28, 2009 6:40:25 AM(UTC)

RaYWoLF  
RaYWoLF

Groups: Registered
Posts: 22


Hello! I'm trying to do what you say, but I have a few questions:
- How can I create a new RasterImage? I don't know how fill the bold parameters (palette and userData)
- How can I use the CombineFastCommand to join both images?

-------------------------------------------------------------------------------------
RasterCodecs.Startup();
RasterCodecs codecs = new RasterCodecs();
           
RasterImage imagenOriginal = codecs.Load(@"C:\original_image.jpg");
RasterImage imagenNueva = new RasterImage(RasterMemoryFlags.None, imagenOriginal.Width, imagenOriginal.Height + 100, imagenOriginal.BitsPerPixel, RasterByteOrder.Rgb, RasterViewPerspective.TopLeft, palette, userData, 0);
           
FillCommand comando = new FillCommand(RasterColor.FromGdiPlusColor(Color.Black));
comando.Run(imagenNueva);

CombineFastCommand comando2 = new CombineFastCommand();
           
codecs.Save(imagenNueva, @"C:\test.jpg", RasterImageFormat.Jpeg, imagenOriginal.BitsPerPixel, 1, 1, 1, CodecsSavePageMode.Overwrite);
RasterCodecs.Shutdown();
-------------------------------------------------------------------------------------
 
#6 Posted : Thursday, January 29, 2009 5:41:58 AM(UTC)

Adnan Ismail  
Guest

Groups: Guests
Posts: 3,022

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

I am attaching a sample project that you can use to combine your image with a created image. Please let me know if you face a problem.
File Attachment(s):
CombineDemo.zip (16kb) downloaded 21 time(s).
 
#7 Posted : Thursday, January 29, 2009 9:52:01 PM(UTC)

RaYWoLF  
RaYWoLF

Groups: Registered
Posts: 22


Thanks for your help, it works perfectly!!

Now I'm facing the second part of the problem (write the text). I can do it with this code:

Bitmap customImage = new Bitmap(@"C:\test.jpg");               
Graphics g = Graphics.FromImage(customImage);
g.DrawString("Some text", new Font("Arial", 20, GraphicsUnit.Pixel), new SolidBrush(Color.Red), 60, 10);
customImage.Save(@"C:\test2.jpg");

Is there any way to do using Leadtools? If I do this I save the image 2 times and lose quality on the second save (from 452kb to 111kb in my example).

Thanks in advance
 
#8 Posted : Thursday, January 29, 2009 10:09:37 PM(UTC)

RaYWoLF  
RaYWoLF

Groups: Registered
Posts: 22


Forget it, I did using this example:

http://support.leadtools.com/SupportPortal/CS/forums/7408/ShowPost.aspx
 
#9 Posted : Monday, March 16, 2009 1:13:41 AM(UTC)

RaYWoLF  
RaYWoLF

Groups: Registered
Posts: 22


As I said before, I solved the problem of adding a header to an image but now I'm facing another problem. In this case the problem is related to the size of the new image (with the header). The new one is almost 3 times the original size.

This an image example (original and with header), 87kb vs 231kb:
http://img21.imageshack.us/my.php?image=imagenpy.jpg
http://img21.imageshack.us/my.php?image=imagewithheader.jpg

This is the code I use:
---------------------------------------------------------------------------
RasterCodecs.Startup();
RasterCodecs codecs = new RasterCodecs();
RasterImage imagenOriginal = codecs.Load("C:\\image.jpg");
RasterImage imagenNueva = new RasterImage(RasterMemoryFlags.Conventional, imagenOriginal.Width, imagenOriginal.Height + 50, imagenOriginal.BitsPerPixel, RasterByteOrder.Bgr, imagenOriginal.ViewPerspective, null, IntPtr.Zero, 0);
//Important Note: If image is 8-bits or less, you must copy palette from imagenOriginal to imagenNueva
FillCommand cmdFill = new FillCommand(RasterColor.FromGdiPlusColor(Color.Black));
cmdFill.Run(imagenNueva);
CombineFastCommand cmdCombine = new CombineFastCommand(imagenNueva, new Rectangle(0, 50, imagenOriginal.Width, imagenOriginal.Height), new Point(0, 0), CombineFastCommandFlags.OperationAdd);
cmdCombine.Run(imagenOriginal);
               
RasterImageGdiPlusGraphicsContainer container = imagenNueva.CreateGdiPlusGraphics();
container.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
Font fuente = new Font("Arial", 14, GraphicsUnit.Pixel);
StringBuilder sbLineaCabecera = new StringBuilder();
sbLineaCabecera.AppendLine(TimeStamp.ToString("dd/MM/yyyy") + "           some text");
sbLineaCabecera.Append(TimeStamp.ToString("HH:mm:ss.fff"));

int x = 10;
int y = 5;
container.Graphics.DrawString(sbLineaCabecera.ToString(), fuente, new SolidBrush(Color.White), x, y);

codecs.Save(imagenNueva, "C:\\image_with_header.jpg", RasterImageFormat.Jpeg, imagenOriginal.BitsPerPixel, 1, 1, 1, CodecsSavePageMode.Overwrite);
RasterCodecs.Shutdown();
---------------------------------------------------------------------------
 
#10 Posted : Tuesday, March 17, 2009 5:51:48 AM(UTC)

Adnan Ismail  
Guest

Groups: Guests
Posts: 3,022

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

You are using RasterImageFormat.Jpeg, which is JPEG 4:4:4. Is the original file also 4:4:4 or is it 4:2:2 or 4:1:1?
Also, what is the Quality Factor you use when you save? You can set it using the RasterCodecs.Options.Jpeg.Save.QualityFactor property.
 
#11 Posted : Friday, March 20, 2009 12:26:51 AM(UTC)

RaYWoLF  
RaYWoLF

Groups: Registered
Posts: 22


I don't know what do you mean with JPEG 4:4:4. An example of an original file (and the result) is on the previous post.

Anyway, I'll try the Quality Factor property that you write about.
 
#12 Posted : Sunday, March 22, 2009 1:23:51 AM(UTC)

Adnan Ismail  
Guest

Groups: Guests
Posts: 3,022

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

There are 3 different types of Jpeg file when saving it:
- RasterImageFormat.Jpeg411
- RasterImageFormat.Jpeg422
- RasterImageFormat.Jpeg
In the save method you are using the RasterImageFormat.Jpeg which means (Jpeg 4:4:4). You should save your image using the RasterImageFormat.Jpeg411.
 
#13 Posted : Tuesday, March 24, 2009 2:01:12 AM(UTC)

RaYWoLF  
RaYWoLF

Groups: Registered
Posts: 22


If I use the RasterImageFormat.Jpeg411 as you say (without change quality factor), the image result is still too heavy:
- original, 87kb
- with header using RasterImageFormat.Jpeg, 231kb
- with header using RasterImageFormat.Jpeg411, 216kb
- with header using RasterImageFormat.Jpeg and QualityFactor 40 (I can see a bit loss of quality), 90kb

codecs.Save(imagenNueva, "C:\\image_with_header_411.jpg", RasterImageFormat.Jpeg411, imagenOriginal.BitsPerPixel, 1, 1, 1, CodecsSavePageMode.Overwrite);

Anyway, I think can combine both methods (jpg411 and quality factor) to get the ideal values. If you have any more suggestion, please make me know.

Thanks for all.
 
#14 Posted : Tuesday, March 24, 2009 8:39:21 AM(UTC)

Adnan Ismail  
Guest

Groups: Guests
Posts: 3,022

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

Please keep in mind that since JPEG compression is lossy, every time you modify the image and re-save it, you will get additional quality loss. This means you should try to keep the number of re-save operation to a minimum.

If you need to save more than once before storing the final result image, you should keep the intermediate steps in a high-quality or even a lossless format if possible.

 
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-2024, Yet Another Forum.NET
This page was generated in 0.237 seconds.