Hello,
I need to read image from disk without displaying it, then cut some area and save these to disk in new file
some help I will appreciate
regards
Marcelo
#include "fivewin.ch"
function main()
local oWnd
local hBmp := ReadBitmap( 0, "007.bmp" )
local hCut := CutImage( 40, 40, 80, 80, hBmp )
local hDib := DibFromBitmap( hCut )
DibWrite( "test.bmp", hDib )
DeleteObject( hDib )
DeleteObject( hCut )
DeleteObject( hBmp )
return nil
#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>
HB_FUNC( CUTIMAGE )
{
HDC hdc1, hdcSrc, hdcDest;
HBITMAP hbmpSrc = ( HBITMAP ) hb_parnl( 5 );
HBITMAP hbmpDest, hold1, hold2;
RECT rct;
BITMAP bm;
rct.top = hb_parnl( 1 );
rct.left = hb_parnl( 2 );
rct.bottom = hb_parnl( 3 );
rct.right = hb_parnl( 4 );
GetObject( ( HGDIOBJ ) hbmpSrc, sizeof( BITMAP ), ( LPSTR ) &bm );
hdc1 = GetDC( GetDesktopWindow() );
hdcSrc = CreateCompatibleDC( hdc1 );
hdcDest = CreateCompatibleDC( hdc1 );
hbmpDest = CreateCompatibleBitmap( hdc1, rct.right - rct.left, rct.bottom - rct.top );
ReleaseDC( GetDesktopWindow(), hdc1 );
hold1 = SelectObject( hdcSrc, hbmpSrc );
hold2 = SelectObject( hdcDest, hbmpDest );
BitBlt( hdcDest, 0, 0, rct.right, rct.bottom, hdcSrc, rct.left, rct.top, SRCCOPY );
SelectObject( hdcSrc, hold1 );
SelectObject( hdcDest, hold2 );
DeleteDC( hdcSrc );
DeleteDC( hdcDest );
hb_retnl( ( LONG ) hbmpDest );
}
#pragma ENDDUMP
#include "fivewin.ch"
function main()
CutImage( "007.bmp", "cut_007.bmp" )
CutImage( "halo.gif", "cut_halo.bmp" )
CutImage( "fivewin.png", "cut_five.bmp" )
CutImage( "olga.bmp", "cut_olga.bmp" )
return nil
function CutImage( cNameIn, cNameOut )
local hBmp := FiLoadImg( cNameIn )
local hCut := CropImage( hBmp, 40, 40, 80, 80 )
local hDib := DibFromBitmap( hCut )
DibWrite( cNameOut, hDib )
DeleteObject( hDib )
DeleteObject( hCut )
DeleteObject( hBmp )
return nil
#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>
HB_FUNC( CROPIMAGE ) //hOriginalBmp, nTop, nLeft, nBottom, nRight --> hCroppedBmp
{
HDC hdc1, hdcSrc, hdcDest;
HBITMAP hbmpSrc = ( HBITMAP ) hb_parnl( 1 );
HBITMAP hbmpDest, hold1, hold2;
RECT rct;
BITMAP bm;
GetObject( ( HGDIOBJ ) hbmpSrc, sizeof( BITMAP ), ( LPSTR ) &bm );
rct.top = hb_pcount() > 1 ? hb_parnl( 2 ) : 0;
rct.left = hb_pcount() > 2 ? hb_parnl( 3 ) : 0;
rct.bottom = hb_pcount() > 3 ? hb_parnl( 4 ) : bm.bmHeight;
rct.right = hb_pcount() > 4 ? hb_parnl( 5 ) : bm.bmWidth;
hdc1 = GetDC( GetDesktopWindow() );
hdcSrc = CreateCompatibleDC( hdc1 );
hdcDest = CreateCompatibleDC( hdc1 );
hbmpDest = CreateCompatibleBitmap( hdc1, rct.right - rct.left, rct.bottom - rct.top );
ReleaseDC( GetDesktopWindow(), hdc1 );
hold1 = SelectObject( hdcSrc, hbmpSrc );
hold2 = SelectObject( hdcDest, hbmpDest );
BitBlt( hdcDest, 0, 0, rct.right, rct.bottom, hdcSrc, rct.left, rct.top, SRCCOPY );
SelectObject( hdcSrc, hold1 );
SelectObject( hdcDest, hold2 );
DeleteDC( hdcSrc );
DeleteDC( hdcDest );
hb_retnl( ( LONG ) hbmpDest );
}
#pragma ENDDUMP
LOCAL hBmp := oImage:hBitmap
LOCAL hDc := GetDc(hBmp)
local hDCMem := CreateCompatibleDC( hDC )
local hOldBmp:= SelectObject( hDCMem, hBmp )
local nX := oImage:nWidth
local nY := oImage:nHeight
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Google [Bot] and 110 guests