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
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
Marcelo,
I don*t understand.
How do You want to save a area of a Image without Preview,
to select the Area ?
Best Regards
Uwe ![]()
Hello,
thanks for your response, I will try to be clear
I have a image in file, what I want is cut some area from this image and save cuted area to other image file, without show any thing. The area to cut (top, left...) will be parameters.
thanks in advance
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 ENDDUMPDaniel,
thanks very much, but
I am trying to do the same but for JPG files, are there some function compatible with ReadBitmap but for JPG files?
Regards
Marcelo
#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:nHeightDaniel,
really I appreciate your help, all work perfectly, one help more sorry
how can I save the cropping image to a other file format like JPG
muchas gracias
Marcelo
Hello
i dont know if this feature is supported by freeimage, for now is only BMP using fivewin