HPDFPRINT IMAGE Image cannot be loaded

Moderator: Rathinagiri

User avatar
mustafa
Posts: 1032
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Been thanked: 234 times
Contact:

Re: HPDFPRINT IMAGE Image cannot be loaded

Post by mustafa »

Hello Franco:
For me it is a serious problem not to understand English
I'm translating with Google and I can't interpret
your writing sorry

My Sample is based on seeing the image with "camera.swf "
and then how the image is not saved correctly
due to lack of compression and resolution

I take a screenshot of the frame area
Where is the image

If you want to expand your Sample, please send
the Full Code in prg
Regards
Mustafa

franco
Posts: 478
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Been thanked: 19 times

Post by franco »

Hello Mustafa,
I modified the previous post. I have it sort of figured out.
I am just in the process of moving the capture to the left top of the screen, because my clients have touch screen tablets and
while taking a picture they just touch button with ther thumb.
Also trying to get rid of black lines on top and bottom, I thonk created by swf capture.
All the Best,
Franco.
All The Best,
Franco
Canada

franco
Posts: 478
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Been thanked: 19 times

Post by franco »

Auge_ore and Mustafa,
Auge that command works I am in process of testing.
Mustafa, I have a new simple version of your last post. I will replace my original with our new one.
All the Best,
Franco
All The Best,
Franco
Canada

User avatar
mustafa
Posts: 1032
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Been thanked: 234 times
Contact:

Post by mustafa »

Hola Franco
Espero que te funcione
Saludos
Mustafa

franco
Posts: 478
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Been thanked: 19 times

Post by franco »

