AutoHotkey Community

It is currently May 26th, 2012, 9:13 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 1000 posts ]  Go to page Previous  1 ... 13, 14, 15, 16, 17, 18, 19 ... 67  Next
Author Message
 Post subject:
PostPosted: July 4th, 2009, 4:43 pm 
Offline

Joined: December 13th, 2006, 7:10 am
Posts: 118
Does anyone knows a good tutorial on using matrix ?

Is there a way to change alpha transparency when using Gdip_DrawImage ?
I know this could be done to the final result, with "UpdateLayeredWindow" but that's not what I want...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 4th, 2009, 7:15 pm 
Offline

Joined: December 13th, 2006, 7:10 am
Posts: 118
Instead of:
Code:
Gdip_Startup()
{
   If !DllCall("GetModuleHandle", "Str", "gdiplus")
   DllCall("LoadLibrary", "Str", "gdiplus")
   VarSetCapacity(si, 16, 0), si := Chr(1)
   DllCall("gdiplus\GdiplusStartup", "UInt*", pToken, "UInt", &si, "UInt", 0)
   Return, pToken
}

Gdip_Shutdown(pToken)
{
   DllCall("gdiplus\GdiplusShutdown", "UInt", pToken)
   If hModule := DllCall("GetModuleHandle", "Str", "gdiplus")
   DllCall("FreeLibrary", "UInt", hModule)
   Return, 0
}


why not:
Code:
Gdip_StartStop()
{
Static pToken

if !pToken
   {
      If !DllCall("GetModuleHandle", "Str", "gdiplus")
      DllCall("LoadLibrary", "Str", "gdiplus")
      VarSetCapacity(si, 16, 0), si := Chr(1)
      DllCall("gdiplus\GdiplusStartup", "UInt*", pToken, "UInt", &si, "UInt", 0)
   }
   else
   {
      DllCall("gdiplus\GdiplusShutdown", "UInt", pToken)
      If hModule := DllCall("GetModuleHandle", "Str", "gdiplus")
      DllCall("FreeLibrary", "UInt", hModule)
   }
}


This avoid the use of a global pToken


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 8th, 2009, 1:06 pm 
Offline

Joined: April 30th, 2009, 12:35 pm
Posts: 29
I like GDIP, very nice.

I'm wondering though, how to erase parts ?

A small request for your consideration. In the class Gdip_TextToGraphics it would be nice to add a border aswell (contrasting colour) xpoints around the text.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 8th, 2009, 1:39 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
Smurth, if two separate parts of a script (e.g. library functions) were to try to initialize GDI+, they currently won't conflict as long as they use a static/local variable or uniquely-named global variable to store the token. With your version, the second call intended to initialize GDI+ would shut it down for both.

mrr19121970, I think there are (at least) two ways to erase:
  • Gdip_GraphicsClear. To erase only part, set clipping with Gdip_SetClipRect.
  • Set overwrite mode with Gdip_SetCompositingMode, create a transparent brush with Gdip_BrushCreateSolid (passing an ARGB value with zero for the alpha component), then call Gdip_FillRectangle.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 10th, 2009, 9:42 am 
Offline

Joined: April 30th, 2009, 12:35 pm
Posts: 29
@Lexikos

Thanks, the 2nd example did exactly what I was getting at. However I didn't qualify my original question with what I wanted to do. I wanted to remove text from the image. So draw a rectangle and 'cut out' the word 'draft' for example.

Changing GDIP.ahk class Gdip_TextToGraphics:
Code:
Gdip_SetCompositingMode(pGraphics,1)
E := Gdip_DrawString(pGraphics, Text, hFont, hFormat, pBrush, RC)
Gdip_SetCompositingMode(pGraphics)


cuts out a rectangle the size of the letter, rather than the letter itself.

so I suspect this might not be possible.



EDIT

Posted too quick ?

This does the trick:

Code:
Gdip_SetCompositingMode(G,1)
Gdip_SetClipRect(G, 0, 0, 50, 50, 3)
Options = x20 y20 w200 Centre c0 r1 s40
Gdip_TextToGraphics(G, "DRAFT", Options, Font, Width, Height)


