Note that there are some explanatory texts on larger screens.

plurals
  1. POWant to place several images with transparent colour on the same background
    text
    copied!<p>I am desparately searching for place several graphics having a transparent background on the same background with GDI+. I did not have any programming experience with Windows or graphic programming (like games) before, so it is more difficult to find a solution. GDI+ has a transparent colour. GDI+ only uses the transparency information to bitmap this colour properly on another image. Once bitmaped, however, the first image is no more transparent. If you put the same image several times on the same background, you will see that only the first placement was transparent.</p> <p>My problem is placing several transparent objects on a background at once. You can see the code below that works for one ship (nNrOfShips = 1;). If you write a larger value for this variable, no ship will be placed.</p> <p>How should I modify the code? I also tried to use Ship arrays, but no ship appears on the screen. You may create your own example by using a background with (slightly) changing colour and just place an image transparently. I hope that that example would help me.</p> <p>Here the code example...</p> <pre><code>HDC hdcScreen = GetLockedScreen(); m_hdcShip = CreateCompatibleDC(hdcScreen); ReleaseLockedScreen(); // Draw the ship image on restored background Graphics grBkg(m_hdcNewBackground); grBkg.SetSmoothingMode(SmoothingModeHighQuality); // Restore new background BitBlt(m_hdcNewBackground, 0, 0, GetWtsMetrics(wtsm_ScreenSizeX), GetWtsMetrics(wtsm_ScreenSizeY), m_hdcSavedBackground, 0, 0, SRCCOPY); // 20100125 SAE BYTE nNrOfShips = 1; // DATA-&gt;GetNrOfShips(); for (BYTE nShipId = 0; nShipId &lt; nNrOfShips; nShipId++) { Ship ship = DATA-&gt;GetShipList()[nShipId]; ShipModel shipModel = DATA-&gt;FindShipModel(ship.nShipModelId); // 20100202 SAE WORD nCurResId = DATA-&gt;FindCurShipResourceId(ship); // 20100131 SAE WORD nIndex = nCurResId - shipModel.nFirstResId; // 20100131 SAE assert(nIndex &gt;= 0); ShipResource shipRes = (*shipModel.pvectResource)[nIndex]; // 20100202 SAE // 20100126 SAE // Always take the first (upper left) coordinates of the ship rectangle: QuadrantVector &amp;wpQuadrants = *DATA-&gt;GetWallpapers()[DATA-&gt;SelectWallpaper()].pvectQuadrant; do { // 20100115 SAE: Determine first the coordinates of the ship ship.vectRectangle = DATA-&gt;RandomRectangleCoordinates( shipModel.nHeight, shipModel.nWidth); } while (!DATA-&gt;AreCoordinatesValid(ship.vectRectangle, wpQuadrants) &amp;&amp; !DATA-&gt;AreShipsTooClose(ship, DATA-&gt;GetShipList(), DATA-&gt;GetDistance())); grBkg.TranslateTransform(ship.vectRectangle[0].fX, ship.vectRectangle[0].fY); grBkg.RotateTransform(0); // 20100201 SAE grBkg.DrawImage(shipRes.pimgPicture, -shipModel.nWidth/2, -shipModel.nHeight/2); // Determine bounding rectangle of ship after drawing on transformed page // 20100125 SAE Rect rcSrc(-shipModel.nWidth/2, -shipModel.nHeight/2, shipModel.nWidth, shipModel.nHeight); TransformRect(&amp;grBkg, &amp;m_rcCurShip, &amp;rcSrc, CoordinateSpacePage, CoordinateSpaceWorld); } // for DeleteDC(m_hdcShip); m_hdcShip = 0; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload