I have question, is it windows is provide some API can easy and quick to get (bmp/picture) that Pixel?
I want to get that pixel around 200-300 bmp file(s), any advice please!
Printable View
I have question, is it windows is provide some API can easy and quick to get (bmp/picture) that Pixel?
I want to get that pixel around 200-300 bmp file(s), any advice please!
GetPixel retrieves the pixel from the bitmap image's (hdc) X and Y position specified in the API and returns it's color
Public Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
I found MSDN to get more about gdi32/getpixel
http://msdn.microsoft.com/en-us/libr...amp;cs-lang=vb
but I not undetstand how to start, any simple sample tell me please!
Private Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Dim c As Long
c = GetPixel(Picture1.hdc, 0, 0)
c will contain the long color value of the upper left corner (X = 0, Y = 0) of Picture1.Picture
This is for VB6 and earlier. If you are using VB.NET you are in the wrong Forum
Judging from the screenshot, I think rpool wants to retrieve each bitmap file's image dimensions. If so, then the GetDIBits function might help achieve that.
Quote:
Originally Posted by MSDN
I am sorry, not clearly my question,
yes, I need get that bitmap.picture.dimensions (result: need use "pixel" value)
but where to start ?
please!
EDIT: Width / 26.45 and Height/26.45
but not understand why use 26.45?
Code:myPic_W = myPic.Width / 26.45 'changed to pixel
myPic_H = myPic.Height / 26.45 'changed to pixel
Code:
Option Explicit
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Sub Command1_Click()
Dim myPic As StdPicture
Dim myPic_W As Long
Dim myPic_H As Long
Form1.Picture1.ScaleMode = 3 'pixel
Form1.Picture1.AutoRedraw = True
Form1.Picture1.AutoSize = True
Set myPic = LoadPicture("R:\st.bmp")
Picture1.Picture = myPic
myPic_W = myPic.Width
myPic_H = myPic.Height
Debug.Print Time, myPic_W, myPic_H
Dim c As Long
c = GetPixel(Picture1.hdc, 0, 0)
Debug.Print c
Set myPic = Nothing
End Sub
As you can see, you don't understand what that magic number means. Therefore, you should avoid magic numbers whenever possible. Use constants instead!
Code:Option Explicit
Private Sub Command1_Click()
Dim myPic_W As Long
Dim myPic_H As Long
With Form1.Picture1
.ScaleMode = vbPixels
.AutoRedraw = True
.AutoSize = True
Set .Picture = LoadPicture("R:\st.bmp")
myPic_W = ScaleX(.Picture.Width, vbHimetric, vbPixels)
myPic_H = ScaleY(.Picture.Height, vbHimetric, vbPixels)
Debug.Print Time, myPic_W & "x" & myPic_H
End With
End Sub
Why don't you just use Picture1.Width and Picture1.Height only? Why the other stuff?
Because Picture1.Width and Picture1.Height returns the size of the PictureBox control itself while the dimensions of the PictureBox's Picture property are obtained through the similarly named Width and Height properties of the StdPicture class. The Picture property's dimensions are usually independent from the size of the PictureBox, but in this case, since the AutoSize property was set to True, both dimensions of the PictureBox and its Picture property coincide with each other. However, I decided not to rely on this fact, but instead I used the ScaleX/ScaleY methods of the Form to convert the true dimensions of the Bitmap Picture from HiMetric to Pixels.
Then use ScaleWidth and ScaleHeight.
Well, they don't always correspond with the dimensions of the Picture property, so they're also unreliable. A PictureBox can be bigger or smaller than the Picture assigned to it, thus its Width/Height or ScaleWidth/ScaleHeight won't always agree with the dimensions of its Picture property.
Interesting. Never ran into that problem in all the years I have used pictureboxes in VB programming. I'll take your work for it however
Bonnie
True dat .. ;)Quote:
Well, they don't always correspond with the dimensions of the Picture property, so they're also unreliable.
BTW, how did you get the keywords to go blue in your post #7.
It's brilliant.
Spoo
There is a Text Color drop-down button on the editor's toolbar.
Here is another way of doing it, very easy.
You will need 'Microsoft Window Image Acquisition Library v2.0' installed on the system (which I'm sure you do).
You could do much more with WIA 2.0, ask dilettante :)Code:Private Function GetImageDimension(FileName As String) As String
Dim ImageFile As Object
Set ImageFile = CreateObject("WIA.ImageFile")
With ImageFile
.LoadFile (FileName)
GetImageDimension = .Width & " x " & .Height
End With
End Function
Private Sub Command1_Click()
MsgBox GetImageDimension("C:\1.bmp")
End Sub
Just to add, Bonnie West's example works very good, but is a bit slow because it loads picture into picturebox.
Bonnie West is a great teacher and knows a lot more than I do, but testing Bonnie's example with image folder (image list) it was very slow!
Using the WIA 2.0 looking for 10 images' dimension takes about under 1 second .
Using picturebox (Bonnie's example) took about 4 seconds!
Depending what you need it for, I would go with WIA 2.0.
If you only need the one dimension and that's it, then you could go with Bonnie's example.
There is another approach: ask Windows Explorer (a.k.a. Shell32).
This can be quick or a littler slower depending on whether it already has the info cached from a previous viewing. But at worst it might still be much quicker than completely loading each image file and decoding it far enough to extract the dimensions the way previous suggestions do.
Another approach to consider anyway. Here I request an image folder to list, then pull out the files (not traversing subfolders though you could do that too). Then I extract a few properties and extended properties and dump them into a flexgrid.
You know what Spoo, I always wondered that too, about the blue text in Bonnie's post.
Regarding my post #18 above:
Note that results might vary from version to version of Windows. Sometimes the extended properties have different "friendly names" and then you'd want to fetch them by FMTID and PID (combined as a SCID), which you'd need to look up.
Ok, went back and got the info to make SCIDs for the extended properties I've used here. Updating attachment above.Quote:
ExtendedProperty Method
sPropName argument:
Required. String value that specifies the property. There are two ways to specify a property. The first is to assign the property's name, such as "Author" or "Date", to sPropName. However, each property is a member of a COM property set and can also be identified by specifying its format ID (FMTID) and property ID (PID). An FMTID is a GUID that identifies the property set, and a PID is an integer that identifies a particular property within the property set. Specifying a property by its FMTID/PID values is usually more efficient than using its name. To use a property's FMTID/PID values with ExtendedProperty, they must be combined into an SCID. An SCID is a string that contains the FMTID/PID values in the form "FMTID,PID", where the FMTID is the string form of the property set's GUID. For example, the SCID of the summary information property set's author property is "{F29F85E0-4FF9-1068-AB91-08002B27B3D9},4". For a list of FMTIDs and PIDs that are currently supported by the Shell, see SHCOLUMNID.
Your attachment worked for me dilettate (just to let you know).
It would be nice if you did fix that issue for other versions of windows, I am using Winows 7 Home Premium (x64).
Got it.
Sure was a pain figuring out where to dig it out from though. The info isn't where they say it is in that quote above.
Even so, it requires Shell 5.00 or later so it probably won't work at all prior to Windows Me and 2000.