0,0 Position color 
Author Message
 0,0 Position color

I need to know what the first color is in a picture that has been loaded
with the LoadPicture function in VB.  This way, I can set the background
transparency to that color.  This picture is being loaded into an imagelist
which then uses it's Draw method to display the image in a Picture control.

Thanks!

Mythran



Sat, 05 Feb 2005 05:42:31 GMT  
 0,0 Position color
Check out the Point(x/y) method... which returns the color of the specified
pixel

--
Ken Halter - MS-MVP-VB - Please keep it in the groups..
http://www.vbsight.com - http://www.vbsight.com/MultiColumn.htm
New Tabbed Dialog http://www.vbsight.com/TBGDialogCTL.htm


Quote:
> I need to know what the first color is in a picture that has been
> loaded with the LoadPicture function in VB.  This way, I can set the
> background transparency to that color.  This picture is being loaded
> into an imagelist which then uses it's Draw method to display the
> image in a Picture control.

> Thanks!

> Mythran



Sat, 05 Feb 2005 06:05:52 GMT  
 0,0 Position color


Quote:
> Check out the Point(x/y) method... which returns the color of the
specified
> pixel

> --
> Ken Halter - MS-MVP-VB - Please keep it in the groups..
> http://www.vbsight.com - http://www.vbsight.com/MultiColumn.htm
> New Tabbed Dialog http://www.vbsight.com/TBGDialogCTL.htm



> > I need to know what the first color is in a picture that has been
> > loaded with the LoadPicture function in VB.  This way, I can set the
> > background transparency to that color.  This picture is being loaded
> > into an imagelist which then uses it's Draw method to display the
> > image in a Picture control.

> > Thanks!

> > Mythran

Umm, I don't think Point will work.  This is because I use the ImageList
control.  The ImageList control doesn't print the picture onto the screen.
Well, it does...but I need the color of 0,0 BEFORE I print the image to the
Picture control which displays the image....get what I mean???

Mythran



Sat, 05 Feb 2005 07:14:31 GMT  
 0,0 Position color

Quote:
> Umm, I don't think Point will work.  This is because I use the ImageList
> control.  The ImageList control doesn't print the picture onto the screen.

Two options:

- Print it onto an offscreen picturebox and use Point on that
- Select the bitmap into a memory hDC and use the GetPixel API

Unless you have loads of images to print at the same time, the performance
hit shouldn't be too great...

--
Ben Baird
Visual Basic Thunder
http://www.vbthunder.com



Sat, 05 Feb 2005 08:09:32 GMT  
 0,0 Position color


Quote:


> > Umm, I don't think Point will work.  This is because I use the ImageList
> > control.  The ImageList control doesn't print the picture onto the
screen.

> Two options:

> - Print it onto an offscreen picturebox and use Point on that
> - Select the bitmap into a memory hDC and use the GetPixel API

> Unless you have loads of images to print at the same time, the performance
> hit shouldn't be too great...

> --

Well, I have thousands of images that need to be displayed :)  So the
performance hit will be too great...

These images actually are in separate directories...some lists may have one
or two images, while others have hundreds of images...right now, it takes
approximately 15-20 seconds to list all of the images for the latter....

Mythran



Sun, 06 Feb 2005 01:31:38 GMT  
 0,0 Position color

Quote:
> Well, I have thousands of images that need to be displayed :)

Daaaanng!

Quote:
> These images actually are in separate directories...some lists may have
one
> or two images, while others have hundreds of images...right now, it takes
> approximately 15-20 seconds to list all of the images for the latter....

Well, you don't actually have enough screen space to list hundreds of images
at the same time, do you? That wouldn't work, even if you were using
thumbnails, unless they were only a few square pixels :-) So you might want
to scratch loading them all at once, and only load the ones that are visible
(with perhaps a buffer of a row or two) at the time. Load more as needed
(i.e., as the user is scrolling through them, etc.). That's assuming your UI
can accommodate that of course, and I don't know what it looks like.

--
Ben Baird
Visual Basic Thunder
http://www.vbthunder.com



Sun, 06 Feb 2005 01:53:22 GMT  
 0,0 Position color


Quote:


> > Well, I have thousands of images that need to be displayed :)

> Daaaanng!

> > These images actually are in separate directories...some lists may have
> one
> > or two images, while others have hundreds of images...right now, it
takes
> > approximately 15-20 seconds to list all of the images for the latter....

> Well, you don't actually have enough screen space to list hundreds of
images
> at the same time, do you? That wouldn't work, even if you were using
> thumbnails, unless they were only a few square pixels :-) So you might
want
> to scratch loading them all at once, and only load the ones that are
visible
> (with perhaps a buffer of a row or two) at the time. Load more as needed
> (i.e., as the user is scrolling through them, etc.). That's assuming your
UI
> can accommodate that of course, and I don't know what it looks like.

> --
> Ben Baird
> Visual Basic Thunder
> http://www.vbthunder.com

