Posible error

Posible error

Postby wmormar » Sun Oct 17, 2010 11:20 am

Amigos,

Le he dado vueltas durante varios dias y el siguiente error me tiene loco.

Cuando copio una imagen al portapapeles y ejecuto el siguiente codigo:
Code: Select all  Expand view
     cFoto    := ".\tempo\tmpmem.bmp"
      FErase( cFoto )
      hBitmap    := oClp:GetBitmap()
      hDib       := DibFromBitmap( hBitmap, 0 )
      DibWrite( cFoto, hDib )
      oFoto:LoadImage( ,cFoto )
      oFoto:refresh()
 


Me da como resultado una imagen distorsionada como está:

Image

Uploaded with ImageShack.us

En versiones anteriores a la 10.8 todo funcionaba de maravillas con el mismo código

Quedo a la espera de su valiosa ayuda.
Gracias de antemano
William, Morales
Saludos

méxico.sureste
User avatar
wmormar
 
Posts: 1073
Joined: Fri Oct 07, 2005 10:41 pm
Location: México

Re: Posible error

Postby Daniel Garcia-Gil » Sun Oct 17, 2010 7:28 pm

William

intenta de esta forma
Code: Select all  Expand view

#include "fivewin.ch"


function main

   local oWnd
   local cFoto  
   local oBar, oClp
   
   define window oWnd
   define buttonbar oBar of oWnd
   
   define clipboard oClp of oWnd
   
   define button action LoadFromClip( oClp, oFoto ) of oBar
   
   @ 35,1 image oFoto size 480, 400 pixel
   
   
   activate window oWnd
   

return nil

function LoadFromClip( oClp, oFoto )

   local cBmp
   cFoto    := ".\tmpmem.bmp"
   FErase( cFoto )
   hBitmap    := oClp:GetBitmap()
   if hBitmap != 0
      cBmp := BmpToStr( hBitmap )
      memowrit( cFoto, cBmp )
      oFoto:LoadImage( ,cFoto )
      oFoto:refresh()
   else
      Msginfo( "no image in clipboard")
   endif

return nil

 
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Posible error

Postby Daniel Garcia-Gil » Sun Oct 17, 2010 10:10 pm

William

Para solucionarlo de la forma como lo usas he hecho estos cambios/subtituciones

cuando compiles ambos fuentes en C se generaran unos warning totalmete inofencivos, no les prestes atencion

dib.c

Agregar

Code: Select all  Expand view
char * DibToStr( HGLOBAL hDib, long * plSize )
{
   LPBITMAPINFO Info = ( LPBITMAPINFO ) GlobalLock( hDib );
   void * Bits  = ( void * ) ( ( char * ) Info + Info->bmiHeader.biSize +
                    wDIBColors( ( LPBITMAPINFOHEADER ) Info ) * sizeof( RGBQUAD ) );  
   BITMAPFILEHEADER bmf;
   char * pDib;
   long lSize;

   lSize = GlobalSize( ( HGLOBAL ) Info );
   
   pDib = hb_xgrab( sizeof( bmf ) + lSize );

   bmf.bfType      = 0x4D42;
   bmf.bfSize      = sizeof( bmf ) + lSize;
   bmf.bfReserved1 = 0;
   bmf.bfReserved2 = 0;
   bmf.bfOffBits   = sizeof( bmf ) + ( LONG ) Bits - ( LONG ) Info;  
   
   memcpy( pDib, &bmf, sizeof( bmf ) );
   memcpy( ( char * ) pDib + sizeof( bmf ), ( void * ) Info, lSize );
   lSize += sizeof( BITMAPFILEHEADER );
   *plSize = lSize;
   
   return pDib;
}


cambiar

Code: Select all  Expand view

BOOL DibWrite( LPSTR szFileName, HGLOBAL hDIB )
{

   long lSize;
   char * pDib;
   int hBmp;
   
   pDib = DibToStr( hDIB, &lSize );

   #ifndef UNICODE
   if( ( hBmp = _lcreat( szFileName, 0 ) ) != HFILE_ERROR )
   {
      _hwrite( hBmp, ( const char * ) pDib, lSize );
      _lclose( hBmp );
      GlobalUnlock( hDIB );
      return TRUE;
   }
   #else
   if( ( hBmp = hb_fsCreate( ( unsigned char * ) szFileName, 0 ) ) != ( int ) INVALID_HANDLE_VALUE )
   {
      hb_fsWriteLarge( hBmp, ( unsigned char * ) pDib, lSize );
      hb_fsClose( hBmp );
      GlobalUnlock( hDIB );
      return TRUE;
   }
   #endif
   else
   {
      GlobalUnlock( hDIB );
      return FALSE;
   }
}
 



