begin process at 2010 02 10 12:15:36
  Trouver un code source :
 
dans
 
Accueil > Forum > 

Delphi

 > 

Divers

 > 

Débutant(e)

 > 

Txt2BMP ?


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

Txt2BMP ?

Echange clos Echange clos, plus de réponse possible sur cet échange

samedi 5 juillet 2008 à 12:21:45 | Txt2BMP ?

MiniProgramer

Hi

j ai une Function de google mais il ya des problemes !?

//-- TBitmap to String -----------------------
function BmpToTxt(const ABitmap: TBitmap): string;
  var X, Y: integer;

  function ColorToHex(AColor: TColor): string;
    begin
        Result := IntToHex(GetRValue(AColor), 2 ) +
                  IntToHex(GetGValue(AColor), 2 ) +
                  IntToHex(GetBValue(AColor), 2 );
    end;

begin
    Result := '';
    for Y := 0 to ABitmap.Height do
      begin
        if Y <> 0 then
          Result := Result + EL;
        for X := 0 to ABitmap.Width do
          Result := Result + ColorToHex(ABitmap.Canvas.Pixels[X, Y]);
      end;
end;

//-- String to TBitmap -----------------------
functionTxtToBmp(const Text: TStrings): TBitmap;
  var X, Y, cy, cx: integer;
      sClr: string;

  function HexToInt(HexStr: string): integer;
  begin
      if HexStr = '' then
        HexStr := 'FFFFFF';
      Result := StrToInt('0x' + HexStr);
  end;

  function StrToColor(AText: string): TColor;
  begin
      Result := RGB(HexToInt(Copy(AText, 1, 2)),
                    HexToInt(Copy(AText, 3, 2)),
                    HexToInt(Copy(AText, 5, 2)));
  end;

begin
    X := Length(Text[0]) div 6 - 1;
    Y := Text.Count - 1;
    Result := TBitmap.Create;
    Result.Width := X;
    Result.Height := Y;
    cy := Y;
    cx := X;
    for Y := 0 to cy do
      begin
        for X := 0 to cx do
          begin
            sClr := Copy(Text[Y], (X * 6) + 1, 6);
            Result.Canvas.Pixels[X, Y] := StrToColor(sClr);
          end;
      end;
end;


And you can use like this:
    Memo1.Text := BmpToTxt(Image1.Picture.Bitmap);
    Memo1.Lines.SaveToFile('C..Some.txt');
or
    Image1.Picture.Bitmap := TxtToBmp(Memo1.Lines);

samedi 5 juillet 2008 à 13:11:15 | Re : Txt2BMP ?

Oniria

Bonjour,

c'est quoi le probléme ? Message d'erreur ?

Oniria
samedi 5 juillet 2008 à 14:11:26 | Re : Txt2BMP ?

MiniProgramer

1. //-- TBitmap to String -----------------------
Result := Result + EL; // undeclared EL

2. //-- String to Bitmap -----------------------
si je donne un Text in Memo1 et faire Click:
the value in memo1 is no valid Integer !

mais tu peut tester ;)


samedi 5 juillet 2008 à 14:46:47 | Re : Txt2BMP ?

f0xi

Membre Club Administrateur CodeS-SourceS
type
  DByte = array[0..1] of byte;

procedure BinToHex(const Buffer; const Len: integer; var Str: string);
var pB : ^byte;
    pR : ^DByte;
    N : integer;
const
  BTC : array[$0..$F] of byte = ($30,$31,$32,$33,$34,$35,$36,$37,
                                 $38,$39,$41,$42,$43,$44,$45,$46);
begin
  SetLength(Str, Len shl 1);
  pB := @Buffer;
  pR := @Str[1];
  for N := 0 to Len-1 do
  begin
    pR^[0] := BTC[pB^ shr 4];
    pR^[1] := BTC[pB^ and $0F];
    inc(pR);
    inc(pB);
  end;
end;

procedure HexToBin(const Str: string; const LenStr: integer; var Buffer);
var pB   : ^byte;
    pS   : ^DByte;
    LZ,N : integer;
    L,H  : byte;
begin
  LZ := LenStr shr 1;

  pS := @Str[1];
  pB := @Buffer;
  for N := 0 to LZ-2 do
  begin
    case pS^[0] of
      $30..$39 : H := (pS^[0] - $30) shl 4;
      $41..$46 : H := (pS^[0] - $37) shl 4;
      else
        break;
    end;
    case pS^[1] of
      $30..$39 : L := pS^[1] - $30;
      $41..$46 : L := pS^[1] - $37;
      else
        break;
    end;
    pB^ := byte(H or L);
    inc(pS);
    inc(pB);
  end;