The vast majority of the images are 16x16 px....some are 32x32....these
images are pre-icon images used for icons in our applications.  The
application I am developing lists all images in a specified directory, they
list ALL images at once, regardless of how many or few.  This is the
requirement... :(  Anywho, it is scrollable, so listing all at once is
ok....and it doesn't take up too much memory at any one time....it is
cancellable but still viewable so the images quit loading if the developer
presses the ESC key, and it will continue if the user presses the space key.
So, loading isn't quite that expensive...but I still need to find some way
to grab the 1x1 pixel color for each image to determine the background
transparency color...since some are red, white, green, blue, violet, grey,
et cetera....

Mythran



Sun, 06 Feb 2005 04:02:54 GMT  
 0,0 Position color
Hi,

I didn't see the previous posts on this thread, but can you use the
LoadImage API along with the LR_LOADTRANSPARENT flag?

"Retrieves the color value of the first pixel in the image and replaces the
corresponding entry in the color table with the default window color
(COLOR_WINDOW). All pixels in the image that use that entry become the
default window color. This value applies only to images that have
corresponding color tables."

David
lilchips.com


Quote:





> > > Well, I have thousands of images that need to be displayed :)

> > Daaaanng!

> > > These images actually are in separate directories...some lists may
have
> > one
> > > or two images, while others have hundreds of images...right now, it
> takes
> > > approximately 15-20 seconds to list all of the images for the
latter....

> > Well, you don't actually have enough screen space to list hundreds of
> images
> > at the same time, do you? That wouldn't work, even if you were using
> > thumbnails, unless they were only a few square pixels :-) So you might
> want
> > to scratch loading them all at once, and only load the ones that are
> visible
> > (with perhaps a buffer of a row or two) at the time. Load more as needed
> > (i.e., as the user is scrolling through them, etc.). That's assuming
your
> UI
> > can accommodate that of course, and I don't know what it looks like.

> > --
> > Ben Baird
> > Visual Basic Thunder
> > http://www.vbthunder.com

