The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: stbfish on October 04, 2009, 12:41:25 PM

Title: Finding image on screen
Post by: stbfish on October 04, 2009, 12:41:25 PM
i got a bmp format pic.(test.bmp)  then i want to get the pic's coordinate on screen.
any dll i can use. if not, any clue to do things like this.
thanks.
Title: Re: Finding image on screen
Post by: donkey on October 04, 2009, 02:39:43 PM
How is the image displayed on the desktop ? Is it in a window or is it integrated into the desktop wallpaper ?

If its in a window it can be found by using the window handle if its on the desktop you can do a simple pattern search to find the bitmap as long as its unique.
Title: Re: Finding image on screen
Post by: stbfish on October 05, 2009, 12:05:57 AM
first screenshot(full screen), then compare with test.bmp(a small block on screen), then get the test.bmp coordinate on screen.
sorry, my english is not good.i  hope my mean is clear now. :P :P
Title: Re: Finding image on screen
Post by: dedndave on October 05, 2009, 12:32:24 AM
i think you want to know about the BMP file format
for 24-bit BMP files, there is a 54 byte header, then each pixel takes 4 bytes - B, G, R, 0<-- always 0
the left pixel of the bottom image line is first in the file
some guy at microsoft had his hat on backwards when he designed the format - lol
Title: Re: Finding image on screen
Post by: hutch-- on October 05, 2009, 01:15:00 AM
 :bg

> some guy at microsoft had his hat on backwards

Which endian ?  :P
Title: Re: Finding image on screen
Post by: dedndave on October 05, 2009, 02:30:27 AM
what endians ? - i didn't even see any arrows   :red
Title: Re: Finding image on screen
Post by: stbfish on October 05, 2009, 12:07:37 PM
Quote from: dedndave on October 05, 2009, 12:32:24 AM
i think you want to know about the BMP file format
for 24-bit BMP files, there is a 54 byte header, then each pixel takes 4 bytes - B, G, R, 0<-- always 0
the left pixel of the bottom image line is first in the file
some guy at microsoft had his hat on backwards when he designed the format - lol

2x2 Pixel, 24-Bit Bitmap
B G
R W
Hex view, the Bitmap Data show like below

0000FFFFFFFF0000FF000000FF000000

00 00 FF   0 0 255  Red, Pixel (1,0)
FF FF FF   255 255 255 White, Pixel (1,1)
00 00 0 0 Padding for 4 byte alignment (Could be a value other than zero)

3 bytes per pixel

found this on http://en.wikipedia.org/wiki/BMP_file_format

Title: Re: Finding image on screen
Post by: dedndave on October 05, 2009, 12:18:43 PM
if you want to handle a variety of BMP files, you should familiarize yourself with the header format
normally, i test the first 2 bytes to make sure it is a BMP file
then, i read the bits per pixel field so that i know how to interpret the rest of the file
the header is usually 54 bytes long, although, it can be longer (actually, they can add remarks etc.)
monochrome, 16 color, and 256 color files have a palette following the header
24 bit files need no palette, as each pixel is directly encoded
after that, you will want to know the dimensions of the image so you know how long a line is and how many there are
it is a good idea to verify the file size, as well, so that you know you have the entire image
uncompressed BMP files are probably the simplest of all graphics files to work with
Title: Re: Finding image on screen
Post by: FORTRANS on October 05, 2009, 02:03:35 PM
Hi,

Quote
the header is usually 54 bytes long, although, it can be longer

   It can be shorter as well.  Microsoft and IBM came up with the format,
and between the Windows and OS/2 versions....  And both extended
the definitions, presumably without talking to each other.

Quote
24 bit files need no palette, as each pixel is directly encoded

   But they can have one anyway.

Quote
after that, you will want to know the dimensions of the image so you know how long a line is and how many there are
it is a good idea to verify the file size, as well, so that you know you have the entire image

   And some header fields can be incorrect (one of the size fields
when it bit me).

Quote
uncompressed BMP files are probably the simplest of all graphics files to work with

   If you get them from a consistent source.  One of my favorite
image editing programs does not seem sane when creating BMP's.
Luckily 97% seem to play by the normal rules.

   The Targa TGA format is a bit simpler.  Though it too has version
and optional extensions.

   Uncompressed BMP is a good, easy start if you do some sanity
checks.  Or just use the right BMP's.

Regards,

Steve N.

P.S.  Just follow Dave's advice.  I collect images from (apparently)
bad places.

SRN
Title: Re: Finding image on screen
Post by: dedndave on October 05, 2009, 02:57:43 PM
if you do have a funky image - just load it into paint, then save it
that should straighten out the file format