AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

BmpToIcon

Ein Thema von Shaman · begonnen am 17. Mai 2004 · letzter Beitrag vom 22. Apr 2006
Antwort Antwort
Benutzerbild von Shaman
Shaman

Registriert seit: 2. Nov 2003
Ort: Schweiz
407 Beiträge
 
Turbo Delphi für Win32
 
#1

BmpToIcon

  Alt 17. Mai 2004, 22:38
Hallo zusammen

Wie kann ich eine Bitmap mit mehr als 256 Farben in ein Icon konvertieren? Ich hab zwar Beispiele gefunden, doch da gibts Probleme mit 24-Bit...

Gruss
Shaman
Daniel Pauli
Looking for answers from the great beyond
  Mit Zitat antworten Zitat
Benutzerbild von nailor
nailor

Registriert seit: 12. Dez 2002
Ort: Karlsruhe
1.989 Beiträge
 
#2

Re: BmpToIcon

  Alt 17. Mai 2004, 22:47
mit deinem eigenen programm, oder mit einer anderen software klick
Michael N.
http://nailor.devzero.de/code/sharpmath/testing/ --- Tests, Feedback, Anregungen, ... aller Art sehr willkommen!
::: don't try so hard - it'll happen for a reason :::
  Mit Zitat antworten Zitat
Benutzerbild von SirThornberry
SirThornberry
(Moderator)

Registriert seit: 23. Sep 2003
Ort: Bockwen
12.235 Beiträge
 
Delphi 2006 Professional
 
#3

Re: BmpToIcon

  Alt 17. Mai 2004, 23:30
Irfan View kann das und ist freeware...
Jens
Mit Source ist es wie mit Kunst - Hauptsache der Künstler versteht's
  Mit Zitat antworten Zitat
Benutzerbild von Shaman
Shaman

Registriert seit: 2. Nov 2003
Ort: Schweiz
407 Beiträge
 
Turbo Delphi für Win32
 
#4

Re: BmpToIcon

  Alt 18. Mai 2004, 10:17
Ich meine, wie sich das in Delphi verwirklichen lässt...
Daniel Pauli
Looking for answers from the great beyond
  Mit Zitat antworten Zitat
Anubis

Registriert seit: 17. Mai 2004
Ort: Biebelried
27 Beiträge
 
#5

Re: BmpToIcon

  Alt 18. Mai 2004, 10:20
DBR Delphi Ecke - Icon erstellen
Eine Mehrheit kann auch nur eine Ansammlung von Idioten sein.
  Mit Zitat antworten Zitat
Benutzerbild von Shaman
Shaman

Registriert seit: 2. Nov 2003
Ort: Schweiz
407 Beiträge
 
Turbo Delphi für Win32
 
#6

Re: BmpToIcon

  Alt 18. Mai 2004, 21:11
Funktioniert, danke vielmals
Daniel Pauli
Looking for answers from the great beyond
  Mit Zitat antworten Zitat
Balu der Bär
(Gast)

n/a Beiträge
 
#7

Re: BmpToIcon

  Alt 22. Apr 2006, 10:35
Hi Shaman,

könntest du mir mal bitte sagen wie du das gemacht hast, der Link oben geht nämlich nicht mehr. Danke.
  Mit Zitat antworten Zitat
Benutzerbild von Shaman
Shaman

Registriert seit: 2. Nov 2003
Ort: Schweiz
407 Beiträge
 
Turbo Delphi für Win32
 
#8

Re: BmpToIcon

  Alt 22. Apr 2006, 11:02
Hey there

Hab ich noch irgendwo in meiner CodeLib gefunden, aber nicht mehr getestet. Ist auch schon länger her...

Delphi-Quellcode:
type
  TIconDirEntry = packed record
    bWidth:Byte;
    bHeight:Byte;
    bColorCount:Byte;
    bReserved:Byte;
    wPlanes:Word;
    wBitCount:Word;
    dwBytesInRes:DWord;
    dwImageOffset:DWord;
  end;

  TIcondir = packed record
    idReserved:Word;
    idType:Word;
    idCount:Word;
    IdEntries:array[1..20] of TIconDirEntry;
  end;

procedure SaveBmpAsIcon(const Bmp: TBitmap; const Icon: string; const SmallIcon: Boolean;
                        const Transparent: Boolean; const X, Y: Integer);

// Bmp : Die Bitmpap
// Icon : Dateiname, unter welchem das Icon gespeichert wird
// SmallIcon : True: 16x16 Icon, False: 32x32 Icon
// Transparent: Farbe des Pixels an (X, Y) als transparent definieren
// X, Y : Koordinaten der Transparentfarbe