dibbmp.c

agregar prototipo

Code: Select all  Expand view
char * DibToStr( HGLOBAL hDib, long * plSize );


cambiar
Code: Select all  Expand view

HB_FUNC( BMPTOSTR ) // hBmp --> cBitmapAsString
{
   HGLOBAL hDib = ( HGLOBAL ) DibFromBitmap( ( HBITMAP ) hb_parnl( 1 ), 0, 0, NULL );
   long lSize;
   char * pDib = DibToStr( hDib, &lSize );

   hb_retclen( pDib, lSize );
   
   GlobalUnlock( hDib );
   GlobalFree( hDib );
   hb_xfree( pDib );
}
 
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Posible error

Postby wmormar » Mon Oct 18, 2010 2:47 am

Daniel,

Muchas gracias por tu ayuda como siempre.

La primera opción funciona de perlas, sin problemas.

La opción segunda mas compleja y he realizado las modificaciones que comentas y no funciona, el mismo problema y solo a veces sale bien la imagen. Cuando graba el archivo Windows detecta el archivo con problemas y no muestra la imagen en el preview que trae windows. Si abro el archivo con el Paint y lo grabo sobre el paint, ya se corrije el archivo de imagen.

Quedo pendiente. Saludos
William, Morales
Saludos

méxico.sureste
User avatar
wmormar
 
Posts: 1073
Joined: Fri Oct 07, 2005 10:41 pm
Location: México

Re: Posible error

Postby Daniel Garcia-Gil » Mon Oct 18, 2010 2:55 am

William

a mi me funcionan bien las modificaciones y no hice mas de lo que publique,
te pregunto, modificaste los fuentes o agregastes las funciones aparte?
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Posible error

Postby wmormar » Mon Oct 18, 2010 7:52 am

Daniel Garcia-Gil wrote:William

a mi me funcionan bien las modificaciones y no hice mas de lo que publique,
te pregunto, modificaste los fuentes o agregastes las funciones aparte?


Daniel,

