T O P I C R E V I E W |
Marius |
Posted - Jul 19 2011 : 05:11:57 Hello Fabio/Nigel,
Nice to see you back in action Fabio, finally my favorite graphic toolbox is actively developed again!
1) We have just upgraded to imageen 4.0 and i'm get the following exception on the line "APng.TransparentColor := clWhite". Exception: "Setting bit transparency color is not allowed for png images containing alpha value for each pixel (COLOR_RGBALPHA and COLOR_GRAYSCALEALPHA)". As soon as i put the 3.12 back this is working properly. I got this working again by modifying the bitmap and setting the transparant color (which wasn't alway's the case). Did something change in this corner or do i do something wrong?
2) The same code still goes wrong on making a couple of png's transparant. This ONLY happends with Rgb(255, 255, 000), i attached one of the images (other images with the same color are ok so i do expect its a imageen#4 issue). Is there something i do wrong in this code?
If you need more info or need the example project please ask (i dont want to post it here)
APng := TPngImage.Create; AStream := TMemoryStream.Create; ImageEn2 := TImageEn.Create(nil); try ImageEn2.IO.LoadFromFileBMP(AFilename); ImageEn2.IO.Params.BMP_HandleTransparency := true; ImageEn2.IO.Params.PNG_Background := TColor2TRGB(clWhite);
//Replace yellow with the newcolor ANewColor := Rgb(255, 255, 000); for x := 0 to ImageEn2.IEBitmap.Width do begin for y := 0 to ImageEn2.IEBitmap.Height do begin if ImageEn2.IEBitmap.Canvas.Pixels[x, y] = clYellow then ImageEn2.IEBitmap.Canvas.Pixels[x, y] := ANewColor; end; end; ImageEn2.Proc.Resample(20, 20, rfNearest); //Resize ImageEn2.IO.SaveToStreamPng(AStream);
AStream.Position := 0; APng.LoadFromStream(AStream); APng.TransparentColor := clWhite; ADatamodule.ImageList.AddPng(APng); finally ImageEn2.Free; AStream.Free; APng.Free; end;
Greetings, Marius
|
3 L A T E S T R E P L I E S (Newest First) |
fab |
Posted - Jul 19 2011 : 14:05:27 The "ImageEn" way is:
var
oldColor, newColor, transpColor:TRGB;
...other variables
begin
ImageEnView1.IO.LoadFromFile('20117195814_Analysis.bmp');
// replace all pixels with "oldColor" with "newColor"
oldColor := CreateRGB(255, 255, 0); // yellow
newColor := CreateRGB(0, 0, 255); // blue
ImageEnView1.Proc.CastColorRange(oldColor, oldColor, newColor);
// resample to 20x20
ImageEnView1.Proc.Resample(20, 20, rfNearest);
// make all pixels with "transpColor" transparent (alpha=0)
transpColor := CreateRGB(255, 255, 255); // white
ImageEnView1.Proc.SetTransparentColors(transpColor, transpColor, 0);
// now you can save the PNG and reload it
ImageEnView1.IO.SaveToStreamPNG(AStream);
AStream.Position := 0;
APng.LoadFromStream(AStream);
ADatamodule.ImageList.AddPng(APng);
end;
Note that CreateRGB is defined in "imageenproc" unit.
Hope this helps. |
Marius |
Posted - Jul 19 2011 : 08:50:16 hello Fabrizio,
The code is part of a tool we use to generates resources files, in the end the imagelist contains about 300 images with different variations of colors. Your assumptions are almost correct, just a few minor corrections:
1) load an image (that hasn't alpha channel, true?) yes. -> replace a specific marked color with another. 2) resample to a specified size (ie 20x20) yes. 3) make some colors transparent and save as PNG (yes, but only white should be transparent in this case)
My major problem is that in step 3 the image with the specific color Rgb(255, 255, 000) is not transparent while other are.
Greetings, Marius |
fab |
Posted - Jul 19 2011 : 07:47:21 Hi Marius, what is the goal of your code? I suppose: 1) load an image (that hasn't alpha channel, true?) 2) resample to a specified size (ie 20x20) 3) make some colors transparent and save as PNG
If the supposition is right I will send you the right code to do the task.
Please note that TPngImage is not an ImageEn class. However the exception is right, because you are trying to make a color transparent, while the PNG created by ImageEn already has an alpha channel (which use, your color or the embedded alpha channel?). |
|
|