Found something while testing
If I take a picture with the internal hmg camera to .jpg will not print to pdf. And open the picture file with notepad, they start is BMÎ( 6 (
If I open a picture that is taken with a real camera or windows camera they will print to pdf. The start in notepad is ÿØÿà JFIF ` `
I wonder what the BM at start means, Do you think the hmg picture is a bitmap and can be converted to a real jpg picture that can be printed to pdf.
All The Best,
Franco
Canada

edk
Posts: 617
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 150 times
Been thanked: 552 times

Post by edk »

BM indicates that's a bitmap (bmp), not jpg file. Just try to add image as bmp into pdf.
Or try to convert into jpg:

Code: Select all

#include "BosTaurus.CH"

BT_BitmapSaveFile ( ( hBitmap:=BT_BitmapLoadFile (cBmpFileName) )  , cJpgFileName, BT_FILEFORMAT_JPG )
BT_BitmapRelease (hBitmap)
Note: this code was not tested, I wrote it from my mind.

franco
Posts: 478
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Been thanked: 19 times

Post by franco »

edk, thank you, thank you, THANK YOU,
I have been looking for this for 2 months.
Mustafa this is what we where looking for.
Instead of CAMFORM.CAPTURE('TEST.JPG',15,7,300,230) in hmg camera
We now use CAMFORM.CAPTURE('TEST.BMP',15,7,300,230) BECAUSE IT IS A BITMAP.
Then add edk suggestion

BT_BitmapSaveFile ( ( hBitmap:=BT_BitmapLoadFile ("test.bmp") ) , "test.jpg", BT_FILEFORMAT_JPG )
BT_BitmapRelease (hBitmap
This will print to pdf.

I am still working on the windows 10 camera as it is much clearer, and does not have the black lines around the picture.
Thanks to all,
All The Best,
Franco
Canada

franco
Posts: 478
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Been thanked: 19 times

Post by franco »

New problem
After taking a picture in hmg which even though its name is jpg but it is a bitmap.
BT_BitmapSaveFile ( ( hBitmap:=BT_BitmapLoadFile ("test.bmp") ) , "test.jpg", BT_FILEFORMAT_JPG )
BT_BitmapRelease (hBitmap)
This works fine, BUT a 100 kb bp file becomes a 6 kb jpeg file, which becomes a poor quality picture.
Am I doing something wrong. If so this could be easy fix.


I can use:
BT_BitmapSaveFile ( ( hBitmap:=BT_BitmapLoadFile ("test.bmp") ) , "test.jpg", BT_FILEFORMAT_PNG )
BT_BitmapRelease (hBitmap)
This becomes a png file that is still 100 kb with name .JPG. This still works throughout my program except when I want to print it.
I set print image type by the name which is jpg because I also use other cameras to take pictures which are real jpg files.

IS THERE A PROCEDURE TO CHECK THE FILE BEFORE PRINTING TO SEE IF IT IS A PNG OR JPG. LIKE:
IF FILETYPE(JPG) OR FORMAT(PNG) , WHICH WOULD CHECK THE FILE NOT BY NAME OR EXTENTION.
I can use Fopen and Fread but do not like to low level open and close files (Can create problems)

Thanks in advance,
All The Best,
Franco
Canada

edk
Posts: 617
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 150 times
Been thanked: 552 times

Post by edk »

franco wrote:
Fri Jan 17, 2020 6:21 pm
New problem
After taking a picture in hmg which even though its name is jpg but it is a bitmap.
BT_BitmapSaveFile ( ( hBitmap:=BT_BitmapLoadFile ("test.bmp") ) , "test.jpg", BT_FILEFORMAT_JPG )
BT_BitmapRelease (hBitmap)
This works fine, BUT a 100 kb bp file becomes a 6 kb jpeg file, which becomes a poor quality picture.
IMHO print quality is poor because of
franco wrote:
Tue Jan 14, 2020 1:50 am
CAMFORM.CAPTURE('TEST.BMP',15,7,300,230)
This will capture part of screen with 72 or 96 DPI
I am so sorry, I can't help you. I don't have any PC camera and I don't want to have it 😉

edk
Posts: 617
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 150 times
Been thanked: 552 times

Post by edk »

franco wrote:
Fri Jan 17, 2020 6:21 pm
IS THERE A PROCEDURE TO CHECK THE FILE BEFORE PRINTING TO SEE IF IT IS A PNG OR JPG.
Try to replace the _HMG_HPDF_IMAGE function in the h_HMG_HPDF.Prg file and then rebuild the HMG using the BuildLib32.bat batch file

Code: Select all

Function _HMG_HPDF_IMAGE ( cImage, nRow, nCol, nImageheight, nImageWidth, lStretch , cImageType)
Local nWidth := _HMG_SYSDATA[ 150 ][ 4 ]
Local nHeight := _HMG_SYSDATA[ 150 ][ 5 ]
Local nxPos := _HMG_HPDF_MM2Pixel( nCol )
Local nyPos := nHeight - _HMG_HPDF_MM2Pixel( nRow )
Local oImage := Nil
default lStretch := .f.
default cImageType := "AUTO"

If _HMG_SYSDATA[ 150 ][ 1 ] == Nil // PDF object not found!
   _HMG_HPDF_Error( 3 )
   Return Nil
endif
If _HMG_SYSDATA[ 150 ][ 7 ] == Nil // PDF Page object not found!
   _HMG_HPDF_Error( 5 )
   Return Nil
endif

do case
   case HMG_UPPER( alltrim( cImageType ) ) = "PNG"
      oImage := _HPDF_LOAD_PNG (_HMG_SYSDATA[ 150 ][ 1 ], cImage)
   case HMG_UPPER( alltrim( cImageType ) ) = "JPG"
      oImage := _HPDF_LOAD_JPG (_HMG_SYSDATA[ 150 ][ 1 ], cImage)
   case HMG_UPPER( alltrim( cImageType ) ) = "AUTO"
      oImage := _HPDF_LOAD_PNG (_HMG_SYSDATA[ 150 ][ 1 ], cImage)
	  IF oImage = Nil .OR. Empty ( oImage )
	      HPDF_ResetError( _HMG_SYSDATA[ 150 ][ 1 ] )
	      oImage := _HPDF_LOAD_JPG (_HMG_SYSDATA[ 150 ][ 1 ], cImage)
	  ENDIF
   otherwise
       _HMG_HPDF_Error( 20 )
endcase    

If oImage = Nil  
   _HMG_HPDF_Error( 7 )
   HPDF_ResetError( _HMG_SYSDATA[ 150 ][ 1 ] )
   Return Nil
endIf   

If empty( oImage ) 
   _HMG_HPDF_Error( 7 )
   HPDF_ResetError( _HMG_SYSDATA[ 150 ][ 1 ] )
   Return Nil
endIf   
HPDF_Page_DrawImage( _HMG_SYSDATA[ 150 ][ 7 ], oImage, nxPos, nyPos - _HMG_HPDF_MM2Pixel( nImageHeight ), _HMG_HPDF_MM2Pixel( nImageWidth ), _HMG_HPDF_MM2Pixel( nImageHeight ) )
Return Nil
If you do not declare the image type (jpg / png) when creating a PDF file then the new function will try to open the image file as png first, and if it fails then as jpg. The correct file name extension is not important, it is important that it is a valid png or jpg file.

E.g. @ 126, 10 HPDFPRINT IMAGE "hmghpdf.valid_png_or_jpg" WIDTH 190 HEIGHT 46

Post Reply