Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   C++ Builder (https://www.clubdelphi.com/foros/forumdisplay.php?f=13)
-   -   ¿como CrearBitmap ? codigo de delphi a C++ Builder (https://www.clubdelphi.com/foros/showthread.php?t=92071)

JXJ 15-07-2017 22:52:59

¿como CrearBitmap ? codigo de delphi a C++ Builder
 
hola

tengo este codigo delphi que crea un bitmap.
es una funcion que regresa un bitmap

Código Delphi [-]
class function TQRCode.GetBitmapImage(const Text: string; Margin,
  PixelSize: integer; Level : TErrorCorretion): TBitmap;
var
  Bmp : HBITMAP;
  DIB: TDIBSection;
  ScreenDC : THandle;
  DC : THandle;
begin
  Bmp := GetHBitmap(PChar(Text), Margin, PixelSize, ord(Level));
  GetObject(Bmp, SizeOf(DIB), @DIB);
  Result := TBitmap.Create();
  Result.Width := DIB.dsBmih.biWidth;
  Result.Height := DIB.dsBmih.biHeight;
  Result.PixelFormat := pf32bit;
  ScreenDC := GetDC(0);
  DC := CreateCompatibleDC(ScreenDC);
  SelectObject(DC, Bmp);
  ReleaseDC(0, ScreenDC);
  BitBlt(Result.Canvas.Handle, 0, 0, Result.Width, Result.Height, DC, 0, 0, SRCCOPY);
  DeleteDC(DC);
  DeleteObject(Bmp);
end;

Al convertirla a C++ Builder me da error.

Código PHP:


    TBitmap __fastcall TFrmMainF
::GetBitmapImage(String TextoToImgQRCodeint Marginint PixelSizeint Level )
    {
      
HBITMAP Bmp;
      
TDIBSection DIB;
      
THandle ScreenDC;
     
THandle DC;

        
String TextoToQR TextoToImgQRCode;
            
char *TextoToQRImg AnsiString(TextoToQR).c_str()  ;


       
Bmp GetHBitmapA(TextoToQRImgMargin,PixelSizeLevel)  ;
       
GetObjectA(Bmpsizeof(DIB), &DIB);

       
Graphics::TBitmap *Result = new Graphics::TBitmap;
       
Result->Width DIB.dsBmih.biWidth;
       
Result->Height DIB.dsBmih.biHeight;
       
Result->PixelFormat pf32bit;

       
ScreenDC GetDC(0);
    } 

el ide de c++ builder como hint, en el editor me indica que ScreenDC es un unsigned int
y que GetDC(0) es una macro __in_opt HWND hWnd

al compilar me sale este error

[bcc32 Error] FrmMainU.cpp(65): E2034 Cannot convert 'HDC__ *' to 'unsigned int'
Full parser context
FrmMainU.cpp(47): parsing: TBitmap _fastcall TFrmMainF::GetBitmapImage(UnicodeString,int,int,int)

que ando haciendo mal. ?
¿como lo puedo solucionar ?

gracias.

JXJ 15-07-2017 23:44:38

avanze algo en los tipos
y ahora me da error de que
[bcc32 Error] FrmMainU.cpp(74): E2108 Improper use of typedef 'DWORD'

BitBlt(Result->Canvas->Handle, 0,0, Result->Width, Result->Height, DC, 0,0 SRCCOPY);

no se por que no me acepta SRCCOPY
Código PHP:

    TBitmap __fastcall TFrmMainF::GetBitmapImage(String TextoToImgQRCodeint Marginint PixelSizeint Level )
    {
      
HBITMAP Bmp;
      
TDIBSection DIB;
//      THandle ScreenDC;
//     THandle DC;

        
String TextoToQR TextoToImgQRCode;
            
char *TextoToQRImg AnsiString(TextoToQR).c_str()  ;


       
Bmp GetHBitmapA(TextoToQRImgMargin,PixelSizeLevel)  ;
       
GetObjectA(Bmpsizeof(DIB), &DIB);

       
Graphics::TBitmap *Result = new Graphics::TBitmap;
       
Result->Width DIB.dsBmih.biWidth;
       
Result->Height DIB.dsBmih.biHeight;
       
Result->PixelFormat pf32bit;

     
HDC  ScreenDC GetDC(0);
     
HDC DC CreateCompatibleDC(ScreenDC);
     
SelectObject(DCBmp);
     
ReleaseDC(0ScreenDC);
//     const BitBltRopMode_WinNT = $40000000 or SRCCOPY;

     
BitBlt(Result->Canvas->Handle0,0Result->WidthResult->HeightDC0,0  SRCCOPY);
     
DeleteDC(DC);
     
DeleteObject(Bmp);
    } 


_Leo 16-07-2017 01:48:30

Te falta una coma en la siguiente línea que provoca precisamente ese error:

Código:

BitBlt(Result->Canvas->Handle, 0,0, Result->Width, Result->Height, DC, 0,0  SRCCOPY);
                                                                          ^
                                                                          |

Si dentro de la función necesitas trabajar con ANSI, solo tienes que declarar como AnsiString "TextoToImgQRCode"

Lo digo por la línea donde veo que haces algo "raro" dentro de la función con "String". String es un typedef que según si en las propiedades del proyecto tienes "TCHAR" mapeado a "char" o a "wchar_t" se declara como AnsiString o UnicodeString respectivamente. De todas formas no debería ser necesario en teoría si en las opciones del proyecto esta mapeado para trabajar con o sin Unicode.

La salida de la función la tienes como "TBitmap" y debería ser "Graphics::TBitmap*", y te falta añadir un "return Result;" al final de la función. Aunque con lo de la coma supongo que ya te habrías dado cuenta. Que una coma o un punto y coma puede volver loco a cualquiera cuando lleva muchas horas.. ;-)

JXJ 16-07-2017 22:20:06

Muchisimas Gracias _Leo

no vi que faltara la ,

y lo del resto tambien me ayuda mucho.

probe el codigo y si funciona,, :D:D:D:D::D:D:D:D

Que dicha.

Buen dia. ;D

JXJ 17-07-2017 00:03:22

Muchisimas Gracias _Leo

no vi que faltara la ,

y lo del resto tambien me ayuda mucho.

probe el codigo y si funciona,, :D:D:D:D::D:D:D:D

Que dicha.
la cosa rara con los ansi string , es por que es la unica forma que encontre de pasar el unicodestring del edit
a la funcion de la libreria que solo acepta ansi o de tipo char* , no soy bueno en c++ por eso es que hize esa cosa rara

aparte de que la lib qricol se compila con c++ de visual studio.
y la dll el autor de qrcol la da con un wrapper para delphi.
la recomendacion es usarlo con versiones delphi que soportan unicode

y la png y zlib y jpeg, las compile con c++ builder xe6


Buen dia. ;D

header
Código PHP:

//---------------------------------------------------------------------------

#ifndef FrmMainUH
#define FrmMainUH

//#define MiSRCCOPY              (DWORD)0x00CC0020 /* dest = source*/
     #define BitBltRopMode_WinNT (DWORD)0x00CC0020 or SRCCOPY;
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <System.Actions.hpp>
#include <Vcl.ActnList.hpp>
#include <Vcl.Dialogs.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.Menus.hpp>
#include <Vcl.Samples.Spin.hpp>
#include <Winapi.Windows.hpp>
#include <System.SysUtils.hpp>
#include <Vcl.Imaging.jpeg.hpp>
#include "../include/qrcode/quricol.h"
//---------------------------------------------------------------------------
class TFrmMainF : public TForm
{
__published:    // IDE-managed Components
    
TShape *Shape1;
    
TLabel *Label1;
    
TBevel *Bevel1;
    
TImage *imgCode;
    
TLabel *Label2;
    
TLabel *Label3;
    
TEdit *edtText;
    
TSpinEdit *edtMargin;
    
TSpinEdit *edtSize;
    
TActionList *ActionList1;
    
TAction *actClose;
    
TAction *actSave;
    
TAction *actCreate;
    
TAction *actCopy;
    
TSaveDialog *SaveDialog;
    
TPopupMenu *PopupMenu1;
    
TMenuItem *Opslaan1;
    
TMenuItem *Kopierennaarhetklembord1;
    
TButton *btnCreate;
    
TButton *btnSave;
    
TButton *BtnClose1;
    
TButton *Button1;
    
TMemo *Memo1;
    
void __fastcall actCloseExecute(TObject *Sender);
    
void __fastcall actSaveExecute(TObject *Sender);
    
void __fastcall Button1Click(TObject *Sender);
[
bGraphics::TBitmap__fastcall GetBitmapImage(String TextoToImgQRCodeint Marginint PixelSizeint Level );[/b]
private:    
// User declarations
public:        // User declarations
    
__fastcall TFrmMainF(TComponentOwner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFrmMainF *FrmMainF;
//---------------------------------------------------------------------------
#endif 

implementacion corregida
Código PHP:



Graphics
::TBitmap__fastcall TFrmMainF::GetBitmapImage(String TextoToImgQRCodeint Marginint PixelSizeint Level )
    {
      
HBITMAP Bmp;
      
TDIBSection DIB;
//      THandle ScreenDC;
//     THandle DC;

        
String TextoToQR TextoToImgQRCode;
            
char *TextoToQRImg AnsiString(TextoToQR).c_str()  ;

       
Bmp GetHBitmapA(TextoToQRImgMargin,PixelSizeLevel)  ;
       
GetObjectA(Bmpsizeof(DIB), &DIB);

       
Graphics::TBitmap *Result = new Graphics::TBitmap;
       
Result->Width DIB.dsBmih.biWidth;
       
Result->Height DIB.dsBmih.biHeight;
       
Result->PixelFormat pf32bit;

     
HDC  ScreenDC GetDC(0);
     
HDC DC CreateCompatibleDC(ScreenDC);
     
SelectObject(DCBmp);
     
ReleaseDC(0ScreenDC);


     
BitBlt(Result->Canvas->Handle0,0Result->WidthResult->HeightDC0,0,  SRCCOPY);// da error no se por que
     
DeleteDC(DC);
     
DeleteObject(Bmp);

     return 
Result;
    } 

procedure donde la uso
Código PHP:



void __fastcall TFrmMainF
::actSaveExecute(TObject *Sender)
{
 
String Ext;
 
TJPEGImage *Jpg = new TJPEGImage();
 
TBitmap *= new TBitmap;
     
/*
 if SaveDialog.Execute then
   begin
     Ext := ExtractFileExt(SaveDialog.FileName);
     if SameText(ext, '.png') then
       TQRCode.GeneratePngFile(SaveDialog.FileName, edtText.Text, edtMargin.Value, edtSize.Value){este es el de interes gdmx como guardar como png}
     else if SameText(ext, '.bmp') then
       TQRCode.GenerateBitmapFile(SaveDialog.FileName, edtText.Text, edtMargin.Value, edtSize.Value)
     else
       begin
         Jpg := TJPEGImage.Create;
         B := TQRCode.GetBitmapImage(edtText.Text, edtMargin.Value, edtSize.Value);
         Jpg.Assign(B);
         B.Free;
         Jpg.SaveToFile(SaveDialog.FileName);
         Jpg.Free;
       end;
   end;                 */
    
if (SaveDialog->Execute() )
    {
        
Memo1->Lines->Add("nombrearch SAVEEXecute " SaveDialog->FileName);
      
Ext ExtractFileExt(SaveDialog->FileName);
            
Memo1->Lines->Add("estension saveexe" Ext);
       if(
SameText(Ext,".png"))
       {
         
String NameFile SaveDialog->FileName;
            
char *NameFileOD AnsiString(NameFile).c_str();

            
String TextoToQR edtText->Text;
            
char *TextoToQRImg AnsiString(TextoToQR).c_str()  ;

            
Memo1->Lines->Add(Ext);
                                    
Memo1->Lines->Add("dentro de png SAVEEXecute " SaveDialog->FileName);
//          GeneratePNGW(  SaveDialog->FileName.c_str(), edtText->Text.c_str(),   edtMargin->Value, edtSize->Value,3) ;
          
GeneratePNGA(  NameFileOD      ,  TextoToQRImg  ,   edtMargin->ValueedtSize->Value,3) ;
       }
       else if (
SameText(Ext".bmp"))
       {
          
String NameFile SaveDialog->FileName;
            
char *NameFileOD AnsiString(NameFile).c_str();

            
String TextoToQR edtText->Text;
            
char *TextoToQRImg AnsiString(TextoToQR).c_str()  ;
         
GenerateBMPA(  NameFileOD      ,  TextoToQRImg  ,   edtMargin->ValueedtSize->Value,3) ;
       }
       else
       {
            
String NameFile SaveDialog->FileName;
            
char *NameFileOD AnsiString(NameFile).c_str();

            
String TextoToQR edtText->Text;
            
char *TextoToQRImg AnsiString(TextoToQR).c_str()  ;

              
=  GetBitmapImage(TextoToQRImgedtMargin->ValueedtSize->Value);
               
Jpg->Assign(B);
               
B->Free();
               
Jpg->SaveToFile(SaveDialog->FileName);
               
Jpg->Free();
       }
    }





La franja horaria es GMT +2. Ahora son las 22:08:50.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi