Welcome Guest Search | Active Topics | Members

Assign a known colour to be transparent in a saved output Options
Taylor Nicholls
Posted: Monday, December 17, 2007 11:10:47 AM
Rank: Newbie
Groups: Member

Joined: 12/17/2007
Posts: 2
Points: -91
Hello All,

I have a quick question about the proper syntax to assign a know colour (i.e. white or 255,255,255) to be transparent when I save the processed tile. I have provided a code snippet as an example. It may be a problem that I "Transparentize" a channel then continue onto convert that same image to an indexed format.

Thanks in advance, Taylor

Code:

                            Aurigma.GraphicsMill.Bitmap oOutputMap = new Aurigma.GraphicsMill.Bitmap(256, 256, Aurigma.GraphicsMill.PixelFormat.Format24bppRgb);
                            Aurigma.GraphicsMill.Drawing.GdiGraphics oOutputMapGraphic = oOutputMap.GetGdiGraphics();

                            oOutputMapGraphic.DrawImage(bitmap, new RectangleF(0, 0, 256, 256), new RectangleF(0, 0, 256, 256), Aurigma.GraphicsMill.Transforms.CombineMode.Copy, 1, Aurigma.GraphicsMill.Transforms.InterpolationMode.Bilinear);

                            oOutputMap.Channels.Transparentize(Aurigma.GraphicsMill.Color.FromRgb(255, 255, 255), 0);

                            oOutputMap.ColorManagement.PaletteEntryCount = 8;
                            oOutputMap.ColorManagement.ConvertToIndexed(8, Aurigma.GraphicsMill.ColorPaletteType.Adaptive, null);
                            
                            oOutputMap.Save("1.png");

                            oOutputMap.Dispose();
                            oOutputMapGraphic.Dispose();
Taylor Nicholls
Posted: Monday, December 17, 2007 11:23:29 AM
Rank: Newbie
Groups: Member

Joined: 12/17/2007
Posts: 2
Points: -91
Thanks to all,

This seems to enable the "Transparentize" function to operate as expected, it was placed directly ahead of that call:

Code:

                            if (!oOutputMap.HasAlpha)
                            {
                                oOutputMap.Channels.AddAlpha(1);
                                oOutputMap.ColorManagement.BuildAdaptivePaletteWithAlpha = true;
                                oOutputMap.ColorManagement.PaletteAlphaThresholdUsed = true;
                                oOutputMap.ColorManagement.PaletteAlphaThreshold = 255;
                            }

Have a great day. Taylor
Dmitry
Posted: Monday, December 17, 2007 10:24:10 PM
Rank: Advanced Member
Groups: Administration , Member

Joined: 8/3/2003
Posts: 607
Points: 651
Hello,

Thanks for your post.

We have made a modification in the last versions of Graphics Mill for .NET: now if you try to create Aurigma.GraphicsMill.Drawing.GdiGraphics on ARGB32 bitmap exception is thrown. It was made because GDI does not work with alpha channels correctly. So I have modified your code and now it should work with the last versions of Graphics Mill for .NET.

Code:

using(Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap("c:/pattern.png"))
{
    using(Aurigma.GraphicsMill.Bitmap oOutputMap = new Aurigma.GraphicsMill.Bitmap(
        256, 256, Aurigma.GraphicsMill.PixelFormat.Format24bppRgb))
    {
        bitmap.Draw(oOutputMap, new System.Drawing.RectangleF(0, 0, 256, 256),
            new System.Drawing.RectangleF(0, 0, 256, 256),
            Aurigma.GraphicsMill.Transforms.CombineMode.Copy, 1,
            Aurigma.GraphicsMill.Transforms.InterpolationMode.Bilinear);
        oOutputMap.Channels.Transparentize(Aurigma.GraphicsMill.Color.FromRgb(255, 255, 255), 0);

        oOutputMap.ColorManagement.BuildAdaptivePaletteWithAlpha = true;
        oOutputMap.ColorManagement.PaletteAlphaThresholdUsed = true;
        oOutputMap.ColorManagement.PaletteAlphaThreshold = 255;
        oOutputMap.ColorManagement.ConvertToIndexed(8, Aurigma.GraphicsMill.ColorPaletteType.Adaptive, null);

        oOutputMap.Save("c:/1.png");
    }
}


Sincerely yours,
Dmitry Sevostyanov.
Users browsing this topic
Guest


Forum Jump
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.

Main Forum RSS : RSS

YAFVision Theme Created by Jaben Cargman (Tiny Gecko)
Yet Another Forum.net version 1.9.1.6 running under Cuyahoga.
Copyright © 2003-2006 Yet Another Forum.net. All rights reserved.