save bmp in same depth as loaded bmp 
Author Message
 save bmp in same depth as loaded bmp

I am using the following code to load a 4bit (16 color) bitmap image. I am
not normally a graphics programmer but I think I understand the following
code. When I get the BITMAP structure, the BMP.bmBitsPixel seems to match my
screen solor resolution regardless of the image color resolution. All I want
to do is draw some text on top of the bitmap image in the device context,
which I can do OK, but I would like to output the image in the same
resolution that it was to begin with. Any ideas on how to do this? If the
input image is 4 bit, then I want to load it, draw some text on it, and save
it again as 4 bit (same with 8 bit...etc... not dependent on screen
resolution) This part kind of stumps me...any help or sample code is very
much appreciated.

    ' load the bmp, get handle
    Dim hBmp As Long
    hBmp = LoadImage(0, "c:\temp\stone.bmp", IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE Or LR_DEFAULTSIZE)
    Debug.Print "hBmp:", hBmp

    ' create dc
    Dim hDC As Long
    hDC = CreateCompatibleDC(0)
    Debug.Print "hDC:", hDC

    ' select bmp into dc
    Dim hBmp0
    hBmp0 = SelectObject(hDC, hBmp)

    ' get some bitmap information
    Dim BMP As BITMAP
    GetObjectAPI hBmp, Len(BMP), BMP
    Debug.Print BMP.bmWidth & "x" & BMP.bmHeight, BMP.bmBitsPixel,
BMP.bmWidthBytes

   ....draw some text in the hDC (code intentionally left out)
   ....save image in original format (this is the stumper)

    SelectObject hDC, hBmp0
    DeleteObject hDC

(please not this is done using only API's in a module, there will be no form
components to use; and speed and memory are important factors)



Mon, 07 Feb 2005 20:46:43 GMT  
 save bmp in same depth as loaded bmp


Quote:
>I am using the following code to load a 4bit (16 color) bitmap image. I am
>not normally a graphics programmer but I think I understand the following
>code. When I get the BITMAP structure, the BMP.bmBitsPixel seems to match my
>screen solor resolution regardless of the image color resolution. All I want
>to do is draw some text on top of the bitmap image in the device context,
>which I can do OK, but I would like to output the image in the same
>resolution that it was to begin with. Any ideas on how to do this? If the
>input image is 4 bit, then I want to load it, draw some text on it, and save
>it again as 4 bit (same with 8 bit...etc... not dependent on screen
>resolution) This part kind of stumps me...any help or sample code is very
>much appreciated.

>    ' load the bmp, get handle
>    Dim hBmp As Long
>    hBmp = LoadImage(0, "c:\temp\stone.bmp", IMAGE_BITMAP, 0, 0,
>LR_LOADFROMFILE Or LR_DEFAULTSIZE)

Use LR_LOADFROMFILE Or LR_CREATEDIBSECTION and it won't get mapped to
the screen bitdepth.
As cxDesired,cyDesired are specified as 0,0 the LR_DEFAULTSIZE is not
required and the image will load at its actual width/height.

--
Richard Mason



Mon, 07 Feb 2005 21:25:07 GMT  
 save bmp in same depth as loaded bmp
That did the trick, I am not exactly sure what a DIBSECTION is but that is
exactly what I was missing.
Thankyou very much.


Quote:


> >I am using the following code to load a 4bit (16 color) bitmap image. I
am
> >not normally a graphics programmer but I think I understand the following
> >code. When I get the BITMAP structure, the BMP.bmBitsPixel seems to match
my
> >screen solor resolution regardless of the image color resolution. All I
want
> >to do is draw some text on top of the bitmap image in the device context,
> >which I can do OK, but I would like to output the image in the same
> >resolution that it was to begin with. Any ideas on how to do this? If the
> >input image is 4 bit, then I want to load it, draw some text on it, and
save
> >it again as 4 bit (same with 8 bit...etc... not dependent on screen
> >resolution) This part kind of stumps me...any help or sample code is very
> >much appreciated.

> >    ' load the bmp, get handle
> >    Dim hBmp As Long
> >    hBmp = LoadImage(0, "c:\temp\stone.bmp", IMAGE_BITMAP, 0, 0,
> >LR_LOADFROMFILE Or LR_DEFAULTSIZE)

> Use LR_LOADFROMFILE Or LR_CREATEDIBSECTION and it won't get mapped to
> the screen bitdepth.
> As cxDesired,cyDesired are specified as 0,0 the LR_DEFAULTSIZE is not
> required and the image will load at its actual width/height.

> --
> Richard Mason



Mon, 07 Feb 2005 22:31:45 GMT  
 save bmp in same depth as loaded bmp
Hello ,

I recommend you the Open and Save Dialogs Toolkit from:
http://www.fcoder.com/products/osdialog.htm

Regards,
Mikhael


Quote:
> I am using the following code to load a 4bit (16 color) bitmap image. I am
> not normally a graphics programmer but I think I understand the following
> code. When I get the BITMAP structure, the BMP.bmBitsPixel seems to match
my
> screen solor resolution regardless of the image color resolution. All I
want
> to do is draw some text on top of the bitmap image in the device context,
> which I can do OK, but I would like to output the image in the same
> resolution that it was to begin with. Any ideas on how to do this? If the
> input image is 4 bit, then I want to load it, draw some text on it, and
save
> it again as 4 bit (same with 8 bit...etc... not dependent on screen
> resolution) This part kind of stumps me...any help or sample code is very
> much appreciated.

>     ' load the bmp, get handle
>     Dim hBmp As Long
>     hBmp = LoadImage(0, "c:\temp\stone.bmp", IMAGE_BITMAP, 0, 0,
> LR_LOADFROMFILE Or LR_DEFAULTSIZE)
>     Debug.Print "hBmp:", hBmp

>     ' create dc
>     Dim hDC As Long
>     hDC = CreateCompatibleDC(0)
>     Debug.Print "hDC:", hDC

>     ' select bmp into dc
>     Dim hBmp0
>     hBmp0 = SelectObject(hDC, hBmp)

>     ' get some bitmap information
>     Dim BMP As BITMAP
>     GetObjectAPI hBmp, Len(BMP), BMP
>     Debug.Print BMP.bmWidth & "x" & BMP.bmHeight, BMP.bmBitsPixel,
> BMP.bmWidthBytes

>    ....draw some text in the hDC (code intentionally left out)
>    ....save image in original format (this is the stumper)

>     SelectObject hDC, hBmp0
>     DeleteObject hDC

> (please not this is done using only API's in a module, there will be no
form
> components to use; and speed and memory are important factors)



Sun, 27 Feb 2005 21:52:01 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Saving API Drawings to a BMP or Converting from WMF to BMP

2. Saving & Loading BMP's from API

3. Need Help - Decrease BMP color depth to 256 color

4. Convert color BMP to black and white BMP

5. 24 bit BMP to 8 bit BMP

6. BMP output mapping BMP-pixel to printer-pixel 1:1

7. BMP 24-bit to BMP 1-bit converting

8. Convert 16 bit bmp to 24 bit bmp

9. Convert 24bit Bmp to 16bit BMP

10. 16 color BMP file reformat to Monochron BMP

11. Loading BMP files into OLE field in table

12. How to load BMP file in OLE field using VBA

 

 
Powered by phpBB® Forum Software