r1 is very important, otherwise the edge will be ragged (normally you would use r4)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 12th, 2009, 2:55 pm 
Offline

Joined: April 30th, 2009, 12:35 pm
Posts: 29
I suspect there is a tiny bug in Gdip_TextToGraphics.

If I give an align of 'Center' and an Xpos of say -10 or +10 then my text will be 10 points left or right of centre. However if I do the same with VPos/YPos my text is always centred. This seems to work as a fix

Code:
   If vPos
   {
      StringSplit, ReturnRC, ReturnRC, |
      
      If (vPos = "vCentre") || (vPos = "vCenter")
      ypos := ypos + (Height-ReturnRC4)//2

;      Else If (vPos = "Top") || (vPos = "Up")
;      ypos := 0

      Else If (vPos = "Bottom") || (vPos = "Down")
      ypos := ypos + Height-ReturnRC4
      
      CreateRectF(RC, xpos, ypos, Width, ReturnRC4)
   }



Perhaps TIC can think of including it in any new change he makes ?


Here is my solution for bordered text:


Code:
Gdip_BorderedText(pGraphics, Text, Options, Font="Arial", Width="", Height="")
{
   IWidth := Width, IHeight:= Height
   
   RegExMatch(Options, "i)X([\-0-9]+)(p*)", xpos)
   RegExMatch(Options, "i)Y([\-0-9]+)(p*)", ypos)
   RegExMatch(Options, "i)W([0-9]+)(p*)", Width)
   RegExMatch(Options, "i)H([0-9]+)(p*)", Height)
   RegExMatch(Options, "i)C(?!(entre|enter))([a-f0-9]{8})", Colour)
   RegExMatch(Options, "i)Top|Up|Bottom|Down|vCentre|vCenter", vPos)
   RegExMatch(Options, "i)R([0-9])", Rendering)
   RegExMatch(Options, "i)S([0-9]+)(p*)", Size)
   RegExMatch(Options, "i)T([0-9])", Border_Thickness)
   RegExMatch(Options, "i)B([a-f0-9]{8})", Border_Colour)

   Style =
   Styles := "Regular|Bold|Italic|BoldItalic|Underline|Strikeout"
   Loop, Parse, Styles, |
   {
      If RegExMatch(Options, "\b" A_loopField)
      Style := A_LoopField
   }
   Align =
   Alignments := "Near|Left|Centre|Center|Far|Right"
   Loop, Parse, Alignments, |
   {
      If RegExMatch(Options, "\b" A_loopField)
      Align := A_loopField
   }

   if Border_Thickness <>
   {
      if xpos =
         xpos = x0
      if ypos =
         ypos = y0
      Border_Thickness_Array = -1 -1 0 -1 +1 -1 -1 0 +1 0 -1 +1 0 +1 +1 +1
      StringSplit, Border_Thickness_Item, Border_Thickness_Array, %A_Space%

      Border_Thickness := SubStr(Border_Thickness,2)
      Border_Colour := SubStr(Border_Colour,2)

      Border_Thickness_Idx=0
      Loop, % Border_Thickness_Item0 / 2
      {
         Border_Thickness_Idx++
         xbord = % Border_Thickness_Item%Border_Thickness_Idx%
         Border_Thickness_Idx++
         ybord = % Border_Thickness_Item%Border_Thickness_Idx%
         xbord := SubStr(xpos,2) + (Border_Thickness * xbord)
         ybord := SubStr(ypos,2) + (Border_Thickness * ybord)
         Options = x%xbord% y%ybord% %Width% %Align% %vPos% %Style% c%Border_Colour% %Rendering% %Size%
         Gdip_TextToGraphics(pGraphics, text, Options, Font, iWidth, iHeight)
      }
      Gdip_SetCompositingMode(pGraphics,1)
      Gdip_SetClipRect(pGraphics, 0, 0, %iWidth%, %iWidth%, 3)
      Options = %xpos% %ypos% %Width% %Align% %vPos% %Style% cffffffff %Rendering% %Size%
      Gdip_TextToGraphics(pGraphics, Text, Options, Font, iWidth, iHeight)
      Gdip_SetCompositingMode(pGraphics)
      Gdip_ResetClip(pGraphics)
   }

   Options = %xpos% %ypos% %Width% %Height% %Align% %vPos% %Style% %Colour% %Rendering% %Size%
   Gdip_TextToGraphics(pGraphics, Text, Options, Font, iWidth, iHeight)

}


