reduce an image to a fixed size

reduce an image to a fixed size

Postby Otto » Fri Oct 16, 2020 7:44 am

Good Morning,
Can someone please help me with some source code on how to reduce an image to a fixed size.
Many thanks in advance
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6364
Joined: Fri Oct 07, 2005 7:07 pm

Re: reduce an image to a fixed size

Postby nageswaragunupudi » Fri Oct 16, 2020 2:46 pm

ResizeBitmap( hBitmap, nWidth, nHeight ) --> hResizedBmp
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10690
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: reduce an image to a fixed size

Postby Otto » Fri Oct 16, 2020 4:48 pm

Dear Mr. Rao,
Thank you. Would you be so kind as to show me the best way to get the handle and how to save the new BMP.
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6364
Joined: Fri Oct 07, 2005 7:07 pm

Re: reduce an image to a fixed size

Postby Antonio Linares » Sat Oct 17, 2020 8:50 am

local hBmp
local hDib := DibFromBitmap( hBmp := ResizeBitmap( hBitmap, nWidth, nHeight ) )

DibWrite( cFileName, hDib )
GloBalFree( hDib )
DeleteObject( hBmp )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: reduce an image to a fixed size

Postby Otto » Sat Oct 17, 2020 12:33 pm

Dear Antonio,
Thank you.

In my case, the image is now saved with 96 dpi and a bit depth of 32. The size of the picture is
1,920 KB.

If I do the whole thing with PAINT, I get a picture that
226 KB, DPI 72, and bit depth 24.

How can I reduce the DPIs and the color depth with FIVEWIN.

Thank you in advance
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6364
Joined: Fri Oct 07, 2005 7:07 pm

Re: reduce an image to a fixed size

Postby Antonio Linares » Sat Oct 17, 2020 9:08 pm

Dear Otto,

It seems as we need to use the function SetDIBColorTable()
https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-setdibcolortable

Maybe there is a simpler way using GDI+
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: reduce an image to a fixed size

Postby Otto » Sat Oct 17, 2020 9:21 pm

Dear Antonio,

I tried with


Code: Select all  Expand view  RUN
oImage   := GdiBmp():New( "c:\fwh\samples\204.jpg" )
   oImage:Resize( nWidth, nHeight )
   oImage:Save( "newfile.jpg", nQuality )
   oImage:End()



The result is good.
Thank you and have a nice weekend.
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6364
Joined: Fri Oct 07, 2005 7:07 pm

Re: reduce an image to a fixed size

Postby Otto » Sun Oct 18, 2020 7:18 am

Hello,
Now I can resize all my images in a quick and easy batch mode for WINDOWS QR.

This is a web page I made with mod harbour.

The small images are loaded first and the large ones asynchronously.

As soon as a large picture is loaded, the small one will be replaced.
With this method, the web page loads quickly.

The contents of all stick boxes can be displayed on the PC, and then you can zoom into the boxes.
The correct box can then be found using the warehouse number.

But you can also read the QR code on the stick box with your smartphone, and then the content is displayed on the mobile phone.



Best regards,
Otto
Code: Select all  Expand view  RUN

#include "FIVEWIN.CH"

function main()
    local oImage
    local nQuality := 0
    local I  := 0
    local cPfad := "c:\bilder\"
    local aDir := directory(  cPfad +  "
*.jpg","DHS")
    local cSrc := "
"
    local nWidth := 800
    local nHeight := 600
    *----------------------------------------------------------
   
   lMKDir( cPfad + "
\klein" )
   
   for I := 1 to len( aDir )
       cSrc := aDir[I,1]
        oImage   := GdiBmp():New( cPfad + cSrc )
       oImage:Resize( nWidth, nHeight )
       
       oImage:Save( cPfad + "
\klein\" + cFileNoPath( cSrc ) , nQuality )
       oImage:End()
   next
   
   ? "
Ende"
   
return nil
//----------------------------------------------------------------------------//


Image

Image

Image

Image


Image
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6364
Joined: Fri Oct 07, 2005 7:07 pm

Re: reduce an image to a fixed size

Postby Marc Venken » Sun Oct 18, 2020 1:00 pm

Interesting !!

Will this keep a good quality of jpg's ??

I use folowing technic for my update of webshop pictures.

With Fw I select and create my menu and the products inside the menu.
Than I copy from source jpg's (all random size i got from manufacturers) to a picture folder and use nConvert with a .bat file to convert to 3 formats needed.
These 3 folders need to be uploaded with FTP to the server of the webshop.

If the pictures from Otto are Ok, then maybe I can start using his code for this. I have seen also some code to upload pic's from home to the server of the hosting company.
They gave my rights to do it with Ftp, so I think I can use it also for copy direct from FW.

Is the right ?
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1456
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: reduce an image to a fixed size

Postby Antonio Linares » Sun Oct 18, 2020 3:37 pm

Dear Otto,

many thanks for sharing your solution :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 35 guests