var
  PBI, MPBI: PBitmapInfo;
  IHS, MIHS, ImageSize, MImageSize: DWord;
  bmBuffer, MaskBuffer: Pointer;
  TID: TIconDir;
  TBIH: TBitmapInfoHeader;
  Bmx, Bmm: TBitmap;
  TranspCol: TColor;
  I, J: Integer;
begin
  Bmx:= TBitmap.Create;
  Bmm:= TBitmap.Create;
  try
    if SmallIcon then begin
      Bmx.Width:= GetSystemMetrics(SM_CXSMICON);
      Bmx.Height:= GetSystemMetrics(SM_CYSMICON);
    end else begin
      Bmx.Width:= GetSystemMetrics(SM_CXICON);
      Bmx.Height:= GetSystemMetrics(SM_CYICON);
    end;
    bmx.pixelformat:=pf24bit;
    Bmx.Canvas.StretchDraw(Rect(0, 0, Bmx.Width, Bmx.Height), Bmp);
    TranspCol:= Bmx.Canvas.Pixels[X, Y];
    Bmm.Assign(Bmx);
    Bmm.Mask(TranspCol);
    GetDIBSizes(Bmm.Handle, MIHS, MImageSize);
    GetDIBSizes(Bmx.Handle, IHS, ImageSize);
    MaskBuffer:= AllocMem(MImageSize);
    bmBuffer:= AllocMem(ImageSize);
    MPBI:= AllocMem(MIHS);
    PBI:= AllocMem(IHS);
    try
      if Transparent then begin
        for I:=0 to Bmx.Width-1 do
          for J:=0 to Bmx.Height-1 do
            if Bmx.Canvas.Pixels[I, J] = TranspCol then
              Bmx.Canvas.Pixels[I, J]:= 0;
        with MPBI^.bmiHeader do begin
          biSize:= SizeOf(TBitmapInfoHeader);
          biWidth:= Bmm.Width;
          biHeight:= Bmm.Height;
          biPlanes:= 1;
          biBitCount:= 1;
          biCompression:= BI_RGB;
          biSizeImage:= MImageSize;
          biXPelsPerMeter:= 0;
          biYPelsPerMeter:= 0;
          biClrUsed:= 2;
          biClrImportant:= 2;
        end;
        GetDIBits(Bmm.Canvas.Handle, Bmm.Handle, 0, Bmm.height, MaskBuffer, MPBI^, DIB_RGB_COLORS);
      end;
      with PBI^.bmiHeader do begin
        biSize:= SizeOf(TBitmapInfoHeader);
        biWidth:= Bmx.Width;
        biHeight:= Bmx.Height;
        biPlanes:= 1;
        biBitCount:= 24;
        biCompression:= BI_RGB;
        biSizeImage:= ImageSize;
        biXPelsPerMeter:= 0;
        biYPelsPerMeter:= 0;
        biClrUsed:= 0;
        biClrImportant:= 0;
      end;
      GetDIBits(Bmx.Canvas.Handle, Bmx.Handle, 0, Bmx.Height, bmBuffer, PBI^, DIB_RGB_COLORS);
      with TBIH do begin
        biSize:= 40;
        biWidth:= Bmx.Width;
        biHeight:= Bmx.Height * 2;
        biPlanes:= 1;
        biBitCount:= 24;
        biCompression:= 0;
        biSizeImage:= ImageSize;
        biXPelsPerMeter:= 0;
        biYPelsPerMeter:= 0;
        biClrUsed:= 0;
        biClrImportant:= 0;
      end;
      with TID do begin
        idReserved:=0;
        idType:=1;
        idCount:=1;
        with idEntries[1] do begin
          bWidth:=bmx.width;
          bHeight:=bmx.height;
          bColorCount:=0;
          bReserved:=0;
          wPlanes:=1;
          wBitCount:=24;
          dwBytesInRes:= SizeOf(TBitmapInfoHeader) + TBIH.biSizeImage + MImageSize;
          dwImageOffset:= 6 + TID.idCount * SizeOf(TIconDirEntry);
        end;
      end;
      with TFileStream.Create(Icon, fmCreate) do try
        Write(TID, 6 + TID.idCount * SizeOf(TIconDirEntry));
        Write(TBIH, SizeOf(TBitmapInfoheader));
        Write(bmBuffer^, TBIH.biSizeImage);
        Write(maskBuffer^, MImageSize);
      finally
        Free;
      end;
    finally
      FreeMem(MaskBuffer);
      FreeMem(bmBuffer);
      FreeMem(MPBI);
      FreeMem(PBI);
    end;
  finally
    Bmx.free;
    Bmm.free;
  end;
end;
Daniel Pauli
Looking for answers from the great beyond
  Mit Zitat antworten Zitat
Balu der Bär
(Gast)

n/a Beiträge
 
#9

Re: BmpToIcon

  Alt 22. Apr 2006, 11:16
Vielen Dank das geht.
  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 10:32 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