AutoHotkey Community

It is currently May 27th, 2012, 12:00 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 17 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: December 9th, 2011, 2:29 pm 
Offline

Joined: November 12th, 2011, 2:24 pm
Posts: 122
You can do it using gdip but saving it as jpg will change the colors slightly because of the compression algorithm so viewing it again will be different than the original.

I always use png because it is lossless and has alpha channel.You can easily change the format in the code by changing the destination filename extension.


Code:
#SingleInstance, Force
#NoEnv
SetBatchLines, -1

;#Include, Gdip.ahk  http://www.autohotkey.com/forum/topic32238.html

If !pToken := Gdip_Startup()
{
   MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
   ExitApp
}
data=
(
0xff00ff,0xffffff,0xff00ff
)

;read line count to get height of image

StringReplace,data,data,`n,`n,UseErrorlevel
height:=ErrorLevel + 1

;read "," to get width
loop,parse,data,`n
{
StringReplace,temp,A_LoopField,`,`,UseErrorlevel
width:=ErrorLevel + 2
Break
}

pBitmap := Gdip_CreateBitmap(width,height)
 
y=0
x=0
loop,parse,data,`n
{
  loop,parse,A_LoopField,`,
  {
  Gdip_SetPixel(pBitmap, x, y, A_LoopField+0xff000000)

  x++
  }
x=0
y++
}
;Gdip_SetBitmapToClipboard(pBitmap)  ; to set to clipboard
Gdip_SaveBitmapToFile(pBitmap, "File.bmp")

Gdip_DisposeImage(pBitmap)

Gdip_Shutdown(pToken)
ExitApp






Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 9th, 2011, 6:34 pm 
Offline

Joined: June 4th, 2005, 1:30 am
Posts: 113
Location: Stuttgart, Germany
I think ImageMagick will do this way faster.
Code:
oI := ComObjCreate("ImageMagickObject.MagickImage.1")
oI.convert("plasma1.txt", "plasma1.png")
Code:
# ImageMagick pixel enumeration: 200,200,255,rgb
0,0: (247,252,248)  #F7FCF8  rgb(247,252,248)
1,0: (242,247,243)  #F2F7F3  rgb(242,247,243)
2,0: (243,248,244)  #F3F8F4  rgb(243,248,244)
3,0: (250,252,247)  #FAFCF7  rgb(250,252,247)
4,0: (249,250,245)  #F9FAF5  rgb(249,250,245)
5,0: (253,252,247)  #FDFCF7  rgb(253,252,247)
6,0: (241,238,233)  #F1EEE9  rgb(241,238,233)
7,0: (245,237,234)  #F5EDEA  rgb(245,237,234)
8,0: (248,237,235)  #F8EDEB  rgb(248,237,235)
...

Though it requires the colors in RGB format e.g. (247,252,248).
Quote:
Reading TXT images is also valid. You do not need to define ALL the pixels in the image. In fact you do not even need to have the pixels in the correct order! ImageMagick will just read each of the pixel in turn and 'draw' it onto a blank image canvas. Only the numbers in the parenthesis on each line is used for this, not the color names.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group