Write all pixel colors of a image.

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
shapowsky
Newbie
Posts: 11
Joined: Sun Mar 06, 2016 9:29 am

Write all pixel colors of a image.

Post by shapowsky » Mon Jun 20, 2016 7:20 pm

There's a way to do it?

Import image and writeln all pixels colors?
x1,y1 = z
x1,y2 = z1
...

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Write all pixel colors of a image.

Post by Marcus Tettmar » Fri Jun 24, 2016 11:21 am

Not natively, that I can think of. But there's probably a third party control or app.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Write all pixel colors of a image.

Post by JRL » Mon Jun 27, 2016 2:01 pm

Script is a proof of concept and has not been thoroughly tested. Basic premise is to read each pixel of a selected image using GetPixelColor>, Then write the pixel coordinates and the color to a txt file. Image is displayed on a Macro Scheduler dialog so the Image file type must be JPG, BMP or PNG. Once started, press Esc or close the dialog to kill the script.

This will be slow, my computer is reading about 30 pixels per second.


Code: Select all

OnEvent>key_down,VK27,0,Quit
SRT>Quit
  Exit>0
END>Quit


Dialog>Dialog1
object Dialog1: TForm
  Left = 547
  Top = 122
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Get Color Matrix'
  ClientHeight = 108
  ClientWidth = 301
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poScreenCenter
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 16
    Top = 16
    Width = 95
    Height = 13
    Caption = 'Select an image file:'
  end
  object MSImage1: tMSImage
    Left = 0
    Top = 0
    Width = 105
    Height = 105
  end
  object Edit1: TEdit
    Left = 16
    Top = 41
    Width = 248
    Height = 21
    TabOrder = 0
  end
  object MSButton1: tMSButton
    Left = 269
    Top = 41
    Width = 21
    Height = 21
    Glyph.Data = {
      F6000000424DF600000000000000760000002800000010000000100000000100
      0400000000008000000000000000000000001000000010000000000000000000
      80000080000000808000800000008000800080800000C0C0C000808080000000
      FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00777777777777
      77777777777777777777000000000007777700333333333077770B0333333333
      07770FB03333333330770BFB0333333333070FBFB000000000000BFBFBFBFB07
      77770FBFBFBFBF0777770BFB0000000777777000777777770007777777777777
      7007777777770777070777777777700077777777777777777777}
    TabOrder = 1
    DoBrowse = False
    Filter = 'Any file (*.*)|*.*'
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,MSButton1,OnClick,Start
AddDialogHandler>Dialog1,,OnClose,Quit
Let>SelectionFlag=0

Show>Dialog1

Label>Loop
  Wait>0.01
  If>SelectionFlag=1
  

**BREAKPOINT**
    Let>ky=0
    Repeat>ky
    Add>ky,1
      Let>kx=0
      SetDialogProperty>Dialog1,MSImage1,Left,kx
      Repeat>kx
        Add>kx,1
        GetPixelColor>vWinX,vWiny,vColor
        WriteLn>%temp_dir%Image_Log.txt,wres,%kx%,%ky%,%vColor%
        Let>vLeft={%kx%*-1}
        SetDialogProperty>Dialog1,MSImage1,Left,vLeft
      Until>kx=vWide
      Let>vTop={%ky%*-1}
      SetDialogProperty>Dialog1,MSImage1,Top,vTop
    Until>ky=vHigh
    Exit>0
  EndIf
Goto>Loop

SRT>Start
  SetDialogProperty>Dialog1,MSButton1,DoBrowse,True
  GetDialogProperty>Dialog1,MSButton1,Filename,strFileName
  SetDialogProperty>Dialog1,MSImage1,LoadImage,strFileName
  SetDialogProperty>Dialog1,MSImage1,AutoSize,True
  SetDialogProperty>Dialog1,MSButton1,Visible,False
  SetDialogProperty>Dialog1,Label1,Visible,False
  SetDialogProperty>Dialog1,Edit1,Visible,False
  SetDialogProperty>Dialog1,,BorderStyle,bsNone
  Let>SelectionFlag=1
  GetDialogProperty>Dialog1,MSImage1,Width,vWide
  GetDialogProperty>Dialog1,MSImage1,Height,vHigh
  GetWindowPos>Get Color Matrix,vWinX,vWinY
  Add>vWinX,1
  Add>vWinY,1
END>Start

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts