minol / gr32ex

Automatically exported from code.google.com/p/gr32ex
5 stars 2 forks source link

Problems with alpha Channel #2

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Add TGRButton add png Glyph on it

What is the expected output? What do you see instead?

seems that original Alpha Channel of the png is not used. and if I set the
Drawmode to dmTransparent and outercolor to clWhite32 there will be weird
pixelation at the edge (of the visible area)...

What version of the product are you using? On what operating system?

New release, D2007, Vista64

Please provide any additional information below.

sorry if this just misunderstanding on my side... 

Original issue reported on code.google.com by tommi.prami@gmail.com on 29 Oct 2008 at 1:25

Attachments:

GoogleCodeExporter commented 8 years ago
Hello again...

It works perfectly if I set the Glyph at run time with this code:

I've used provided Update tool, before I tested component (which is pretty 
obvious,
because it would not compile without it.)

- If I assigne Glyph at runtime it works perfectly!!! I can live with that, 
because i
can stream images from resources...

// ------------------------------------------------------
procedure LoadPNGintoBitmap32(ADstBitmap: TBitmap32; ASrcStream: TStream; out
vAlphaChannelUsed: Boolean); overload;
var
  LPNGObject: TPNGObject;
  LTransparentColor: TColor32;
  LPixelPtr: PColor32;
  LAlphaPtr: PByte;
  X, Y: Integer;
begin
  LPNGObject := nil;
  try
    LPNGObject := TPngObject.Create;
    LPNGObject.LoadFromStream(ASrcStream);

    ADstBitmap.Assign(LPNGObject);
    ADstBitmap.ResetAlpha;

    case LPNGObject.TransparencyMode of
      ptmPartial:
        begin
          if (LPNGObject.Header.ColorType = COLOR_GRAYSCALEALPHA) or
             (LPNGObject.Header.ColorType = COLOR_RGBALPHA) then
          begin
            LPixelPtr := PColor32(@ADstBitmap.Bits[0]);
            for Y := 0 to ADstBitmap.Height - 1 do
            begin
              LAlphaPtr := PByte(LPNGObject.AlphaScanline[Y]);
              for X := 0 to ADstBitmap.Width - 1 do
              begin
                LPixelPtr^ := (LPixelPtr^ and $00FFFFFF) or (TColor32(LAlphaPtr^) shl
24);
                Inc(LPixelPtr);
                Inc(LAlphaPtr);
              end;
            end;

            vAlphaChannelUsed := True;
          end;
        end;
      ptmBit:
        begin
          LTransparentColor := Color32(LPNGObject.TransparentColor);
          LPixelPtr := PColor32(@ADstBitmap.Bits[0]);
          for X := 0 to (ADstBitmap.Height - 1) * (ADstBitmap.Width - 1) do
          begin
            if LPixelPtr^ = LTransparentColor then
              LPixelPtr^ := LPixelPtr^ and $00FFFFFF;
            Inc(LPixelPtr);
          end;

          vAlphaChannelUsed := True;
        end;
      ptmNone:
        vAlphaChannelUsed := False;
    end;
  finally
    if Assigned(LPNGObject) then
      LPNGObject.Free;
  end;
end;

// ------------------------------------------------------

Original comment by tommi.prami@gmail.com on 30 Oct 2008 at 7:42

GoogleCodeExporter commented 8 years ago
look at the \Examples\test_control
it works well.

  Btn1 := TGRButton.Create(Self);
  with Btn1 do
  try
    Glyph.LoadFromFile('Background\123.png');
    //LoadPicture(Glyph, 'Background\123.png');

Original comment by riceball...@gmail.com on 13 Nov 2008 at 1:10

GoogleCodeExporter commented 8 years ago
Hello,

I am not loading from file, but trying to add glyph at design time. 

I stream file into it Runtime (from resources mxStorage component), with code 
above,
it works. But adding glyph at designtime on the IDE I have problem with.

Sorry about not making that clear in previous post...

-TP-

Original comment by tommi.prami@gmail.com on 13 Nov 2008 at 1:19