FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Saving bitmap from TXImage.
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Saving bitmap from TXImage.
Posted: Fri Feb 19, 2016 10:57 AM

Change bitmap in TXImage. Can I save the modified bitmap into a file ?

Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Saving bitmap from TXImage.
Posted: Fri Feb 19, 2016 01:23 PM
Used the example XIMAGE01.PRG
Open bitmap 2.png, rotate it and save in a file named my.png
It's works. But the bitmap remains unchanged

Code (fw): Select all Collapse
procedure Sav_Img
local hDib:=DibFromBitmap( oWnd:aControls[3]:GetHBitmap() )
local cTempFile := cTempFile()
local lSaved

  nFormat:=13
  nQuality:=25
  cFile:="my.png"

  DibWrite( cTempFile, hDib )
  GloBalFree( hDib )
  lSaved = FIConvertImageFile( cTempFile, cFile, nFormat, nQuality )
  FErase( cTempFile )
return

function FIConvertImageFile( cSrcFile, cDstFile, nDstFormat, nQuality )
local nSrcFormat, hDib, hDib2, lOk := .f.

   DEFAULT nQuality := 0

   if LoadFreeImage() > 32
      nSrcFormat:= FIGETFILETYPE( cSrcFile, 0 )

      hDib:= FILOAD( nSrcFormat, cSrcFile, 0 )
      hDib2:= FICNV24( hDib )
      lOk:= FISAVE( nDstFormat, hDib2, cDstFile, nQuality )

      FIUNLOAD( hDib )
      FIUNLOAD( hDib2 )
   endif

return lOk
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Saving bitmap from TXImage.
Posted: Sat Feb 20, 2016 09:06 AM

How do you rotate it ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Saving bitmap from TXImage.
Posted: Sat Feb 20, 2016 09:39 AM

I rotate bitmap in TXImage. How I can save result to file ?

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Saving bitmap from TXImage.
Posted: Sat Feb 20, 2016 10:45 AM

Rotation:
a) Mouse: Shift-MouseWheel
b) Touch: Rotate gesture by fingers
Zoom/Unzoom:
a) Mouse: MouseWheel
b) Touch: Zoom and Pinch gestures with fingers
Pan
(a) Mouse: Mouse drag
(b) Touch: Move with finger

The image that is loaded itself is never modified. The rotation or zoom/unzoom are only visual (in the recent versions) and that helped high performance.

If you want to save a rotated image of a png, we shall soon post a sample here.

Regards



G. N. Rao.

Hyderabad, India
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Saving bitmap from TXImage.
Posted: Sat Feb 20, 2016 11:57 AM

Thank you.
How then is it possible to load bitmap into memory. Rotate it and save it to a file ?

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Saving bitmap from TXImage.
Posted: Sat Feb 20, 2016 05:57 PM
This is an example code for rotating an image by 90,180,270 degrees clock-wise:
Code (fw): Select all Collapse
   oImage   := GdiBmp():New( "oldfile.png" )
   oImage:Rotate( nRotate )
   oImage:Save( "newfile.png" )
   oImage:End()

Values of nRotate
1 for 90 deg
2 for 180 deg
3 for 270 deg

Important note:
The above constants of nRotate are the correct values. But just now while testing the above program, I noticed a bug in the C++ function. We shall fix the bug in the next version.
But with this bug the following values of nRotate give the desired results. You may use these values till next version:

3 for 90 deg
4 for 180 deg
2 for 270 deg
Regards



G. N. Rao.

Hyderabad, India
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Saving bitmap from TXImage.
Posted: Sat Feb 20, 2016 08:19 PM

Mr.Rao, thank for your help !!

Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
Re: Saving bitmap from TXImage.
Posted: Sun Feb 21, 2016 09:02 AM

Hi Mr. Rao,

What file types supports GDIBmp class other than PNG?

Regards,



Hakan ONEMLI



Harbour & MSVC 2022 & FWH 23.06
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Saving bitmap from TXImage.
Posted: Sun Feb 21, 2016 09:23 AM

bmp,jpg,tif,emf,wmf,ico

Regards



G. N. Rao.

Hyderabad, India
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: Saving bitmap from TXImage.
Posted: Mon Feb 22, 2016 09:33 AM

And gif. But please note that saving gifs still gives a poor quality result.

EMG

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Saving bitmap from TXImage.
Posted: Mon Feb 22, 2016 03:19 PM

Nages,

May I suggest just using the degrees themselves (90,180,270) for the rotation rather than a code (1,2,3)? This would be easier to remember.

Actually, would it be possible to rotate in degree increments( e.g. 92 degrees)? This would help de-skew crooked scans, etc..

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Saving bitmap from TXImage.
Posted: Mon Feb 22, 2016 03:48 PM
James Bott wrote:Nages,

May I suggest just using the degrees themselves (90,180,270) for the rotation rather than a code (1,2,3)? This would be easier to remember.
James


This is what is in my mind too.

James Bott wrote:Nages,
Actually, would it be possible to rotate in degree increments( e.g. 92 degrees)? This would help de-skew crooked scans, etc..
James


The present function is only a wrapper to the gdi+ function, which allows only rotation in multiples of 90 deg with option to flip the image. I am planning to provide rotation by any angle in the coming versions.

As of now this is an option. Ximage provides for rotation by any angle. But this is visual only and the image itself is not rotated. What can be done now is to use ximage, rotate by the required angle and then save the control as bitmap with oImage:SaveToBmp( <filename> )
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Saving bitmap from TXImage.
Posted: Mon Feb 22, 2016 06:03 PM

Latest information:
As you all may be knowing, tgdiplus.prg and gdiplus.cpp are contributed by our gdi+ expert Mr Manuel Alwarez.
Just now we received his latest update which provides for a new method ImageRotate( nDegrees, lAdjust ). So now it is possible to reotate the image by any angle and save. This will be available from the next release.

Regards



G. N. Rao.

Hyderabad, India
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Saving bitmap from TXImage.
Posted: Mon Feb 22, 2016 07:29 PM

Awsome.

Thanks for looking into it.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10

Continue the discussion