Forum > Beginners

need advice about the following code (transparency linked to (0,0) pixel)


Nono Reading Activity:
i add Pictures to PDF and some of them don't have transparency.
to emulate Transparency, i created the following function and procedure.
it work, but i don't know if it can be upgrade (or correct, if some part need it)
thanks in advance

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function TestCouleur(img: TBGRABitmap; x: integer;y: integer; VerifTrans: Boolean):boolean;var  TestRed:   Integer;  TestGreen: Integer;  TestBlue:  Integer;  MaxDiff:   Integer = 2000;begin  if VerifTrans then    begin      TestRed   :=;      TestGreen := BGRAPixelTransparent.Green;      TestBlue  := BGRAPixelTransparent.Blue;    end  else    begin      TestRed   := ZeroRed;      TestGreen := ZeroGreen;      TestBlue  := ZeroBlue;    end;   if (img.Colors[x, y].Red   = TestRed)   and // test equal     (img.Colors[x, y].Green = TestGreen) and     (img.Colors[x, y].Blue  = TestBlue)  then    Result := true  else if (VerifTrans = false) and            // test close if not test transparent          (abs(img.Colors[x, y].Red   - TestRed)   < MaxDiff) and          (abs(img.Colors[x, y].Green - TestGreen) < MaxDiff) and          (abs(img.Colors[x, y].Blue  - TestBlue)  < MaxDiff) then    Result := true  else    Result := false;end; procedure RemplacerPixelParTransparent(const FileName: string);var  Img:   TBGRABitmap;  x,y:   Integer;  Modif: boolean;begin  Img := TBGRABitmap.Create(FileName);  try    if Img.GetPixel(0, 0) <> BGRAPixelTransparent then      begin        ZeroRed    := img.Colors[0, 0].Red;        ZeroGreen  := img.Colors[0, 0].Green;        ZeroBlue   := img.Colors[0, 0].Blue;         For x :=0 to img.Width - 1 do          for y := 0 to img.Height - 1 do            begin              Modif := true;              if not TestCouleur(Img, x, y, false) then     // test pixel itself                Modif := false              else if ((x = 0) or (Y = 0)) then             // no other test for 1st line and column              else if TestCouleur(Img, x-1, y, true) then   // previous x is transparent              else if TestCouleur(Img, x, y-1, true) then   // previous y is transparent              else                Modif := false;                             // the pixel isn't close to a transparent               if Modif then                Img.ReplaceColor(Img.GetPixel(x, y), BGRAPixelTransparent);            end;      end;    Img.SaveToFile(ImageTmp);  finally    Img.Free;  end;end;     

as far as I know, overlay images for buttons etc use the lower left of the image for the transparent color.



[0] Message Index

Go to full version