News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Screenshot with small size

Started by Ar0n, November 19, 2015, 05:52:27 AM

Previous topic - Next topic

Ar0n

Hello MASM32 forum, so I am currently taking a screenshot using this method:
https://msdn.microsoft.com/en-us/library/windows/desktop/dd183402(v=vs.85).aspx

This code works just fine but there is a problem, the size of the bitmap is 4-10MB, so I'm trying to find a solution to reduce the size of the bitmap.

Does anyone know if there is a way to compress the bitmap using the WinAPI or another method of taking the screenshot with a small size?

btw, I would not want to use any third-party lib.

dedndave

you can save it as a JPG by using some COM and/or GDI Plus functions

another way to go...
you can reduce the size of the image by using StretchBlt

and - if you are saving it as a 32-bit image, it will be a little smaller as a 24-bit image
you could even drop to a 16-bit image

Vortex

Here is an example converting a bmp to jpg :

http://masm32.com/board/index.php?topic=4731.msg51075#msg51075

Ar0n

Quote from: dedndave on November 19, 2015, 05:56:54 AM
you can save it as a JPG by using some COM and/or GDI Plus functions

another way to go...
you can reduce the size of the image by using StretchBlt

and - if you are saving it as a 32-bit image, it will be a little smaller as a 24-bit image
you could even drop to a 16-bit image
Dave, yes, I have read that it is possible with GDI+ but I did not find what functions are for that. Do you k know what functions are used?

Quote from: Vortex on November 19, 2015, 06:09:47 AM
Here is an example converting a bmp to jpg :

http://masm32.com/board/index.php?topic=4731.msg51075#msg51075
Thank you Vortex, before looking at how the code works, i have a question, it is possible with your code or functions that you use to convert the image from memory since I'm sending the image via sockets so this is better for me to send it directly from memory instead of saving to a file and read it again.

dedndave

i haven't played with GDI+ that much

but, it appears that GdipSaveImageToStream might be usable for what you want
(Erol's example uses GdipSaveImageToFile - perhaps with the right parameters, the file can be memory)

https://msdn.microsoft.com/en-us/library/ms534041%28v=vs.85%29.aspx

Jose Roca's site has some examples

http://www.jose.it-berater.org/smfforum/index.php?board=277.0

Ar0n

Quote from: dedndave on November 19, 2015, 06:46:55 AM
i haven't played with GDI+ that much

but, it appears that GdipSaveImageToStream might be usable for what you want
(Erol's example uses GdipSaveImageToFile - perhaps with the right parameters, the file can be memory)

https://msdn.microsoft.com/en-us/library/ms534041%28v=vs.85%29.aspx

Jose Roca's site has some examples

http://www.jose.it-berater.org/smfforum/index.php?board=277.0
:icon_eek: wow, I did not know that forum, I think I'm going to have fun for a few hours reading all these messages.  :t

Vortex

Hi Ar0n,

The trick is to use the GdipCreateBitmapFromHBITMAP to convert a bitmap handle to a GDI+ object :

https://msdn.microsoft.com/en-us/library/windows/desktop/ms533971%28v=vs.85%29.aspx

    invoke      GdipCreateBitmapFromHBITMAP,hBmp,0,ADDR BmpImage

Attached is an example saving the desktop as a jpg image.

Ar0n

Thanks guys, I achieved my goal with your help-.