Agregue las funciones con todo lo que mencionas. Así quedó:
Code: Select all  Expand view
#pragma BEGINDUMP
/*
#include <windows.h>
#include <hbapi.h>

 /// ....  Aquí adicioné las funciones que comentas y esto está en el PRG principal de mi aplicación

#pragma ENDDUMP



Saludos y quedo pendiente de lo que comentes
William, Morales
Saludos

méxico.sureste
User avatar
wmormar
 
Posts: 1073
Joined: Fri Oct 07, 2005 10:41 pm
Location: México

Re: Posible error (** SOLUCIONADO ** )

Postby wmormar » Wed Oct 20, 2010 12:01 am

Daniel,

Efectivamente integrando las modificaciones directas a los fuentes de FWH y recompilando las LIB funciona de maravilla tal cual dejaste el código.

Gracias Mil
William, Morales
Saludos

méxico.sureste
User avatar
wmormar
 
Posts: 1073
Joined: Fri Oct 07, 2005 10:41 pm
Location: México

Re: Posible error

Postby reinaldocrespo » Wed Oct 27, 2010 6:53 pm

Daniel;

Hola. Has puesto en algun lugar como compilar los .c de fivec.lib?

Imagino que lleva algunos flags?

Traté de compilar con bcc. Tengo esto:
Borland C++ 5.82 for Win32 Copyright (c) 1993, 2005 Borland
dib.c:
Warning W8060 dib.c 68: Possibly incorrect assignment in function DibRead
Warning W8060 dib.c 70: Possibly incorrect assignment in function DibRead
Warning W8065 dib.c 240: Call to function 'hb_parc' with no prototype in function HB_FUNC
Warning W8070 dib.c 241: Function should return a value in function HB_FUNC
Warning W8057 dib.c 241: Parameter 'DIBREAD' is never used in function HB_FUNC
Error E2238 dib.c 246: Multiple declaration for 'HB_FUNC'
Error E2344 dib.c 238: Earlier declaration of 'HB_FUNC'
...



Gracias,


Reinaldo.
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Posible error

Postby Daniel Garcia-Gil » Wed Oct 27, 2010 9:22 pm

Reinaldo

Puedes agregar esto en tu prg principal

Code: Select all  Expand view
#pragma BEGINDUMP
#include <windows.h>
#include <hbapi.h>

WORD far pascal wDIBColors( LPBITMAPINFOHEADER );

HANDLE DibFromBitmap( HBITMAP, DWORD, WORD, HPALETTE );


char * DibToStr( HGLOBAL hDib, long * plSize )
{
   LPBITMAPINFO Info = ( LPBITMAPINFO ) GlobalLock( hDib );
   void * Bits  = ( void * ) ( ( char * ) Info + Info->bmiHeader.biSize +
                    wDIBColors( ( LPBITMAPINFOHEADER ) Info ) * sizeof( RGBQUAD ) );  
   BITMAPFILEHEADER bmf;
   char * pDib;
   long lSize;

   lSize = GlobalSize( ( HGLOBAL ) Info );
   
   pDib = hb_xgrab( sizeof( bmf ) + lSize );

   bmf.bfType      = 0x4D42;
   bmf.bfSize      = sizeof( bmf ) + lSize;
   bmf.bfReserved1 = 0;
   bmf.bfReserved2 = 0;
   bmf.bfOffBits   = sizeof( bmf ) + ( LONG ) Bits - ( LONG ) Info;  
   
   memcpy( pDib, &bmf, sizeof( bmf ) );
   memcpy( ( char * ) pDib + sizeof( bmf ), ( void * ) Info, lSize );
   lSize += sizeof( BITMAPFILEHEADER );
   *plSize = lSize;
   
   return pDib;
}


BOOL DibWrite( LPSTR szFileName, HGLOBAL hDIB )
{

   long lSize;
   char * pDib;
   int hBmp;
   
   pDib = DibToStr( hDIB, &lSize );

   #ifndef UNICODE
   if( ( hBmp = _lcreat( szFileName, 0 ) ) != HFILE_ERROR )
   {
      _hwrite( hBmp, ( const char * ) pDib, lSize );
      _lclose( hBmp );
      GlobalUnlock( hDIB );
      return TRUE;
   }
   #else
   if( ( hBmp = hb_fsCreate( ( unsigned char * ) szFileName, 0 ) ) != ( int ) INVALID_HANDLE_VALUE )
   {
      hb_fsWriteLarge( hBmp, ( unsigned char * ) pDib, lSize );
      hb_fsClose( hBmp );
      GlobalUnlock( hDIB );
      return TRUE;
   }
   #endif
   else
   {
      GlobalUnlock( hDIB );
      return FALSE;
   }
}
 

HB_FUNC( BMPTOSTR ) // hBmp --> cBitmapAsString
{
   HGLOBAL hDib = ( HGLOBAL ) DibFromBitmap( ( HBITMAP ) hb_parnl( 1 ), 0, 0, NULL );
   long lSize;
   char * pDib = DibToStr( hDib, &lSize );

   hb_retclen( pDib, lSize );
   
   GlobalUnlock( hDib );
   GlobalFree( hDib );
   hb_xfree( pDib );
}


HB_FUNC( DIBWRITE )  // ( cFileName, hDib ) --> lSuccess
{
   hb_retl( DibWrite( ( char * ) hb_parc( 1 ), ( HGLOBAL ) hb_parnl( 2 ) ) );
}
 
#pragma ENDDUM
P
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Posible error

Postby reinaldocrespo » Wed Oct 27, 2010 9:44 pm

Daniel;

No. O sea, no quiero tener que cambiar todos mis proyectos. Eso no hace sentido.

Déjame explicar; Ya adqirí Fwh de Oct 2010 que obviamente se publicó con bugs al que tu aparentemente le estas haciendo las correcciones. Si una función tiene un bug y tu me publicas el arreglo, pues chévere, le hago el arreglo, se recompila y se mete en su .lib. Listo. Yo acepto eso.

Tener que alterar todos mis proyectos porque una función en fivehc tiene un bug, no es buena idea.

Espero me entiendas.

Reinaldo.
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Posible error

Postby Daniel Garcia-Gil » Wed Oct 27, 2010 10:31 pm

Reinaldo

para reconstruir la libreria de C (lfivehc.lib) de FW debes usar harbour indistintamente si usas xharbour, de las conversiones se encarga internamente fivewin,
o en su defecto usar los include de harbour y agregar usar estos flags

-c -q -tWM -IHARBOUR_INCLUDE_PATH -IFWH_INCLUDE_PATH -D__HARBOUR__
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Posible error

Postby reinaldocrespo » Wed Oct 27, 2010 11:04 pm

Daniel;

Gracias.

Usé el include path de una copia de harbour del 2003 que tengo. Parece que funcionó bien. Un par de Warnings, pero ya tu habías anunciado que los debo ignorar.

Todos los años en Junio me invitan a un evento en Isla Margarita. Este año que viene voy y de una vez te busco para conocerte. Despues de todo la Isla no puede ser tan grande. o no?

Un saludo,


Reinaldo.
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Posible error

Postby Daniel Garcia-Gil » Wed Oct 27, 2010 11:12 pm

Reinaldo

sera un inmenso placer...

es una isla muy pequeña y soy facilmente localizable
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 86 guests