Page 1 of 1

Saving bitmap from TXImage.

PostPosted: Fri Feb 19, 2016 10:57 am
by Natter
Change bitmap in TXImage. Can I save the modified bitmap into a file ?

Re: Saving bitmap from TXImage.

PostPosted: Fri Feb 19, 2016 1:23 pm
by Natter
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: Select all  Expand view
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

Re: Saving bitmap from TXImage.

PostPosted: Sat Feb 20, 2016 9:06 am
by Antonio Linares
How do you rotate it ?

Re: Saving bitmap from TXImage.

PostPosted: Sat Feb 20, 2016 9:39 am
by Natter
I rotate bitmap in TXImage. How I can save result to file ?

Re: Saving bitmap from TXImage.

PostPosted: Sat Feb 20, 2016 10:45 am
by nageswaragunupudi
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.

Re: Saving bitmap from TXImage.

PostPosted: Sat Feb 20, 2016 11:57 am
by Natter
Thank you.
How then is it possible to load bitmap into memory. Rotate it and save it to a file ?

Re: Saving bitmap from TXImage.

PostPosted: Sat Feb 20, 2016 5:57 pm
by nageswaragunupudi
This is an example code for rotating an image by 90,180,270 degrees clock-wise:
Code: Select all  Expand view
  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

Re: Saving bitmap from TXImage.

PostPosted: Sat Feb 20, 2016 8:19 pm
by Natter
Mr.Rao, thank for your help !!

Re: Saving bitmap from TXImage.

PostPosted: Sun Feb 21, 2016 9:02 am
by Horizon
Hi Mr. Rao,

What file types supports GDIBmp class other than PNG?

Re: Saving bitmap from TXImage.

PostPosted: Sun Feb 21, 2016 9:23 am
by nageswaragunupudi
bmp,jpg,tif,emf,wmf,ico

Re: Saving bitmap from TXImage.

PostPosted: Mon Feb 22, 2016 9:33 am
by Enrico Maria Giordano
And gif. But please note that saving gifs still gives a poor quality result.

EMG

Re: Saving bitmap from TXImage.

PostPosted: Mon Feb 22, 2016 3:19 pm
by James Bott
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

Re: Saving bitmap from TXImage.

PostPosted: Mon Feb 22, 2016 3:48 pm
by nageswaragunupudi
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> )

Re: Saving bitmap from TXImage.

PostPosted: Mon Feb 22, 2016 6:03 pm
by nageswaragunupudi
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.

Re: Saving bitmap from TXImage.

PostPosted: Mon Feb 22, 2016 7:29 pm
by James Bott
Awsome.

Thanks for looking into it.

James