### Handle Missing Dependencies in Free Pascal Source: https://github.com/bgrabitmap/bgrabitmap/blob/master/libwebp/readme.md Use a try-except block to gracefully handle potential errors when loading WebP images, such as missing VC++ Redistributable files. The example includes architecture-specific download links. ```pascal uses BGRABitmap; try bmp := TBGRABitmap.Create('image.webp'); try // do something with the image except // handle errors after the image is loaded end; Free; except on E: Exception do ShowMessage('Failed to load image. This library requires the Microsoft Visual C++ Redistributable.' + LineEnding + 'You can download it here:' + LineEnding + {$IFDEF CPU64}'https://aka.ms/vs/17/release/vc_redist.x64.exe' {$ELSE} 'https://aka.ms/vs/17/release/vc_redist.x86.exe'{$ENDIF}); end; ``` -------------------------------- ### Draw Arcs and Bezier Curves Source: https://context7.com/bgrabitmap/bgrabitmap/llms.txt Utilize these methods for drawing arcs, pie slices, and Bezier curves. Specify start and end angles for arcs, and control points for Bezier curves. ```Pascal uses BGRABitmap, BGRABitmapTypes; var bmp: TBGRABitmap; begin bmp := TBGRABitmap.Create(400, 400, BGRAWhite); // Draw arc (portion of ellipse) bmp.ArcAntialias(100, 100, 50, 50, 0, Pi, BGRABlack, 2); // Draw arc with fill (pie slice) bmp.ArcAntialias(250, 100, 50, 50, Pi/4, Pi*5/4, BGRABlack, 2, BGRA(255,200,200), [aoFillPath, aoClosePath]); // Draw chord bmp.ArcAntialias(100, 250, 50, 50, 0, Pi*3/2, BGRABlack, 2, BGRA(200,200,255), [aoFillPath]); // Bezier curve (quadratic) bmp.DrawPolyLineAntialias( bmp.ComputeBezierSpline([ PointF(200, 250), // Start point PointF(250, 200), // Control point PointF(300, 250) // End point ]), BGRABlack, 2); // Bezier curve (cubic) bmp.DrawPolyLineAntialias( bmp.ComputeBezierCurve([ PointF(50, 350), // Start point PointF(100, 300), // Control point 1 PointF(150, 400), // Control point 2 PointF(200, 350) // End point ]), BGRA(0,128,0), 3); bmp.SaveToFile('curves.png'); bmp.Free; end; ``` -------------------------------- ### Create and Load Bitmaps in Pascal Source: https://context7.com/bgrabitmap/bgrabitmap/llms.txt Demonstrates creating empty bitmaps, loading from files or streams, saving, duplicating, and extracting parts of a bitmap. Ensure to free the bitmap when done. ```pascal uses BGRABitmap, BGRABitmapTypes; var bmp: TBGRABitmap; begin // Create an empty bitmap with dimensions bmp := TBGRABitmap.Create(800, 600); // Create with a background color bmp := TBGRABitmap.Create(800, 600, BGRAWhite); // Load from file (supports PNG, JPEG, BMP, GIF, WebP, etc.) bmp := TBGRABitmap.Create('image.png'); // Create from stream bmp := TBGRABitmap.Create(AStream); // Save to file bmp.SaveToFile('output.png'); // Duplicate a bitmap var copy: TBGRABitmap := bmp.Duplicate; // Get a rectangular portion var part: TBGRABitmap := bmp.GetPart(Rect(10, 10, 100, 100)); bmp.Free; end; ``` -------------------------------- ### Create Canvas2D Gradients and Shadows in Pascal Source: https://context7.com/bgrabitmap/bgrabitmap/llms.txt Demonstrates how to initialize a BGRABitmap canvas and apply linear gradients, radial gradients, and drop shadows to shapes. ```pascal uses BGRABitmap, BGRABitmapTypes, BGRACanvas2D; var bmp: TBGRABitmap; ctx: TBGRACanvas2D; gradient: IBGRACanvasGradient2D; begin bmp := TBGRABitmap.Create(400, 400, StrToBGRA('#E0E0E0')); ctx := bmp.Canvas2D; // Create linear gradient gradient := ctx.createLinearGradient(50, 50, 200, 150); gradient.addColorStop(0, 'white'); gradient.addColorStop(0.5, '#4080FF'); gradient.addColorStop(1, 'navy'); // Draw with gradient fill ctx.fillStyle(gradient); ctx.beginPath; ctx.roundRect(50, 50, 150, 100, 15); ctx.fill; // Create radial gradient gradient := ctx.createRadialGradient(300, 100, 10, 300, 100, 60); gradient.addColorStop(0, 'yellow'); gradient.addColorStop(1, 'red'); ctx.fillStyle(gradient); ctx.beginPath; ctx.arc(300, 100, 60, 0, 2*Pi); ctx.fill; // Shadow effect ctx.shadowColor := BGRA(0, 0, 0, 128); ctx.shadowBlur := 10; ctx.shadowOffsetX := 5; ctx.shadowOffsetY := 5; ctx.fillStyle('green'); ctx.beginPath; ctx.roundRect(100, 200, 200, 150, 20); ctx.fill; bmp.SaveToFile('gradients_shadows.png'); bmp.Free; end; ``` -------------------------------- ### Create Linear and Radial Gradients in Pascal Source: https://context7.com/bgrabitmap/bgrabitmap/llms.txt Demonstrates using GradientFill for basic shapes and TBGRAGradientScanner for advanced control with gamma correction. ```pascal uses BGRABitmap, BGRABitmapTypes, BGRAGradientScanner; var bmp: TBGRABitmap; gradient: TBGRAGradientScanner; begin bmp := TBGRABitmap.Create(400, 400); // Simple two-color linear gradient bmp.GradientFill(0, 0, 400, 200, BGRABlack, BGRAWhite, gtLinear, PointF(0,0), PointF(400,0), dmSet); // Radial gradient bmp.GradientFill(0, 200, 200, 400, BGRA(255,0,0), BGRA(255,255,0), gtRadial, PointF(100,300), PointF(100,400), dmSet); // Diamond gradient bmp.GradientFill(200, 200, 400, 400, BGRA(0,0,255), BGRA(0,255,255), gtDiamond, PointF(300,300), PointF(300,400), dmSet); // Using gradient scanner for more control gradient := TBGRAGradientScanner.Create( BGRA(255,0,0), // Start color BGRA(0,0,255), // End color gtLinear, // Gradient type PointF(0,0), // Origin PointF(200,200) // End point ); gradient.GammaCorrection := True; bmp.FillRect(0, 0, 200, 200, gradient, dmDrawWithTransparency); gradient.Free; bmp.SaveToFile('gradients.png'); bmp.Free; end; ``` -------------------------------- ### Render 3D Scenes with BGRAScene3D Source: https://context7.com/bgrabitmap/bgrabitmap/llms.txt Demonstrates setting up a 3D scene with camera positioning, ambient and directional lighting, and the creation of primitive objects like spheres and custom cubes. ```pascal uses BGRABitmap, BGRABitmapTypes, BGRAScene3D; var bmp: TBGRABitmap; scene: TBGRAScene3D; obj: IBGRAObject3D; begin bmp := TBGRABitmap.Create(400, 400, BGRA(30, 30, 50)); // Create scene scene := TBGRAScene3D.Create(bmp); scene.AutoZoom := True; scene.AutoViewCenter := True; // Set camera position scene.Camera.ViewPoint := Point3D(0, -5, 2); scene.Camera.LookAt(Point3D(0, 0, 0), Point3D(0, 0, 1)); // Add ambient light scene.AmbiantLightness := 0.3; // Add directional light scene.AddDirectionalLight(Point3D(1, -1, 1), 0.7); // Create a sphere obj := scene.CreateSphere(1.0, BGRA(255, 100, 100), 16, 12); obj.MainPart.Translate(0, 0, 0); // Create another object var cube := scene.CreateObject(BGRA(100, 100, 255)); with cube.MainPart do begin // Define cube vertices var v1 := Add(Point3D(-0.5, -0.5, -0.5)); var v2 := Add(Point3D(0.5, -0.5, -0.5)); var v3 := Add(Point3D(0.5, 0.5, -0.5)); var v4 := Add(Point3D(-0.5, 0.5, -0.5)); var v5 := Add(Point3D(-0.5, -0.5, 0.5)); var v6 := Add(Point3D(0.5, -0.5, 0.5)); var v7 := Add(Point3D(0.5, 0.5, 0.5)); var v8 := Add(Point3D(-0.5, 0.5, 0.5)); // Add faces AddFace([v1, v2, v3, v4]); // Bottom AddFace([v5, v6, v7, v8]); // Top AddFace([v1, v5, v8, v4]); // Left AddFace([v2, v6, v7, v3]); // Right AddFace([v1, v5, v6, v2]); // Front AddFace([v4, v8, v7, v3]); // Back Translate(-2, 0, 0); end; // Render scene scene.Render; bmp.SaveToFile('scene3d.png'); scene.Free; bmp.Free; end; ``` -------------------------------- ### Create and Manipulate Layers Source: https://context7.com/bgrabitmap/bgrabitmap/llms.txt Demonstrates creating a multi-layer image. Layers can be added, named, have their opacity and blend modes set, and be reordered. The final image can be flattened or saved in a layered format. ```Pascal uses BGRABitmap, BGRABitmapTypes, BGRALayers; var layers: TBGRALayeredBitmap; layer1, layer2: TBGRABitmap; begin // Create layered bitmap layers := TBGRALayeredBitmap.Create(400, 400); // Create first layer (background) layer1 := TBGRABitmap.Create(400, 400, BGRA(200, 220, 255)); layers.AddOwnedLayer(layer1); layers.LayerName[0] := 'Background'; // Create second layer with content layer2 := TBGRABitmap.Create(400, 400, BGRAPixelTransparent); layer2.FillEllipseAntialias(200, 200, 100, 100, BGRA(255, 100, 100)); layers.AddOwnedLayer(layer2); layers.LayerName[1] := 'Red Circle'; layers.LayerOpacity[1] := 180; layers.BlendOperation[1] := boMultiply; // Add another layer var idx := layers.AddLayer('Blue Rectangle'); var layer3 := layers.LayerBitmap[idx]; layer3.FillRectAntialias(RectF(150, 150, 350, 250), BGRA(100, 100, 255)); layers.LayerOpacity[idx] := 200; // Move layer layers.MoveLayerDown(idx); // Flatten and save var flat: TBGRABitmap := layers.ComputeFlatImage as TBGRABitmap; flat.SaveToFile('layered_flat.png'); flat.Free; // Save as layered format layers.SaveToFile('image.lzp'); // LazPaint format layers.Free; end; ``` -------------------------------- ### Resize and Transform Images in Pascal Source: https://context7.com/bgrabitmap/bgrabitmap/llms.txt Demonstrates how to perform image resizing using different interpolation filters and geometric transformations such as rotation and flipping. ```pascal uses BGRABitmap, BGRABitmapTypes; var bmp, resized, rotated: TBGRABitmap; begin bmp := TBGRABitmap.Create('photo.jpg'); // Resize with simple stretch (fast but low quality) resized := bmp.Resample(200, 150, rmSimpleStretch) as TBGRABitmap; resized.SaveToFile('resize_simple.jpg'); resized.Free; // Resize with fine resampling (high quality) resized := bmp.Resample(200, 150, rmFineResample) as TBGRABitmap; resized.SaveToFile('resize_fine.jpg'); resized.Free; // Set resample filter before resampling bmp.ResampleFilter := rfLanczos3; // High quality resized := bmp.Resample(400, 300) as TBGRABitmap; resized.SaveToFile('resize_lanczos.jpg'); resized.Free; // Rotate image rotated := bmp.FilterRotate(PointF(bmp.Width/2, bmp.Height/2), Pi/6) as TBGRABitmap; rotated.SaveToFile('rotated.png'); rotated.Free; // Rotate 90 degrees clockwise rotated := bmp.RotateCW; rotated.SaveToFile('rotate_cw.jpg'); rotated.Free; // Rotate 90 degrees counter-clockwise rotated := bmp.RotateCCW; rotated.SaveToFile('rotate_ccw.jpg'); rotated.Free; // Flip upside down rotated := bmp.RotateUD; rotated.SaveToFile('flip_vertical.jpg'); rotated.Free; // Horizontal flip (mirror) bmp.HorizontalFlip; bmp.SaveToFile('flip_horizontal.jpg'); bmp.Free; end; ``` -------------------------------- ### Apply Canvas2D Transformations in Pascal Source: https://context7.com/bgrabitmap/bgrabitmap/llms.txt Demonstrates saving/restoring context state and applying translation, rotation, and scaling. ```pascal uses BGRABitmap, BGRABitmapTypes, BGRACanvas2D; var bmp: TBGRABitmap; ctx: TBGRACanvas2D; begin bmp := TBGRABitmap.Create(400, 400, BGRAWhite); ctx := bmp.Canvas2D; // Save state before transformation ctx.save; // Translate origin ctx.translate(200, 200); // Rotate 45 degrees (in radians) ctx.rotate(Pi/4); // Scale ctx.scale(1.5, 1.5); // Draw rectangle at transformed coordinates ctx.fillStyle('red'); ctx.fillRect(-50, -25, 100, 50); // Restore original state ctx.restore; // Multiple rotated rectangles for var i := 0 to 11 do begin ctx.save; ctx.translate(200, 200); ctx.rotate(i * Pi / 6); ctx.translate(80, 0); ctx.fillStyle(BGRA(i*20, 100, 255-i*20)); ctx.fillRect(-15, -10, 30, 20); ctx.restore; end; bmp.SaveToFile('transforms.png'); bmp.Free; end; ``` -------------------------------- ### Color Types and Conversions in Pascal Source: https://context7.com/bgrabitmap/bgrabitmap/llms.txt Illustrates creating BGRA pixels from components, TColor, CSS strings, and predefined constants. Also shows conversions to expanded and HSL formats, and merging/interpolating colors. ```pascal uses BGRABitmap, BGRABitmapTypes; var bgra: TBGRAPixel; expanded: TExpandedPixel; hsla: THSLAPixel; begin // Create BGRA pixel from components bgra := BGRA(255, 128, 64, 200); // Red=255, Green=128, Blue=64, Alpha=200 // Create from TColor bgra := ColorToBGRA(clBlue); bgra := ColorToBGRA(clRed, 128); // With alpha // Create from CSS color string bgra := StrToBGRA('#FF5500'); bgra := StrToBGRA('rgba(255, 85, 0, 0.5)'); bgra := StrToBGRA('red'); // Predefined colors bgra := BGRAWhite; bgra := BGRABlack; bgra := BGRAPixelTransparent; // Convert to expanded pixel (gamma-corrected, 16-bit per channel) expanded := GammaExpansion(bgra); // Convert to HSL color space hsla := BGRAToHSLA(bgra); hsla.hue := (hsla.hue + 32768) mod 65536; // Shift hue by 180 degrees bgra := HSLAToBGRA(hsla); // Merge colors with alpha blending var result: TBGRAPixel := MergeBGRA(BGRA(255,0,0,128), BGRA(0,0,255,128)); // Linear interpolation between colors result := MergeBGRA(BGRAWhite, BGRABlack, 128); // 50% mix end; ``` -------------------------------- ### Create Multi-Stop Gradients in Pascal Source: https://context7.com/bgrabitmap/bgrabitmap/llms.txt Uses nGradientAlphaFill and DoubleGradientAlphaFill to create complex color transitions. ```pascal uses BGRABitmap, BGRABitmapTypes, BGRAGradients; var bmp: TBGRABitmap; begin bmp := TBGRABitmap.Create(400, 200); // nGradient with multiple stops nGradientAlphaFill(bmp, Rect(0, 0, 400, 100), gdHorizontal, [ nGradientInfo(BGRA(255,0,0), BGRA(255,128,0), gdHorizontal, 0.25), nGradientInfo(BGRA(255,128,0), BGRA(255,255,0), gdHorizontal, 0.5), nGradientInfo(BGRA(255,255,0), BGRA(0,255,0), gdHorizontal, 0.75), nGradientInfo(BGRA(0,255,0), BGRA(0,0,255), gdHorizontal, 1.0) ]); // Double gradient (split gradient) DoubleGradientAlphaFill(bmp, Rect(0, 100, 400, 200), BGRA(255,255,255), BGRA(128,128,255), // First gradient colors BGRA(128,128,255), BGRA(0,0,128), // Second gradient colors gdVertical, gdVertical, gdHorizontal, 0.5); bmp.SaveToFile('multi_gradients.png'); bmp.Free; end; ``` -------------------------------- ### Apply Blur Filters in Pascal Source: https://context7.com/bgrabitmap/bgrabitmap/llms.txt Shows how to apply radial, box, and motion blurs to an image, including partial area blurring. ```pascal uses BGRABitmap, BGRABitmapTypes, BGRAFilters; var bmp, blurred: TBGRABitmap; begin bmp := TBGRABitmap.Create('photo.jpg'); // Gaussian-like radial blur blurred := bmp.FilterBlurRadial(10, rbNormal) as TBGRABitmap; blurred.SaveToFile('blur_normal.png'); blurred.Free; // Fast box blur blurred := bmp.FilterBlurRadial(10, rbBox) as TBGRABitmap; blurred.SaveToFile('blur_box.png'); blurred.Free; // Motion blur blurred := bmp.FilterBlurMotion(20, 45, True) as TBGRABitmap; // 45 degree angle blurred.SaveToFile('blur_motion.png'); blurred.Free; // Blur only a portion blurred := bmp.FilterBlurRadial(Rect(50, 50, 200, 200), 8, rbNormal) as TBGRABitmap; blurred.SaveToFile('blur_partial.png'); blurred.Free; bmp.Free; end; ``` -------------------------------- ### Create and Manipulate Animated GIFs Source: https://context7.com/bgrabitmap/bgrabitmap/llms.txt Shows how to generate an animated GIF by adding frames, saving to file or stream, and loading existing files to modify frame properties. ```pascal uses BGRABitmap, BGRABitmapTypes, BGRAAnimatedGif; var anim: TBGRAAnimatedGif; frame: TBGRABitmap; i: integer; begin // Create animated GIF anim := TBGRAAnimatedGif.Create; anim.SetSize(200, 200); anim.BackgroundColor := clWhite; anim.LoopCount := 0; // Infinite loop // Add frames for i := 0 to 35 do begin frame := TBGRABitmap.Create(200, 200, BGRAWhite); // Draw rotating circle var angle := i * 10 * Pi / 180; var cx := 100 + Round(60 * Cos(angle)); var cy := 100 + Round(60 * Sin(angle)); frame.FillEllipseAntialias(cx, cy, 20, 20, BGRA(255, 0, 0)); anim.AddFullFrame(frame, 50); // 50ms per frame = 20fps frame.Free; end; // Save as GIF anim.SaveToFile('animation.gif'); // Save as animated PNG anim.SaveToStream(AStream, ifPng); anim.Free; // Load existing animated image anim := TBGRAAnimatedGif.Create('existing.gif'); // Access frame properties WriteLn('Frame count: ', anim.Count); WriteLn('Total duration: ', anim.TotalAnimationTimeMs, 'ms'); // Get specific frame frame := anim.FrameImage[0]; // Modify frame delay anim.FrameDelayMs[0] := 100; anim.Free; end; ``` -------------------------------- ### Apply Emboss and Distortion Filters in Pascal Source: https://context7.com/bgrabitmap/bgrabitmap/llms.txt Demonstrates geometric transformations and surface effects including emboss, sphere, twirl, and cylinder distortions. ```pascal uses BGRABitmap, BGRABitmapTypes, BGRAFilters; var bmp, filtered: TBGRABitmap; begin bmp := TBGRABitmap.Create('photo.jpg'); // Emboss effect (angle in radians) filtered := bmp.FilterEmboss(Pi/4, 64) as TBGRABitmap; // 45 degrees filtered.SaveToFile('emboss.png'); filtered.Free; // Emboss with highlight filtered := bmp.FilterEmbossHighlight(True, BGRABlack) as TBGRABitmap; filtered.SaveToFile('emboss_highlight.png'); filtered.Free; // Sphere distortion filtered := bmp.FilterSphere as TBGRABitmap; filtered.SaveToFile('sphere.png'); filtered.Free; // Twirl distortion filtered := bmp.FilterTwirl(Point(bmp.Width div 2, bmp.Height div 2), bmp.Width / 2, 1.0, 3.0) as TBGRABitmap; filtered.SaveToFile('twirl.png'); filtered.Free; // Cylinder distortion filtered := bmp.FilterCylinder as TBGRABitmap; filtered.SaveToFile('cylinder.png'); filtered.Free; bmp.Free; end; ``` -------------------------------- ### Apply Color and Enhancement Filters in Pascal Source: https://context7.com/bgrabitmap/bgrabitmap/llms.txt Covers common image processing tasks like grayscale conversion, sharpening, normalization, contour detection, noise reduction, and pixelation. ```pascal uses BGRABitmap, BGRABitmapTypes, BGRAFilters; var bmp, filtered: TBGRABitmap; begin bmp := TBGRABitmap.Create('photo.jpg'); // Grayscale conversion filtered := bmp.FilterGrayscale as TBGRABitmap; filtered.SaveToFile('grayscale.png'); filtered.Free; // Sharpen (amount 256 = normal, higher = more) filtered := bmp.FilterSharpen(300) as TBGRABitmap; filtered.SaveToFile('sharpen.png'); filtered.Free; // Normalize (expand contrast) filtered := bmp.FilterNormalize(True) as TBGRABitmap; // True = each channel separately filtered.SaveToFile('normalize.png'); filtered.Free; // Contour detection filtered := bmp.FilterContour as TBGRABitmap; filtered.SaveToFile('contour.png'); filtered.Free; // Median filter (noise reduction) filtered := bmp.FilterMedian(moMediumSmooth) as TBGRABitmap; filtered.SaveToFile('median.png'); filtered.Free; // Pixelate effect filtered := FilterPixelate(bmp, 8, True) as TBGRABitmap; filtered.SaveToFile('pixelate.png'); filtered.Free; bmp.Free; end; ``` -------------------------------- ### Apply Phong Shading to 3D Shapes Source: https://context7.com/bgrabitmap/bgrabitmap/llms.txt Illustrates the use of TPhongShading to render geometric shapes like spheres, cones, and cylinders with configurable lighting parameters. ```pascal uses BGRABitmap, BGRABitmapTypes, BGRAGradients; var bmp: TBGRABitmap; phong: TPhongShading; begin bmp := TBGRABitmap.Create(400, 400, BGRAWhite); // Create Phong shader phong := TPhongShading.Create; phong.LightPosition := Point(200, 100); phong.LightPositionZ := 100; phong.AmbientFactor := 0.3; phong.DiffusionFactor := 0.7; phong.SpecularFactor := 0.5; phong.SpecularIndex := 20; phong.LightSourceIntensity := 200; phong.LightSourceDistanceTerm := 150; // Draw sphere phong.DrawSphere(bmp, Rect(50, 50, 180, 180), 50, BGRA(255, 0, 0)); // Draw cone phong.DrawCone(bmp, Rect(220, 50, 350, 180), 50, BGRA(0, 255, 0)); // Draw cylinder phong.DrawHorizontalCylinder(bmp, Rect(50, 220, 180, 350), 50, BGRA(0, 0, 255)); // Draw rectangle with border phong.DrawRectangle(bmp, Rect(220, 220, 350, 350), 15, 30, BGRA(255, 200, 0), True, []); phong.Free; bmp.SaveToFile('phong.png'); bmp.Free; end; ``` -------------------------------- ### Draw Lines and Shapes with Antialiasing Source: https://context7.com/bgrabitmap/bgrabitmap/llms.txt Use these methods to draw lines, rectangles, ellipses, and polygons with antialiasing support. Specify colors and line thicknesses as needed. ```Pascal uses BGRABitmap, BGRABitmapTypes; var bmp: TBGRABitmap; begin bmp := TBGRABitmap.Create(400, 400, BGRAWhite); // Draw horizontal/vertical lines bmp.DrawHorizLine(10, 50, 200, BGRABlack); bmp.DrawVertLine(100, 10, 100, BGRABlack); // Draw line with antialiasing bmp.DrawLineAntialias(10, 10, 200, 150, BGRABlack, 2); // Draw polyline bmp.DrawPolyLineAntialias([PointF(10,200), PointF(100,250), PointF(200,200)], BGRA(0,0,255), 3); // Rectangle (outline) bmp.RectangleAntialias(50, 50, 150, 100, BGRABlack, 2); // Rectangle (filled with border) bmp.RectangleAntialias(200, 50, 300, 100, BGRABlack, 2, BGRA(200,200,255)); // Filled rectangle bmp.FillRect(50, 150, 150, 200, BGRA(255,200,200), dmDrawWithTransparency); // Round rectangle bmp.RoundRectAntialias(200, 150, 350, 220, 15, 15, BGRABlack, 2, BGRA(200,255,200)); // Ellipse bmp.EllipseAntialias(100, 300, 60, 40, BGRABlack, 2); // Filled ellipse bmp.FillEllipseAntialias(250, 300, 60, 40, BGRA(255,128,0)); // Circle (special case of ellipse) bmp.EllipseAntialias(100, 350, 30, 30, BGRA(0,128,0), 3, BGRA(200,255,200)); // Polygon bmp.DrawPolygonAntialias([PointF(300,250), PointF(350,300), PointF(320,350), PointF(280,350), PointF(250,300)], BGRABlack, 2, BGRA(255,255,200)); bmp.SaveToFile('shapes.png'); bmp.Free; end; ``` -------------------------------- ### Pixel Access and Manipulation in Pascal Source: https://context7.com/bgrabitmap/bgrabitmap/llms.txt Shows how to access and modify individual pixels using scanlines, SetPixel, DrawPixel, GetPixel, XorPixel, and ErasePixel. Remember to call InvalidateBitmap after direct pixel modifications. ```pascal uses BGRABitmap, BGRABitmapTypes; var bmp: TBGRABitmap; p: PBGRAPixel; x, y: integer; begin bmp := TBGRABitmap.Create(200, 200, BGRABlack); // Direct pixel access via scanline for y := 0 to bmp.Height - 1 do begin p := bmp.ScanLine[y]; for x := 0 to bmp.Width - 1 do begin p^.red := x; p^.green := y; p^.blue := 128; p^.alpha := 255; Inc(p); end; end; bmp.InvalidateBitmap; // Notify that pixels changed // SetPixel with color (opaque) bmp.SetPixel(50, 50, clRed); // DrawPixel with alpha blending bmp.DrawPixel(60, 60, BGRA(255, 0, 0, 128)); // Get pixel color var color: TBGRAPixel := bmp.GetPixel(50, 50); // Get interpolated pixel at floating point coordinates var interpolated: TBGRAPixel := bmp.GetPixel(50.5, 50.5, rfLinear); // XOR pixel operation bmp.XorPixel(70, 70, BGRAWhite); // Erase pixel (reduce alpha) bmp.ErasePixel(80, 80, 128); bmp.Free; end; ``` -------------------------------- ### Load and Render SVG Graphics Source: https://context7.com/bgrabitmap/bgrabitmap/llms.txt Loads an SVG file and renders it onto a TBGRABitmap. Supports rendering at original size, stretching to fit a target size, and aligning the rendered SVG within the target area. ```Pascal uses BGRABitmap, BGRABitmapTypes, BGRASVG, BGRACanvas2D; var svg: TBGRASVG; bmp: TBGRABitmap; begin // Load SVG from file svg := TBGRASVG.Create; svg.LoadFromFile('image.svg'); // Get SVG dimensions var width := svg.WidthAsPixel; var height := svg.HeightAsPixel; // Render at original size bmp := TBGRABitmap.Create(Round(width), Round(height), BGRAWhite); svg.Draw(bmp.Canvas2D, 0, 0); bmp.SaveToFile('svg_original.png'); bmp.Free; // Render stretched to specific size bmp := TBGRABitmap.Create(800, 600, BGRAWhite); svg.StretchDraw(bmp.Canvas2D, 0, 0, 800, 600); bmp.SaveToFile('svg_stretched.png'); bmp.Free; // Render with alignment bmp := TBGRABitmap.Create(800, 600, BGRAWhite); svg.StretchDraw(bmp.Canvas2D, taCenter, tlCenter, 0, 0, 800, 600); bmp.SaveToFile('svg_centered.png'); bmp.Free; svg.Free; end; ``` -------------------------------- ### Draw Basic Shapes with Canvas2D in Pascal Source: https://context7.com/bgrabitmap/bgrabitmap/llms.txt Utilizes TBGRACanvas2D to draw rectangles, circles, paths, and text using an HTML5-like API. ```pascal uses BGRABitmap, BGRABitmapTypes, BGRACanvas2D; var bmp: TBGRABitmap; ctx: TBGRACanvas2D; begin bmp := TBGRABitmap.Create(400, 400, BGRAWhite); ctx := bmp.Canvas2D; // Set fill and stroke styles ctx.fillStyle(BGRA(255, 200, 200)); ctx.strokeStyle(BGRABlack); ctx.lineWidth := 2; // Draw rectangle ctx.beginPath; ctx.rect(50, 50, 100, 80); ctx.fill; ctx.stroke; // Draw circle ctx.fillStyle('blue'); ctx.beginPath; ctx.arc(250, 100, 50, 0, 2*Pi); ctx.fill; // Draw path ctx.strokeStyle('red'); ctx.lineWidth := 3; ctx.beginPath; ctx.moveTo(50, 200); ctx.lineTo(150, 250); ctx.lineTo(100, 350); ctx.closePath; ctx.stroke; // Text drawing ctx.fillStyle(BGRABlack); ctx.fontEmHeight := 24; ctx.fontName := 'Arial'; ctx.fillText('Hello Canvas2D!', 200, 300); bmp.SaveToFile('canvas2d.png'); bmp.Free; end; ``` -------------------------------- ### Draw Text with Various Styles Source: https://context7.com/bgrabitmap/bgrabitmap/llms.txt Renders text with different fonts, sizes, styles, and alignments. Supports drawing text with textures and measuring text dimensions. Text can also be wrapped within a rectangle. ```Pascal uses BGRABitmap, BGRABitmapTypes; var bmp: TBGRABitmap; begin bmp := TBGRABitmap.Create(400, 300, BGRAWhite); // Set font properties bmp.FontName := 'Arial'; bmp.FontHeight := 24; bmp.FontStyle := [fsBold]; bmp.FontQuality := fqFineAntialiasing; // Draw text at position bmp.TextOut(50, 50, 'Hello World!', BGRABlack); // Draw with alignment bmp.TextOut(200, 100, 'Centered', BGRABlack, taCenter); bmp.TextOut(350, 150, 'Right Aligned', BGRABlack, taRightJustify); // Draw with texture var grad: TBGRABitmap := TBGRABitmap.Create(100, 30); grad.GradientFill(0, 0, 100, 30, BGRA(255,0,0), BGRA(0,0,255), gtLinear, PointF(0,0), PointF(100,0), dmSet); bmp.FontHeight := 36; bmp.TextOut(50, 200, 'Gradient Text', grad); grad.Free; // Get text dimensions var size: TSize := bmp.TextSize('Measure me'); // Text in rectangle with wrapping bmp.FontHeight := 14; bmp.TextRect(Rect(250, 180, 380, 280), 'This is a longer text that will wrap within the given rectangle.', taLeftJustify, tlTop); bmp.SaveToFile('text.png'); bmp.Free; end; ``` -------------------------------- ### Fill Operations for Regions Source: https://context7.com/bgrabitmap/bgrabitmap/llms.txt Perform various fill operations including flood fill, progressive flood fill, color replacement, and alpha channel manipulation. These methods are useful for filling enclosed areas or modifying bitmap colors. ```Pascal uses BGRABitmap, BGRABitmapTypes; var bmp: TBGRABitmap; begin bmp := TBGRABitmap.Create(400, 400, BGRAWhite); // Draw a shape to fill bmp.EllipseAntialias(200, 200, 150, 100, BGRABlack, 2); // Flood fill (bucket fill) bmp.FloodFill(200, 200, BGRA(255, 200, 200), fmSet); // Progressive flood fill (fades based on color difference) bmp.RectangleAntialias(50, 50, 150, 150, BGRA(128,128,128), 3); bmp.FloodFill(100, 100, BGRA(100, 150, 255), fmProgressive); // Replace color bmp.ReplaceColor(BGRAWhite, BGRA(240, 240, 255)); // Fill entire bitmap bmp.Fill(BGRA(255, 255, 200, 128), dmDrawWithTransparency); // Alpha fill (modify only alpha channel) bmp.AlphaFill(200); // Set all pixels to alpha 200 bmp.SaveToFile('fills.png'); bmp.Free; end; ``` -------------------------------- ### Draw Rotated Text Source: https://context7.com/bgrabitmap/bgrabitmap/llms.txt Renders text at specified angles around a central point. Angles are in tenths of degrees, counter-clockwise. Useful for creating radial or rotated text effects. ```Pascal uses BGRABitmap, BGRABitmapTypes; var bmp: TBGRABitmap; begin bmp := TBGRABitmap.Create(400, 400, BGRAWhite); bmp.FontName := 'Arial'; bmp.FontHeight := 20; bmp.FontQuality := fqFineAntialiasing; // Rotated text (angle in tenths of degrees, counter-clockwise) bmp.TextOutAngle(200, 200, 450, 'Rotated 45 degrees', BGRABlack, taCenter); bmp.TextOutAngle(200, 200, 900, 'Rotated 90 degrees', BGRA(255,0,0), taCenter); bmp.TextOutAngle(200, 200, 1800, 'Upside down', BGRA(0,128,0), taCenter); // Multiple angles radiating from center for var i := 0 to 11 do begin bmp.TextOutAngle(200, 200, i * 300, IntToStr(i), BGRA(0, 0, 128), taLeftJustify); end; bmp.SaveToFile('rotated_text.png'); bmp.Free; end; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.