How to define a bitmap object in delphi, associate it with a window context, and draw a bitmap? Give pzhl as an example the minimum code.

    2 answers 2

    Put the TImage component (with the name image) on the form. Then at any convenient time we do:

    // Π‘ΠΎΠ·Π΄Π°Π΅ΠΌ Π±ΠΈΡ‚ΠΌΠ°Ρ€ b := TBitMap.create; // Π—Π°Π΄Π°Π΅ΠΌ Ρ€Π°Π·ΠΌΠ΅Ρ€Ρ‹ BitMap, Ρ€Π°Π²Π½Ρ‹Π΅ Ρ€Π°Π·ΠΌΠ΅Ρ€Π°ΠΌ image b.Height:=image.Height; b.Width:=image.Width; // TODO: РисуСм Π½Π° Π±ΠΈΡ‚ΠΌΠ°ΠΏΠ΅ ΠΈΠ»ΠΈ Π·Π°Π³Ρ€ΡƒΠΆΠ°Π΅ΠΌ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΡƒ ΠΈΠ· Ρ„Π°ΠΉΠ»Π° // ... // ΠŸΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅ΠΌ содСрТимоС Π½Π° экранС image.Picture.Assign(b); // ΠžΡ‡ΠΈΡ‰Π°Π΅ΠΌ ΠΏΠ°ΠΌΡΡ‚ΡŒ b.Free; 
    • You just misunderstood the question =) - AseN

    An example of how to draw on the desktop:

     var bmp:Tbitmap; begin bmp:=Tbitmap.Create; bmp.canvas.Handle:=getdc(0); //ΠΏΠΎΠ»ΡƒΡ‡Π°Π΅ΠΌ контСкст(HDC) Ρ€Π°Π±ΠΎΡ‡Π΅Π³ΠΎ стола bmp.canvas.Rectangle(0,0,200,100); // А Π΄Π°Π»Π΅Π΅ рисуСм, ΠΊΠ°ΠΊ Π² ΠΎΠ±Ρ‹Ρ‡Π½ΠΎΠΌ TbitMap`Π΅ =)