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 : Saturday, January 31, 2009 9:21:07 AM(UTC)

Arzak  
Arzak

Groups: Registered
Posts: 5


Hello,
The problem is in correct conversion from png 8 to png 32. Using Ledtools.ImageProcessing.ColorResolutionCommand gives abnormal result. I use С#, .NET Framework 2.0, Leadtools Imaging Pro 16
in attach:
"PNG_adaptive_Original.png" - original image
"processed_PNG_adaptive_ColorResolutionCommand.png"-processed image
 

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 : Monday, February 2, 2009 3:02:51 AM(UTC)

Adam Boulad  
Guest

Groups: Guests
Posts: 3,022

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

Please attach the source file that you are facing a problem with and the result of using the ColorResolutionCommand.
You can attach images by putting them in a ZIP or RAR file. Also, do not use the 'Preview' feature when attaching images or files.
 
#3 Posted : Monday, February 2, 2009 4:03:05 AM(UTC)

Arzak  
Arzak

Groups: Registered
Posts: 5


my images i worked with
File Attachment(s):
PNG_adaptive.rar (183kb) downloaded 32 time(s).
 
#4 Posted : Monday, February 2, 2009 6:28:40 AM(UTC)

Adam Boulad  
Guest

Groups: Guests
Posts: 3,022

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

There are several way to do this, one way is to (after the ColorResolutionCommand):
- Create a new temporary image (same width and height of the original image).
- Fill it with white (using the FillCommand).
- Set the temporary image as the Alpha image of you image (using SetAlphaImage).
- Save the image as 32-bit.

There are other ways to do this, however, I need more information about your Load/Save requirements. Are you only interested in changing the BPP (BitsPerPixel) of the PNG file from 8 to 32?
 
#5 Posted : Monday, February 2, 2009 12:59:52 PM(UTC)

Arzak  
Arzak

Groups: Registered
Posts: 5


I forgot to say, I need to convert from original png8 with transparency to png32 with transparency. Also add a border. By now a problem is in adding a border to a created png32 image with transparency.

using System;
using System.Drawing;
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;

namespace LeadtoolsApplication
{
class Program
{
static void Main(string[] args)
{
RasterCodecs.Startup();
#region {image loading}
string fileName = @".\Images\PNG_adaptive.png";
RasterCodecs codecs = new RasterCodecs();
RasterImage image = codecs.Load(fileName);
CodecsImageInfo imageInfo = codecs.GetInformation(fileName, false, 1);
#endregion
#region {create png32 with transparency}
image.AddColorToRegion(new RasterColor(Color.White), RasterRegionCombineMode.SetNot);
RasterImage alphaImage = image.CreateMaskFromRegion();
image.SetAlphaImage(alphaImage);
#endregion
#region {add to image a border}
int borderWidth = 30;
RasterColor borderColor = new RasterColor(Color.Green);
#region {create a image base}
RasterImage imageResult = new RasterImage(RasterMemoryFlags.Conventional,
image.Width, image.Height, image.BitsPerPixel, image.Order,
image.ViewPerspective, image.GetPalette(), IntPtr.Zero, 0);
#endregion
#region {fill image base with border color}
FillCommand fillCommand = new FillCommand();
fillCommand.Color = borderColor;
fillCommand.Run(imageResult);
#endregion
#region {cut border of the image}
CropCommand cropCommand = new CropCommand();
cropCommand.Rectangle = new Rectangle(borderWidth, borderWidth,
image.Width - borderWidth * 2, image.Height - borderWidth * 2);
cropCommand.Run(image);
#endregion
#region {combine image base with cut image}
CombineFastCommand combineFastCommand = new CombineFastCommand();
combineFastCommand.DestinationRectangle = new Rectangle(
borderWidth, borderWidth, image.Width, image.Height);
combineFastCommand.SourcePoint = Point.Empty;
combineFastCommand.DestinationImage = imageResult;
combineFastCommand.Flags = CombineFastCommandFlags.SourceCopy;
combineFastCommand.Run(image);
#endregion
#endregion
#region {save the modified image}
string fileNameOut = @".\Images\processed_PNG_adaptive.png";
codecs.Save(imageResult, fileNameOut, RasterImageFormat.Png, 32);
#endregion
RasterCodecs.Shutdown();
}
}
}
File Attachment(s):
Images.rar (176kb) downloaded 20 time(s).
 
#6 Posted : Tuesday, February 3, 2009 6:55:06 AM(UTC)

Adam Boulad  
Guest

Groups: Guests
Posts: 3,022

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

Arzak,
About converting from 8-bit to 32-bit, if the original image already contains transparency information, you can load it directly as 32-bit by passing the value 32 in the BitsPerPixel parameter in the RasterCodecs.Load function.
If you then save it as 32-bit, the transparency information will be preserved.
However, if the original image does not contain an alpha channel, you can solve that without the alpha-fill code I sent you by setting  CodecsLoadOptions.InitAlpha Property to ture before loading the 8-bit as 32.

Our moderator has split the forum post to a new thread since it is not directly related to the original issue.


Regarding the border issue, I'm not sure that I understand the exact problem with the result file. Do you want to add the border to the image without clipping the image itself? If yes, do the following to add border color to it:
- Create a new image the size of your existing image plus 2 times the border size you desire. Use the RasterImage Constructor to achieve this.
- Fill the new image with white. Use the FillCommand Class.
- Combine the source image onto the white image. Use the CombineCommand Class.
If you have further questions regarding adding border to an image, please create a new forum thread and provide details regarding your question.
 
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.220 seconds.