Sign in to follow this  
Followers 0
JScript

[SOLVED] VB to AutoIt v3

5 posts in this topic

#1 ·  Posted (edited)

Hello everybody,

Could someone help me pass this little VB code for AutoIt?

Option Explicit
Private Type BITMAPINFOHEADER
    biSize As Long
    biWidth As Long
    biHeight As Long
    biPlanes As Integer
    biBitCount As Integer
    biCompression As Long
    biSizeImage As Long
    biXPelsPerMeter As Long
    biYPelsPerMeter As Long
    biClrUsed As Long
    biClrImportant As Long
End Type

Private Type RGBQUAD
    rgbBlue As Byte
    rgbGreen As Byte
    rgbRed As Byte
    rgbReserved As Byte
End Type

Private Type BITMAPINFO8
    bmiHeader As BITMAPINFOHEADER
    bmiColors(255) As RGBQUAD
End Type

Private Sub GrayScale_Click()
    ' // Convert Picture1 to GrayScale //
    Dim DeskWnd As Long, DeskDC As Long
    Dim MyDC As Long
    Dim MyDIB As Long, OldDIB As Long
    Dim DIBInf As BITMAPINFO8
    Dim MakePal As Long
    
    Picture1.AutoRedraw = True
    
    ' Create DC based on desktop DC
    DeskWnd = GetDesktopWindow()
    DeskDC = GetDC(DeskWnd)
    MyDC = CreateCompatibleDC(DeskDC)
    ReleaseDC DeskWnd, DeskDC
    ' Validate DC
    If (MyDC = 0) Then Exit Sub
    ' Set DIB information
    With DIBInf
        With .bmiHeader ' Same size as picture
            .biWidth = Picture1.ScaleX(Picture1.ScaleWidth, Picture1.ScaleMode, vbPixels)
            .biHeight = Picture1.ScaleY(Picture1.ScaleHeight, Picture1.ScaleMode, vbPixels)
            .biBitCount = 8
            .biPlanes = 1
            .biClrUsed = 256
            .biClrImportant = 256
            .biSize = Len(DIBInf.bmiHeader)
        End With
        ' Palette is Greyscale
        For MakePal = 0 To 255
            With .bmiColors(MakePal)
                .rgbRed = MakePal
                .rgbGreen = MakePal
                .rgbBlue = MakePal
            End With
        Next MakePal
    End With
    ' Create the DIBSection
    MyDIB = CreateDIBSection8(MyDC, DIBInf, 0, ByVal 0&, 0, 0)
    If (MyDIB) Then ' Validate and select DIB
        OldDIB = SelectObject(MyDC, MyDIB)
        ' Draw original picture to the greyscale DIB
        BitBlt MyDC, 0, 0, DIBInf.bmiHeader.biWidth, DIBInf.bmiHeader.biHeight, Picture1.hdc, 0, 0, vbSrcCopy
        ' Draw the greyscale image back to picture box 1
        BitBlt Picture1.hdc, 0, 0, DIBInf.bmiHeader.biWidth, DIBInf.bmiHeader.biHeight, MyDC, 0, 0, vbSrcCopy
        ' Clean up DIB
        SelectObject MyDC, OldDIB
        DeleteObject MyDIB
    End If
    ' Clean up DC
    DeleteDC MyDC
    ' Redraw
    Picture1.Refresh
End Sub

Source: http://www.allquests.com/question/3418218/Convert-color-images-to-black-and-white.html

Edit: I found the light at the end of the tunnel...

And the best: in assembler! It has what I need and much more...

Link:

Edited by jscript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Share this post


Link to post
Share on other sites



AutoIt has a lot in common with VBScript, but is not compatible with plain VB. VB code depends on libraries that are not available to an AutoIt script.

If you wish to perform that function in AutoIt, scrap the VB code and look at calling ImageMagick instead. Use the forum search for examples.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

@PsaltyDS

@ptrex

Thanks for the replies!

But giving a very detailed search, I found the light at the end of the tunnel...

And the best: in assembler! It has what I need and much more...

Link:


http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0