AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Multimedia Delphi Bitblt und transparenz
Thema durchsuchen
Ansicht
Themen-Optionen

Bitblt und transparenz

Ein Thema von Delphi-Noobie · begonnen am 29. Jan 2005 · letzter Beitrag vom 29. Jan 2005
Antwort Antwort
Delphi-Noobie

Registriert seit: 28. Nov 2003
102 Beiträge
 
#1

Bitblt und transparenz

  Alt 29. Jan 2005, 17:58
hi,

Wenn ich die Funktion Bitblt an einem Image anwende, und es irgendwo hinkopiere, z.B auf die Canvasoberfläche vom Dektop, dann kommt um das Bild herum so ein schwarzer Rand, da das Image nicht Viereckig ist. Kann man den schwarzen Rand, wie mit setbkmode(hdc,transparent)bei nem Image, irgendwie transparent machen? Jedes Image mit Scanline durchzugehen, ob ein Pixel nicht schwarz ist, wollte ich mir sparen, da das zu umständlich wäre.
Wieviel Lösungen hat die Gleichung x^13=1? .... 13!
  Mit Zitat antworten Zitat
Benutzerbild von jfheins
jfheins

Registriert seit: 10. Jun 2004
Ort: Garching (TUM)
4.579 Beiträge
 
#2

Re: Bitblt und transparenz

  Alt 29. Jan 2005, 18:46
Du könntest das Image mit MSDN-Library durchsuchenStretchBlt stretchen ...
  Mit Zitat antworten Zitat
tommie-lie
(Gast)

n/a Beiträge
 
#3

Re: Bitblt und transparenz

  Alt 29. Jan 2005, 18:54
Guck dir mal [msdn]"MaskBlt"[/msdn] an, dem kannst du eine Maske übergeben.

@jfheins: das bringt nur nichts, wenn das Bild nicht rechteckig ist
  Mit Zitat antworten Zitat
Delphi-Noobie

Registriert seit: 28. Nov 2003
102 Beiträge
 
#4

Re: Bitblt und transparenz

  Alt 29. Jan 2005, 19:20
also bis zum handle des sourceimages versteh ich die Funktion aber danach nicht mehr(hbmMask,xMask,
ymask,dwRop). Könntest du mal nen Beispiel Code Posten dafür? und als Bild Beispielsweise ne Banane nehmen oder irgendwas , was nich rund oder eckig ist?
Wieviel Lösungen hat die Gleichung x^13=1? .... 13!
  Mit Zitat antworten Zitat
Delphi-Noobie

Registriert seit: 28. Nov 2003
102 Beiträge
 
#5

Re: Bitblt und transparenz

  Alt 29. Jan 2005, 20:43
ok hab ne Lösung gefunden sogar ohne Maskblt.

Code:
procedure DrawTransparentBitmap(DC: HDC; hBmp : HBITMAP ;
          xStart: integer; yStart : integer; cTransparentColor : COLORREF);
var
      bm: BITMAP;
      cColor: COLORREF;
      bmAndBack, bmAndObject, bmAndMem, bmSave: HBITMAP;
      bmBackOld, bmObjectOld, bmMemOld, bmSaveOld: HBITMAP;
      hdcMem, hdcBack, hdcObject, hdcTemp, hdcSave: HDC;
      ptSize: TPOINT;

begin
   hdcTemp := CreateCompatibleDC(dc);
   SelectObject(hdcTemp, hBmp); // Select the bitmap

   GetObject(hBmp, sizeof(BITMAP), @bm);
   ptSize.x := bm.bmWidth; // Get width of bitmap
   ptSize.y := bm.bmHeight; // Get height of bitmap
   DPtoLP(hdcTemp, ptSize, 1); // Convert from device
                                      // to logical points

   // Create some DCs to hold temporary data.
   hdcBack := CreateCompatibleDC(dc);
   hdcObject := CreateCompatibleDC(dc);
   hdcMem := CreateCompatibleDC(dc);
   hdcSave := CreateCompatibleDC(dc);

   // Create a bitmap for each DC. DCs are required for a number of
   // GDI functions.

   // Monochrome DC
   bmAndBack := CreateBitmap(ptSize.x, ptSize.y, 1, 1, nil);

   // Monochrome DC
   bmAndObject := CreateBitmap(ptSize.x, ptSize.y, 1, 1, nil);

   bmAndMem := CreateCompatibleBitmap(dc, ptSize.x, ptSize.y);
   bmSave := CreateCompatibleBitmap(dc, ptSize.x, ptSize.y);

   // Each DC must select a bitmap object to store pixel data.
   bmBackOld := SelectObject(hdcBack, bmAndBack);
   bmObjectOld := SelectObject(hdcObject, bmAndObject);
   bmMemOld := SelectObject(hdcMem, bmAndMem);
   bmSaveOld := SelectObject(hdcSave, bmSave);

   // Set proper mapping mode.
   SetMapMode(hdcTemp, GetMapMode(dc));

   // Save the bitmap sent here, because it will be overwritten.
   BitBlt(hdcSave, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY);

   // Set the background color of the source DC to the color.
   // contained in the parts of the bitmap that should be transparent
   cColor := SetBkColor(hdcTemp, cTransparentColor);

   // Create the object mask for the bitmap by performing a BitBlt
   // from the source bitmap to a monochrome bitmap.
   BitBlt(hdcObject, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0,
          SRCCOPY);

   // Set the background color of the source DC back to the original
   // color.
   SetBkColor(hdcTemp, cColor);

   // Create the inverse of the object mask.
   BitBlt(hdcBack, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0,
          NOTSRCCOPY);

   // Copy the background of the main DC to the destination.
   BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, dc, xStart, yStart,
          SRCCOPY);

   // Mask out the places where the bitmap will be placed.
   BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, SRCAND);

   // Mask out the transparent colored pixels on the bitmap.
   BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcBack, 0, 0, SRCAND);

   // XOR the bitmap with the background on the destination DC.
   BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCPAINT);

   // Copy the destination to the screen.
   BitBlt(dc, xStart, yStart, ptSize.x, ptSize.y, hdcMem, 0, 0,
          SRCCOPY);

   // Place the original bitmap back into the bitmap sent here.
   BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcSave, 0, 0, SRCCOPY);

   // Delete the memory bitmaps.
   DeleteObject(SelectObject(hdcBack, bmBackOld));
   DeleteObject(SelectObject(hdcObject, bmObjectOld));
   DeleteObject(SelectObject(hdcMem, bmMemOld));
   DeleteObject(SelectObject(hdcSave, bmSaveOld));

   // Delete the memory DCs.
   DeleteDC(hdcMem);
   DeleteDC(hdcBack);
   DeleteDC(hdcObject);
   DeleteDC(hdcSave);
   DeleteDC(hdcTemp);
end;
Gruß Delphi-Noobie
Wieviel Lösungen hat die Gleichung x^13=1? .... 13!
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 04:07 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz