Saving bitmap from TXImage.

Post Reply
Natter
Posts: 1241
Joined: Mon May 14, 2007 9:49 am

Saving bitmap from TXImage.

Post by Natter »

Change bitmap in TXImage. Can I save the modified bitmap into a file ?
Natter
Posts: 1241
Joined: Mon May 14, 2007 9:49 am

Re: Saving bitmap from TXImage.

Post 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

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
User avatar
Antonio Linares
Site Admin
Posts: 42529
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 77 times
Contact:

Re: Saving bitmap from TXImage.

Post by Antonio Linares »

How do you rotate it ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
Natter
Posts: 1241
Joined: Mon May 14, 2007 9:49 am

Re: Saving bitmap from TXImage.

Post by Natter »

I rotate bitmap in TXImage. How I can save result to file ?
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: Saving bitmap from TXImage.

Post 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.
Regards

G. N. Rao.
Hyderabad, India
Natter
Posts: 1241
Joined: Mon May 14, 2007 9:49 am

Re: Saving bitmap from TXImage.

Post by Natter »

Thank you.
How then is it possible to load bitmap into memory. Rotate it and save it to a file ?
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: Saving bitmap from TXImage.

Post by nageswaragunupudi »

This is an example code for rotating an image by 90,180,270 degrees clock-wise:

Code: Select all | Expand

  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
Natter
Posts: 1241
Joined: Mon May 14, 2007 9:49 am

Re: Saving bitmap from TXImage.

Post by Natter »

Mr.Rao, thank for your help !!
Horizon
Posts: 1323
Joined: Fri May 23, 2008 1:33 pm
Has thanked: 4 times

Re: Saving bitmap from TXImage.

Post by Horizon »

Hi Mr. Rao,

What file types supports GDIBmp class other than PNG?
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: Saving bitmap from TXImage.

Post by nageswaragunupudi »

bmp,jpg,tif,emf,wmf,ico
Regards

G. N. Rao.
Hyderabad, India
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

Re: Saving bitmap from TXImage.

Post by Enrico Maria Giordano »

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

EMG
User avatar
James Bott
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: Saving bitmap from TXImage.

Post 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
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: Saving bitmap from TXImage.

Post 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> )
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: Saving bitmap from TXImage.

Post 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.
Regards

G. N. Rao.
Hyderabad, India
User avatar
James Bott
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: Saving bitmap from TXImage.

Post by James Bott »

Awsome.

Thanks for looking into it.

James
Post Reply