if anyone's interested. Usage as Gdip_TextToGraphics with Bordercolour & Thickness extra in options
Code:
Options = x10p y30p w80p Centre cbbffffff r1 s20 T4 Bbb000000 Underline Italic
Gdip_BorderedText(G, "Tutorial 8`n`nThank you for trying this example", Options, Font, Width, Height)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 13th, 2009, 12:44 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
Hey, thanks for the ideas and comments. You may have noticed that I havent been posting so much recently, Ive been soooo busy :wink:

I have been meaning to update so many things, including TextToGraphics. I primarily wanted to add the ability to add gradiented text, which wouldnt be too hard, but would need testing. I will when I get time!

note:

Code:
   Styles := "Regular|Bold|Italic|BoldItalic|Underline|Strikeout"
   Loop, Parse, Styles, |
   {
      If RegExMatch(Options, "\b" A_loopField)
      Style := A_LoopField
   }


If you use := rather than |= then you cant set underline and bold for example. You can only set one or the other as they are not ORd together.

Thank you mrr19121970 for your ideas though. I will take a read through and when I get time (one day.....) then I will add all of the updates and test them. Many are already added, but I need to test them


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 17th, 2009, 7:43 pm 
Hi tic, how can I change the transparency of a input file PNG and save the result on another png file?
I want increase or decrease only the value of transparency channel.

1000 thanks in advance!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 19th, 2009, 12:53 pm 
Offline

Joined: April 30th, 2009, 12:35 pm
Posts: 29
See Example #10 http://www.autohotkey.net/~tic/Gdip.Tut ... .image.ahk


Change (blank) line 33 to:

Code:
Gui, 1: Add, Slider, x10 y+20 w300 Tooltip vTransparency Range1-100, 0


Change line 124:

Code:
Gdip_DrawImage(G, pBitmap, 0, 0, Width, Height, 0, 0, OriginalWidth, OriginalHeight, Transparancy/100)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 21st, 2009, 6:50 am 
Hello all in this thread, I would welcome any ideas or programming examples for this problem below.

I basically would like to transform a transparent bitmap to a different color.

Please see this example!

Image

Assuming the background is transparent, how would I take one bitmap and completely change it to a different color, ... preserving the subtle transparency levels in the bitmap? :)

Anyone know how? I would be greatly appreciated if someone in the know, knows how to do this feat. :)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 21st, 2009, 12:03 pm 
Offline

Joined: April 30th, 2009, 12:35 pm
Posts: 29
it's more or less the same question (or at least the answer is the same) that FL asked 2 posts previous to yours.

you need to change the 'matrix' in the call to Gdip_DrawImage. I don't know what the exact values mean, but abit of digging around and playing should help you. in the gdip.ahk there are some examples to make the picture brighter, greyscale and negative which should get you started.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 23rd, 2009, 6:25 am 
THank you 191. I did some looking at that function.

IT looks promising. :)

But, I am confuzed (or confuzed), ... the matrix, bit ... how to construct it to specify a total change of color to a single flat color? Like my example earlier, ... how would I parse matrix to tell it to turn all green? Any examples to get me started? :)

I would appreciate any wisdom or knowledge here. This one has been frustrating for me to figure out.


Best regards, SS


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2009, 2:49 pm 
Offline

Joined: April 30th, 2009, 12:35 pm
Posts: 29
see here http://msdn.microsoft.com/en-us/library ... nd%29.aspx

using your image as input try:

Code:
;red
;myColMat = ("0|0|0|-1|1|1|-1|-1|0|0|1|-1|-1|0|0|1|-1|-1|0|0|1|-1|-1|0|0|")
;green
myColMat = ("0|0|0|-1|1|-1|1|-1|0|0|-1|1|-1|0|0|-1|1|-1|0|0|-1|1|-1|0|0")
;blue
;myColMat = ("0|0|0|-1|1|-1|-1|1|0|0|-1|-1|1|0|0|-1|-1|1|0|0|-1|-1|1|0|0")
Gdip_DrawImage(G, pBitmap, 0, 0, Width, Height, 0, 0, OriginalWidth, OriginalHeight, myColMat)



or add (after line 33):

Code:
Gui, 1: Add, Slider, x10 y+20 w300 Tooltip vRED Range-100-100, 0
Gui, 1: Add, Slider, x10 y+20 w300 Tooltip vGREEN Range-100-100, 0
Gui, 1: Add, Slider, x10 y+20 w300 Tooltip vBLUE Range-100-100, 0


and (before line 124):

Code:
RED := RED/100
GREEN := GREEN/100
BLUE := BLUE/100
myColMat = ("0|0|0|-1|1|%RED%|%GREEN%|%BLUE%|0|0|%RED%|%GREEN%|%BLUE%|0|0|%RED%|%GREEN%|%BLUE%|0|0|%RED%|%GREEN%|%BLUE%|0|0")


replacing line 124 with

Code:
Gdip_DrawImage(G, pBitmap, 0, 0, Width, Height, 0, 0, OriginalWidth, OriginalHeight, myColMat)


to example 10 to play yourself.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 26th, 2009, 4:54 pm 
M, that is really really cool. :cool:

Might I ask, if I needed to pass in a HEX value, or a 0-255 RGB color into this, ... I am sort of bedazzled by the conversion system here. I didn't get the desired result, (at least not 100%)

IE:

A Pure Purple (F000FF) which is R(240) G(0) B(255)

by putting Red=240, Green=0, Blue=255 into this matrix,

produces a close, but off-key (R)255 G(0) B(255).

I am starting with a flat-black (R)0 G(0) B(0) -- (i.e. hex #000000) bitmap. I seem to produce slightly different but close to purple outputs when I change the original bitmap color.

But, is there some method I am missing, whereas I ccould produce a precision output, based on some numerical RGB or HEX standard format ... And that would be assuming the original bitmap is always 100% 00000 black to go from? :) :)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2009, 3:17 am 
Offline

Joined: April 8th, 2009, 7:49 pm
Posts: 6065
Location: San Diego, California
Hey tic,
Thank you very much. :!: :!:
I was looking for a way to show an image on the screen and be able to rotate it.
And then I found :arrow: Example 10: Gdip.Tutorial.10-Rotate.Flip.or.Mirror.an.image.ahk - Rotate, flip or mirror an image on a layered window

This is fantastic and your code has great comments. Again, thanks.

My goal is an application to project a static image through a projector, scaled to fit a rather small screen with strange dimensions.
I want to compensate for both the projector and screen not perfectly aligned.

:arrow: to all: Please understand this is not an "I need a script" post. It is a request for pointers/info that others may already have.

Features I want are:
- black background (another fullscreen GUI with black background will do)
- rotate in the z-axis (Gdip tut #10!)
- select which monitor/screen to show image on (mod of tut#10)
- x & y placement, width & height (again Gdip tut #10!)
- ability to switch between multiple images quickly (mod of tut#10)
- fade images to black or fade between images would be great :?:
- keystone effect http://en.wikipedia.org/wiki/Keystone_effect :?:
--- The Keystoning does not have to be 'proper' it could be as simple as adjusting x & y of 4 control points.

If anyone has pointers on accomplishing keystoning or fading I would appreciate the information.

Thanks in advance.

Leef_me


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1000 posts ]  Go to page Previous  1 ... 13, 14, 15, 16, 17, 18, 19 ... 67  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: iBob35555VR and 11 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