LEADTOOLS Support
Imaging
Imaging SDK Questions
Programmatically Creating Image -- Set Background Color
This topic and its replies were posted before the current version of LEADTOOLS was released and may no longer be applicable.
#1
Posted
:
Wednesday, October 21, 2009 7:14:36 AM(UTC)
Groups: Registered
Posts: 13
Hi,
I am trying to create an image programmatically using Leadtools RasterImage object, and load that into an RasterImageViewer as well as save to disk. However, the image I created always have a black background, even though I filled the entire region with White color, and I also set the RasterImageViewer BackColor to white (although I doubt this has anything to do with this).
I am using Leadtools 16.5, and I am writing in C# and .NET. Following is a code snippet of what I'm doing. What do I need to do to make my image background white?
Thank you,
Ann
using (RasterCodecs rc = new RasterCodecs())
{
RasterImage image = new RasterImage(RasterMemoryFlags.Conventional, 1200, 1600, 8, RasterByteOrder.Bgr, RasterViewPerspective.BottomLeft, null, IntPtr.Zero, 0);
RasterImageGdiPlusGraphicsContainer container = image.CreateGdiPlusGraphics();
Graphics g = container.Graphics;
image.Transparent = true;
image.TransparentColor = RasterColor.FromGdiPlusColor(Color.White);
//RasterRegionXForm xform = new RasterRegionXForm();
//image.FillRegion(g, xform, RasterColor.FromGdiPlusColor(Color.White));
using (Pen p = new Pen(Color.Aqua))
{
g.DrawRectangle(p, new Rectangle(0, 0, 100, 100));
}
this.rasterImageViewer1.Image = image;
this.rasterImageViewer1.BackColor = Color.White;
rc.Save(image, @"c:\TestDev\output.jpg", RasterImageFormat.Jpeg, 8);
}
#2
Posted
:
Thursday, October 22, 2009 3:13:20 AM(UTC)
Groups: Guests
Posts: 3,022
Was thanked: 2 time(s) in 2 post(s)
I'm not exactly sure what is the desired result, but to create an a RasterImage and fill it with white, you can use the following code:
RasterImage image = new RasterImage(RasterMemoryFlags.Conventional, 1200, 1600, 8, RasterByteOrder.Bgr, RasterViewPerspective.BottomLeft, null, IntPtr.Zero, 0);
Leadtools.ImageProcessing.FillCommand command = new Leadtools.ImageProcessing.FillCommand();
command.Color = new RasterColor(255, 255, 255);
command.Run(image);
rc.Save(image, @"c:\output.jpg", RasterImageFormat.Jpeg, 8);
If you need different results, please provide me with more details.
#3
Posted
:
Thursday, October 22, 2009 5:44:30 AM(UTC)
Groups: Registered
Posts: 13
Thank you very much. That is exactly what I want -- I want to have an image that has white background, and I'm going to be drawing on the image. I don't know why I haven't thought about the FillCommand -- maybe I just didn't even find it.
Thank you.
Ann
#4
Posted
:
Thursday, October 22, 2009 5:56:27 AM(UTC)
Groups: Registered
Posts: 13
Hi,
Follow up question -- can I create an image with "transparent" background, and just draw on it? Basically, I need to generate a print image. All I really care is the drawing (black lines). So the background can be white or transparent (I think). Would transparent background make the image size smaller in memory?
Thank you,
Ann
#5
Posted
:
Thursday, October 22, 2009 11:48:24 AM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 764
JPEG files don't support transparent colors. You would need to use a format like GIF or PNG. You need to set the RasterImage.Transparent property to true and then set the TransparentColor property to the color you want to be the transparent background color.
This won't make your image smaller because all of the same image data is there, you're just telling how the viewer how to interpret it.
LEADTOOLS Support
Imaging
Imaging SDK Questions
Programmatically Creating Image -- Set Background Color
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.