> The vast majority of the images are 16x16 px....some are 32x32....these
> images are pre-icon images used for icons in our applications.  The
> application I am developing lists all images in a specified directory,
they
> list ALL images at once, regardless of how many or few.  This is the
> requirement... :(  Anywho, it is scrollable, so listing all at once is
> ok....and it doesn't take up too much memory at any one time....it is
> cancellable but still viewable so the images quit loading if the developer
> presses the ESC key, and it will continue if the user presses the space
key.
> So, loading isn't quite that expensive...but I still need to find some way
> to grab the 1x1 pixel color for each image to determine the background
> transparency color...since some are red, white, green, blue, violet, grey,
> et cetera....

> Mythran



Sun, 06 Feb 2005 04:21:12 GMT  
 0,0 Position color


Quote:
>Umm, I don't think Point will work.  This is because I use the ImageList
>control.  The ImageList control doesn't print the picture onto the screen.
>Well, it does...but I need the color of 0,0 BEFORE I print the image to the
>Picture control which displays the image....get what I mean???

I take it you mean the 0,0 pixel as the top - left pixel which you could
get like this:

  Dim lret As Long
  Dim quadarray() As RGBQUAD
  Dim wid As Long, hgt As Long
  Dim bmapinfo As BITMAPINFO
  Dim pixel00Color As Long
  Dim itemnum As Long

  wid = ImageList1.ImageWidth
  hgt = ImageList1.ImageHeight

  ReDim quadarray(1 To wid, 1 To hgt)

  With bmapinfo.bmiHeader
    .biSize = 40
    .biWidth = wid
    .biHeight = hgt
    .biPlanes = 1
    .biBitCount = 32
    .biCompression = BI_RGB
  End With

  itemnum = 1
  lret = GetDIBits(Me.hDC, _
                ImageList1.ListImages.Item(itemnum).Picture, _
                0, hgt, quadarray(1, 1), bmapinfo, DIB_RGB_COLORS)
  CopyMemory pixel00Color, quadarray(1, hgt), 4

  itemnum = 2
  lret = GetDIBits(Me.hDC, _
                ImageList1.ListImages.Item(itemnum).Picture, _
                0, hgt, quadarray(1, 1), bmapinfo, DIB_RGB_COLORS)
  CopyMemory pixel00Color, quadarray(1, hgt), 4

--
Richard Mason



Sun, 06 Feb 2005 17:27:36 GMT  
 0,0 Position color


Quote:


> >Umm, I don't think Point will work.  This is because I use the ImageList
> >control.  The ImageList control doesn't print the picture onto the
screen.
> >Well, it does...but I need the color of 0,0 BEFORE I print the image to
the
> >Picture control which displays the image....get what I mean???

> I take it you mean the 0,0 pixel as the top - left pixel which you could
> get like this:

>   Dim lret As Long
>   Dim quadarray() As RGBQUAD
>   Dim wid As Long, hgt As Long
>   Dim bmapinfo As BITMAPINFO
>   Dim pixel00Color As Long
>   Dim itemnum As Long

>   wid = ImageList1.ImageWidth
>   hgt = ImageList1.ImageHeight

>   ReDim quadarray(1 To wid, 1 To hgt)

>   With bmapinfo.bmiHeader
>     .biSize = 40
>     .biWidth = wid
>     .biHeight = hgt
>     .biPlanes = 1
>     .biBitCount = 32
>     .biCompression = BI_RGB
>   End With

>   itemnum = 1
>   lret = GetDIBits(Me.hDC, _
>                 ImageList1.ListImages.Item(itemnum).Picture, _
>                 0, hgt, quadarray(1, 1), bmapinfo, DIB_RGB_COLORS)
>   CopyMemory pixel00Color, quadarray(1, hgt), 4

>   itemnum = 2
>   lret = GetDIBits(Me.hDC, _
>                 ImageList1.ListImages.Item(itemnum).Picture, _
>                 0, hgt, quadarray(1, 1), bmapinfo, DIB_RGB_COLORS)
>   CopyMemory pixel00Color, quadarray(1, hgt), 4

> --
> Richard Mason

I customized the code you made, AND IT WORKS!!!!  OMG!

Anywho, is there any memory allocation that needs to be freed after using
it?  I have the following function now...(you may recognise it...)

Public Function GetFirstPixel(p_lngHDC As Long, ByRef p_objPicture As
Picture, p_intHeight As Long, p_intWidth As Long)
  Dim qudArray() As RGBQUAD
  Dim typBitmap As BITMAPINFO
  Dim lngReturn As Long
  Dim lngItem As Long
  Dim lngPixelColor As Long

  ReDim qudArray(1 To p_intWidth, 1 To p_intHeight)

  With typBitmap.bmiHeader
    .biSize = 40
    .biWidth = p_intWidth
    .biHeight = p_intHeight
    .biPlanes = 1
    .biBitCount = 32
    .biCompression = BI_RGB
  End With

  lngReturn = GetDIBits(p_lngHDC, p_objPicture, 0, p_intHeight, qudArray(1,
1), typBitmap, DIB_RGB_COLORS)
  CopyMemory lngPixelColor, qudArray(1, p_intHeight), 4
  GetFirstPixel = Hex(lngPixelColor)
End Function

Now, in this function, before we end the function...does anything need to be
destroyed or freed?

Thanks...

Mythran



Sun, 06 Feb 2005 23:49:21 GMT  
 0,0 Position color
"Mythran" ,

Quote:
> Now, in this function, before we end the function...does anything need to be
> destroyed or freed?

You should be fine.  You are allocating the buffer as a VB array ( Dim
qudArray() As RGBQUAD ) so VB will clean up for you automatically.  The
"CopyMemory" aliased APIs are just copying things to VB declared variables.  You
don't need to do anything fancy to clean up.

-Ray Mercer

Quote:
> Public Function GetFirstPixel(p_lngHDC As Long, ByRef p_objPicture As
> Picture, p_intHeight As Long, p_intWidth As Long)
>   Dim qudArray() As RGBQUAD
>   Dim typBitmap As BITMAPINFO
>   Dim lngReturn As Long
>   Dim lngItem As Long
>   Dim lngPixelColor As Long

>   ReDim qudArray(1 To p_intWidth, 1 To p_intHeight)

>   With typBitmap.bmiHeader
>     .biSize = 40
>     .biWidth = p_intWidth
>     .biHeight = p_intHeight
>     .biPlanes = 1
>     .biBitCount = 32
>     .biCompression = BI_RGB
>   End With

>   lngReturn = GetDIBits(p_lngHDC, p_objPicture, 0, p_intHeight, qudArray(1,
> 1), typBitmap, DIB_RGB_COLORS)
>   CopyMemory lngPixelColor, qudArray(1, p_intHeight), 4
>   GetFirstPixel = Hex(lngPixelColor)
> End Function



Mon, 07 Feb 2005 09:57:23 GMT  
 0,0 Position color


Quote:
>Now, in this function, before we end the function...does anything need to be
>destroyed or freed?

No.

Glad it helped.

--
Richard Mason



Mon, 07 Feb 2005 04:56:51 GMT  
 0,0 Position color
Thanks alot guys...it really helped!  ALthough, the overhead is a little
steep (the time it takes to load 1000 images is about 20-30 seconds) but
hey, it works and is probably as fast as it will be for now...the must be
some other way for me to load the images instead of loading them through the
ImageList control...hmmm

Mythran



Mon, 07 Feb 2005 23:17:29 GMT  
 
 [ 13 post ] 

 Relevant Pages 

1. 0,0 Position color

2. Form Caption Position And Color

3. A different color for a highligted position in the ListBox

4. bitmap pixel position and color?

5. graphics: pset position <> .circle positions

6. HOT POSITION: Visual Basic, NT, SQL Server (3 positions)

7. HOT POSITION: Visual Basic, NT, SQL Server (3 positions)

8. HOT POSITION: Visual Basic, NT, SQL Server (3 positions)

9. Using a Custom color from the color palette.

10. Color codes for the colors of the American flag

11. Maximum colors in document colors pallete reached?

12. ??desktop color/application color??

 

 
Powered by phpBB® Forum Software