saving_20a_20jpeg_20image
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
saving_20a_20jpeg_20image [2018/03/31 13:19] – external edit 127.0.0.1 | saving_20a_20jpeg_20image [2024/01/05 00:21] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
=====Saving a JPEG image===== | =====Saving a JPEG image===== | ||
- | //by Richard Russell, December 2006//\\ \\ The main BBC BASIC for Windows documentation explains how to [[http:// | + | //by Richard Russell, December 2006//\\ \\ The main BBC BASIC for Windows documentation explains how to [[http:// |
+ | |||
+ | <code bb4w> | ||
bmpfile$ = " | bmpfile$ = " | ||
SYS " | SYS " | ||
- | Here the image is loaded at its original size. You can alternatively scale the image to different dimensions:\\ \\ | + | </ |
+ | |||
+ | Here the image is loaded at its original size. You can alternatively scale the image to different dimensions: | ||
+ | |||
+ | <code bb4w> | ||
bmpfile$ = " | bmpfile$ = " | ||
SYS " | SYS " | ||
- | Where **dx%** and **dy%** are the wanted width and height of the image respectively (the scaling quality is not particularly good so for best results you might prefer to scale the image using a third-party program).\\ \\ There are a number of other ways in which you might obtain a bitmap handle, which are outside the scope of this article. You can easily obtain a handle to whatever is displayed in your program' | + | </ |
+ | |||
+ | Where **dx%** and **dy%** are the wanted width and height of the image respectively (the scaling quality is not particularly good so for best results you might prefer to scale the image using a third-party program).\\ \\ There are a number of other ways in which you might obtain a bitmap handle, which are outside the scope of this article. You can easily obtain a handle to whatever is displayed in your program' | ||
+ | |||
+ | <code bb4w> | ||
SYS " | SYS " | ||
- | but this ordinarily returns the //entire// 1920 x 1440 bitmap which is probably not what you want. To save just a region of your program' | + | </ |
+ | |||
+ | but this ordinarily returns the //entire// 1920 x 1440 bitmap which is probably not what you want. To save just a region of your program' | ||
+ | |||
+ | <code bb4w> | ||
PROCsavejpeg(hbitmap%, | PROCsavejpeg(hbitmap%, | ||
- | Here **filename$** is the name of the JPEG file to create and **quality%** is a measure of relative quality from 1 (bad) to 100 (good). The better the quality the larger the file that will be created.\\ \\ One you've saved the file you should delete the bitmap handle:\\ \\ | + | </ |
+ | |||
+ | Here **filename$** is the name of the JPEG file to create and **quality%** is a measure of relative quality from 1 (bad) to 100 (good). The better the quality the larger the file that will be created.\\ \\ One you've saved the file you should delete the bitmap handle: | ||
+ | |||
+ | <code bb4w> | ||
SYS " | SYS " | ||
- | Finally, here's the code for **PROCsavejpeg** itself:\\ \\ | + | </ |
+ | |||
+ | Finally, here's the code for **PROCsavejpeg** itself: | ||
+ | |||
+ | <code bb4w> | ||
DEF PROCsavejpeg(hbitmap%, | DEF PROCsavejpeg(hbitmap%, | ||
LOCAL gdiplus%, ole32% | LOCAL gdiplus%, ole32% | ||
Line 68: | Line 90: | ||
ENDPROC | ENDPROC | ||
- | \\ | + | </ |
+ | |||
+ | |||
+ | If, instead of a bitmap **handle**, you have a bitmap (DIB) stored in memory you can use this alternative routine: | ||
+ | |||
+ | <code bb4w> | ||
DEF PROCsavejpegdib(dib%, | DEF PROCsavejpegdib(dib%, | ||
LOCAL gdiplus%, ole32% | LOCAL gdiplus%, ole32% | ||
Line 123: | Line 150: | ||
ENDPROC | ENDPROC | ||
- | \\ | + | </ |
+ | |||
+ | You would call it as follows: | ||
+ | |||
+ | <code bb4w> | ||
PROCsavejpegdib(dibits%, | PROCsavejpegdib(dibits%, | ||
+ | </ | ||
+ | |||
where **dibits%** is the address of the bitmap data and **bmi{}** is a BITMAPINFO structure containing the dimensions etc. and (optionally) colour palette for the bitmap. | where **dibits%** is the address of the bitmap data and **bmi{}** is a BITMAPINFO structure containing the dimensions etc. and (optionally) colour palette for the bitmap. |
saving_20a_20jpeg_20image.1522502378.txt.gz · Last modified: 2024/01/05 00:16 (external edit)