Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros entornos y lenguajes > C++ Builder
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 15-07-2017
JXJ JXJ is offline
Miembro
 
Registrado: abr 2005
Posts: 2.475
Poder: 21
JXJ Va por buen camino
Question ¿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.
Responder Con Cita
  #2  
Antiguo 15-07-2017
JXJ JXJ is offline
Miembro
 
Registrado: abr 2005
Posts: 2.475
Poder: 21
JXJ Va por buen camino
Question

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);
    } 
Responder Con Cita
  #3  
Antiguo 16-07-2017
Avatar de _Leo
_Leo _Leo is offline
Miembro
 
Registrado: ene 2017
Ubicación: Lanzarote (Islas Canarias)
Posts: 38
Poder: 0
_Leo Va camino a la fama
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.. ;-)

Última edición por _Leo fecha: 16-07-2017 a las 02:01:11.
Responder Con Cita
  #4  
Antiguo 16-07-2017
JXJ JXJ is offline
Miembro
 
Registrado: abr 2005
Posts: 2.475
Poder: 21
JXJ Va por buen camino
Muchisimas Gracias _Leo

no vi que faltara la ,

y lo del resto tambien me ayuda mucho.

probe el codigo y si funciona,, :

Que dicha.

Buen dia. ;D

Última edición por JXJ fecha: 16-07-2017 a las 22:30:52.
Responder Con Cita
  #5  
Antiguo 17-07-2017
JXJ JXJ is offline
Miembro
 
Registrado: abr 2005
Posts: 2.475
Poder: 21
JXJ Va por buen camino
Muchisimas Gracias _Leo

no vi que faltara la ,

y lo del resto tambien me ayuda mucho.

probe el codigo y si funciona,, :

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();
       }
    }


Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Este código Delphi como sería en C++ Builder pepe_baile C++ Builder 5 22-02-2017 18:47:06
pasar codigo de delphi a c++ Builder rxaxx9 C++ Builder 2 13-05-2012 07:27:17
codigo en delphi a c++ builder zidfrid C++ Builder 4 09-07-2008 15:34:29
Convertir codigo Delphi a Builder _Willa C++ Builder 3 15-02-2008 12:37:10
Cambiando el codigo de delphi a builder... paco_galo C++ Builder 5 03-12-2007 23:14:54


La franja horaria es GMT +2. Ahora son las 15:43:05.


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
Copyright 1996-2007 Club Delphi