procedure DrawPixelAlpha(Canvas: TImagingCanvas; X, Y: Integer; Alpha: Byte);
var
ColRec: TColor32Rec;
begin
ColRec.Color := Canvas.Pixels32[X, Y];
ColRec.A := Alpha;
Canvas.Pixels32[X, Y] := ColRec.Color;
end;
procedure DrawAlphaEllipse(Canvas: TImagingCanvas; const Rect: TRect; Alpha: Byte; Fill: Boolean);
var
RadX, RadY, DeltaX, DeltaY, R, RX, RY: LongInt;
X1, X2, Y1, Y2, Bpp, OldY, I: LongInt;
Color: PColor32Rec;
begin
X1 := Rect.Left;
X2 := Rect.Right;
Y1 := Rect.Top;
Y2 := Rect.Bottom;
SwapMin(X1, X2);
SwapMin(Y1, Y2);
RadX := (X2 - X1) div 2;
RadY := (Y2 - Y1) div 2;
Y1 := Y1 + RadY;
Y2 := Y1;
OldY := Y1;
DeltaX := (RadX * RadX);
DeltaY := (RadY * RadY);
R := RadX * RadY * RadY;
RX := R;
RY := 0;
if Fill then
begin
for I := X1 to X2 do
DrawPixelAlpha(Canvas, I, Y1, Alpha);
end;
DrawPixelAlpha(Canvas, X1, Y1, Alpha);
DrawPixelAlpha(Canvas, X2, Y1, Alpha);
while RadX > 0 do
begin
if R > 0 then
begin
Inc(Y1);
Dec(Y2);
Inc(RY, DeltaX);
Dec(R, RY);
end;
if R <= 0 then
begin
Dec(RadX);
Inc(X1);
Dec(X2);
Dec(RX, DeltaY);
Inc(R, RX);
end;
if (OldY <> Y1) and Fill then
begin
for I := X1 to X2 do
DrawPixelAlpha(Canvas, I, Y1, Alpha);
for I := X1 to X2 do
DrawPixelAlpha(Canvas, I, Y2, Alpha);
end;
OldY := Y1;
DrawPixelAlpha(Canvas, X1, Y1, Alpha);
DrawPixelAlpha(Canvas, X2, Y1, Alpha);
DrawPixelAlpha(Canvas, X1, Y2, Alpha);
DrawPixelAlpha(Canvas, X2, Y2, Alpha);
end;
end;
// draw ellipse
DrawAlphaEllipse(Canvas, Rect(16, 64, 240, 192), 55, True);
// draw square
for I := 128 to 255 do
for J := 128 to 255 do
DrawPixelAlpha(Canvas, I, J, 200);
Quote from: Galfar on 31 August 2007, 20:16:24
1) Do you need it working for all data formats or just for one like A8R8G8B8? And do you need it filled or just outlined?
var
OrigImage, SmallImage: TSingleImage;
Texture: IDirect3DTexture9;
D3DDevice: IDirect3DDevice9;
.... init D3D ....
.... create orig image, say 1024x1024 pixels ....
SmallImage := TSingleImage.CreateFromParams(256, 256, OrigImage.Format); // create small image
OrigImage.CopyTo(512, 512, SmallImage.Width, SmallImage.Height, SmallImage, 0, 0); // copy from orig to small
CreateD3DTextureFromImage(SmallImage.ImageDataPointer^, D3DDevice, Texture); // create texture from small image
var
Image: TSingleImage;
Texture: IDirect3DTexture9;
Rect: TD3DLockedRect;
PixelPtr, DestPtr: Pointer;
X, Y, I, LineBytes, TextureSize: Integer; // say TextureSize is 128, [X, Y] is source position in image
.... create your texture and image ....
Texture.LockRect(0, Rect, nil, 0); // lock texture
LineBytes := Image.FormatInfo.GetPixelsSize(Image.FormatInfo.Format, TextureSize, 1);
for I := 0 to TextureSize - 1 do
begin
Move(Image.PixelPointers[X, Y + I]^, // move pixels from image to texture
PByteArray(Rect.pBits)[I * Rect.Pitch], LineBytes);
end;
Texture.UnlockRect(0); // unlock texture
Page created in 0.038 seconds with 19 queries.