end;

function BitmapToStr(const Bmp: TBitmap): string;
var pX : ^byte;
    TBmp: TBitmap;
begin
  TBmp := TBitmap.Create;
  try
    TBmp.Assign(Bmp);
    TBmp.PixelFormat := pf24bit;
    pX := TBmp.ScanLine[TBmp.Height-1];
    BinToHex(pX^, (TBmp.Width * TBmp.Height) * 3, Result);
  finally
    TBmp.Free;
  end;
end;

procedure StrToBitmap(const Str: string; const Width,Height: integer; Bmp: TBitmap);
var pX : ^byte;
    TBmp : TBitmap;
begin
  TBmp := TBitmap.Create;
  try
    TBmp.PixelFormat := pf24bit;
    TBmp.Width       := Width;
    TBmp.Height      := Height;
    pX := TBmp.ScanLine[TBmp.Height-1];
    HexToBin(Str, Length(Str), pX^);
    Bmp.Assign(TBmp);
  finally
    TBmp.Free;
  end;
end;


exemple :

procedure TForm1.Button1Click(Sender: TObject);
var StrL : TStringList;
begin
 StrL := TStringList.Create;
  try
    StrL.Text := BitmapToStr(Image1.picture.bitmap);
    StrL.SaveToFile('c:\data.txt');
  finally
    StrL.Free;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var StrL : TStringList;
begin
  StrL := TStringList.Create;
  try
    StrL.LoadFromFile('c:\data.txt');
    StrToBitmap(StrL.Text, 512, 384, Image1.Picture.Bitmap);
  finally
    StrL.Free;
  end;
end;



voilou, non seulement ça marchera, mais en plus ça marchera mieux et plus vite.

note :

la taille du bitmap n'est pas sauvegarder, il faut la memoriser quelque part pour ensuite appeler StrToBitmap avec les bonnes dimensions.



samedi 5 juillet 2008 à 15:59:28 | Re : Txt2BMP ?

MiniProgramer

error si je fais Click sur Button1:
scan Line Index put of Range
samedi 5 juillet 2008 à 17:10:46 | Re : Txt2BMP ?

Rematrix

éssay ça
http://www.delphifr.com/codes/DFM-READER_46167.aspx

Matrix


Cette discussion est classée dans : end, string, to, begin, result


Sujets en rapport avec ce message

openoffice.org(ooo) et la couleur de fond d'une cellule [ par Tiekula ] J'arrive a ouvrir un fichier exel avec ooo mais pas a trouver la couleur d'une cellule donnée de ce fichier! mon code : unit Unit1; interface use Exclure des caractères d'un string [ par DRJEROME ] bonjour,je n'ai pas accès au "Snippets" de mon ordinateur principal alors que j'ai accès par un ordinateur d'un collègue ... bizarre !je voulais juste pb sur delphi a la compilation need help !!! [ par shark1664 ] voila mon code c'est une requete qui récupère dans une table une ligne compète quand le code est pareil que ce que l'utilisateur a siasie et au niveau Bien installer un API [ par Also know as ] Bonjour a tous, Bon alors apres une longue surune certaine erreur enfin resolu :-), on m'a conseille d'utiliser un nouvel API. Je souhaiterais utilise Tableau 2 dimensions [ par lusitano69 ] Bonjour je m'explique je voudrais avec un string que j ai récupéré(contient des coordonées de X,Y par exemple) remplir un tableau à 2 dimensions mais Tfilestream : problème de lecture du fichier [ par bv94 ] Bonsoir,mon problème est le suivant : je créé un type Toperation qui hérite de Tfilestream. Mais les fonctions de tfilestream que j'utilise (read, see Composant [ par cricri_forever ] Quelqu'un pourrait m'aider a expliquer ce code et si il a moyen de le simplifier encore...procedure TVersion.ChangeVersionResult(Value: boolean);begin Fenetre MDI [ par develomagaly ] VOila j'ai une fenetre parents avec des fenetres Mdichild qui s'ouvre en cliquant sur le menu. Le but est de ne pas pouvoir ouvrir deux fenetres fille Arbre équilibré [ par Pallas4 ] Bonjour j'aimerais programmé un arbre équilibré maismon programme plante. IP cute me dit que des données sont dans le tas mais ne peuvent être atteint garder plusieurs images en memoire [ par valkyrie ] Bonjourj aimerais garder en memoire plusieurs images en meme temps du genrej ai une fenetre avec 6 boutons d opendialogje rentre le nom de l image dan


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,515 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales