<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: Замена области на растровом рисунке - на определенную картинку.]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=14955</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=14955&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Замена области на растровом рисунке - на определенную картинку.».]]></description>
		<lastBuildDate>Wed, 04 Sep 2019 04:10:50 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: Замена области на растровом рисунке - на определенную картинку.]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=135938#p135938</link>
			<description><![CDATA[<p>teadrinker. спасибо.<br />Вроде все нормально работает.</p>]]></description>
			<author><![CDATA[null@example.com (ОсиповаТатьяна)]]></author>
			<pubDate>Wed, 04 Sep 2019 04:10:50 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=135938#p135938</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Замена области на растровом рисунке - на определенную картинку.]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=135937#p135937</link>
			<description><![CDATA[<p>С файлами из вложения так вышло:<br /></p><div class="codebox"><pre><code>#NoEnv
SetBatchLines, -1

; указать правильные пути к файлам
background := A_ScriptDir . &quot;\Основной рисунок.jpg&quot;
picture    := A_ScriptDir . &quot;\Вставка.jpg&quot;
outFile    := A_ScriptDir . &quot;\Out.jpg&quot;

frameColor := 0xED1B24        ; указать цвет рамки
frameVariations := 20         ; +- значение по каждой цветовой компоненте

backgroundColor := 0xFFFFFF   ; указать цвет фона основной картинки
backgroundVariations := 20    ; +- значение по каждой цветовой компоненте

gdip := new GDIplus
pBitmap1 := gdip.CreateBitmapFromFile(background)

rightBottomInnerCornerY := &quot;&quot;
if SearchPixel(gdip, pBitmap1, frameColor, frameVariations, leftTopOuterCornerX := 0, leftTopOuterCornerY := 0) {
   if SearchPixel(gdip, pBitmap1, backgroundColor, backgroundVariations, leftTopInnerCornerX := leftTopOuterCornerX, Y := leftTopOuterCornerY + 30) {
      if SearchPixel(gdip, pBitmap1, backgroundColor, backgroundVariations, X := leftTopInnerCornerX + 10, leftTopInnerCornerY := leftTopOuterCornerY + 10, &quot;DownRight&quot;) {
         if SearchPixel(gdip, pBitmap1, frameColor, frameVariations, rightTopInnerCornerX := leftTopInnerCornerX + 10, Y := leftTopInnerCornerY + 10) {
            SearchPixel(gdip, pBitmap1, frameColor, frameVariations, X := rightTopInnerCornerX - 10, rightBottomInnerCornerY := leftTopInnerCornerY + 10, &quot;DownRight&quot;)
         }
      }
   }
}
if !rightBottomInnerCornerY {
   MsgBox, Не удалось определить размеры рамки
   gdip.DisposeImage(pBitmap1)
   ExitApp
}

G1 := gdip.GraphicsFromImage(pBitmap1)
gdip.SetInterpolationMode(G, 7)
pBrush := gdip.BrushCreateSolid(0xFFFFFFFF)

gdip.FillRectangle(G1, pBrush, (X1 := leftTopInnerCornerX + 1) + 1
                             , (Y1 := leftTopInnerCornerY) + 1
                             , (W1 := rightTopInnerCornerX - leftTopInnerCornerX - 2) - 2
                             , (H1 := rightBottomInnerCornerY - leftTopInnerCornerY - 2) - 2)
gdip.DeleteBrush(pBrush)

pBitmap2 := gdip.CreateBitmapFromFile(picture)
gdip.GetImageDimensions(pBitmap2, W2, H2)
ratio2 := H2/W2
newW := W1
newH := newW*ratio2
if (newH &gt; H1) {
   newH := H1
   newW := newH/ratio2
}
X := newW = W1 ? 0 : (W1 - newW)/2
Y := newH = H1 ? 0 : (H1 - newH)/2
gdip.DrawImage(G1, pBitmap2, X + X1, Y + Y1, newW, newH, 0, 0, W2, H2)
gdip.SaveBitmap(pBitmap1, outFile, 100)

gdip.DeleteGraphics(G1)
gdip.DisposeImage(pBitmap2)
gdip.DisposeImage(pBitmap1)
Return

SearchPixel(gdi, pBitmap, colorRGB, variations, ByRef X, ByRef Y, direction := &quot;RightDown&quot;) {
   sR := (colorRGB &amp; 0xFF0000) &gt;&gt; 16
   sG := (colorRGB &amp;   0xFF00) &gt;&gt;  8
   sB := (colorRGB &amp;     0xFF)
   
   gdi.GetImageDimensions(pBitmap, W, H)
   bool := direction = &quot;RightDown&quot;
   Loop % (bool ? H - Y : W - X) - 1 {
      i := A_Index + (bool ? Y : X)
      Loop % (bool ? W - X : H - Y) - 1 {
         pixelARGB :=  bool ? gdi.GetPixel(pBitmap, A_Index + X, i) : gdi.GetPixel(pBitmap, i, A_Index + Y)
         R := (pixelARGB &amp; 0xFF0000) &gt;&gt; 16
         G := (pixelARGB &amp;   0xFF00) &gt;&gt;  8
         B := (pixelARGB &amp;     0xFF)
         if ( R + variations &gt;= sR &amp;&amp; R - variations &lt;= sR
           &amp;&amp; G + variations &gt;= sG &amp;&amp; G - variations &lt;= sG
           &amp;&amp; B + variations &gt;= sB &amp;&amp; B - variations &lt;= sB )
         {
            if bool
               Y := i, X += A_Index
            else
               X := i, Y += A_Index
            found := true
            break 2
         }
      }
   }
   Return found
}

class GDIplus  {
   __New() {
      if !DllCall(&quot;GetModuleHandle&quot;, Str, &quot;gdiplus&quot;, Ptr)
         DllCall(&quot;LoadLibrary&quot;, Str, &quot;gdiplus&quot;)
      VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1)
      DllCall(&quot;gdiplus\GdiplusStartup&quot;, UPtrP, pToken, Ptr, &amp;si, Ptr, 0)
      this.token := pToken
   }
   
   __Delete()  {
      DllCall(&quot;gdiplus\GdiplusShutdown&quot;, Ptr, this.token)
      if hModule := DllCall(&quot;GetModuleHandle&quot;, Str, &quot;gdiplus&quot;, Ptr)
         DllCall(&quot;FreeLibrary&quot;, Ptr, hModule)
   }
   
   CreateBitmapFromFile(sFile)  {
      DllCall(&quot;gdiplus\GdipCreateBitmapFromFile&quot;, WStr, sFile, PtrP, pBitmap)
      Return pBitmap
   }
   
   CreateBitmap(Width, Height, Format=0x26200A) {
       DllCall(&quot;gdiplus\GdipCreateBitmapFromScan0&quot;, Int, Width, Int, Height, Int, 0, Int, Format, Ptr, 0, PtrP, pBitmap)
       Return pBitmap
   }
   
   GetImageDimensions(pBitmap, ByRef Width, ByRef Height) {
      DllCall(&quot;gdiplus\GdipGetImageWidth&quot;, Ptr, pBitmap, UIntP, Width)
      DllCall(&quot;gdiplus\GdipGetImageHeight&quot;, Ptr, pBitmap, UIntP, Height)
   }

   GraphicsFromImage(pBitmap) {
      DllCall(&quot;gdiplus\GdipGetImageGraphicsContext&quot;, Ptr, pBitmap, PtrP, pGraphics)
      return pGraphics
   }
   
   SetInterpolationMode(pGraphics, InterpolationMode) {
   ; Default = 0
   ; LowQuality = 1
   ; HighQuality = 2
   ; Bilinear = 3
   ; Bicubic = 4
   ; NearestNeighbor = 5
   ; HighQualityBilinear = 6
   ; HighQualityBicubic = 7
      return DllCall(&quot;gdiplus\GdipSetInterpolationMode&quot;, Ptr, pGraphics, Int, InterpolationMode)
   }
   
   GetPixel(pBitmap, x, y) {
      DllCall(&quot;gdiplus\GdipBitmapGetPixel&quot;, Ptr, pBitmap, Int, x, Int, y, UIntP, ARGB)
      return ARGB
   }
   
   BrushCreateSolid(ARGB=0xff000000) {
      DllCall(&quot;gdiplus\GdipCreateSolidFill&quot;, UInt, ARGB, PtrP, pBrush)
      return pBrush
   }
   
   FillRectangle(pGraphics, pBrush, x, y, w, h) {
      return DllCall(&quot;gdiplus\GdipFillRectangle&quot;, Ptr, pGraphics, Ptr, pBrush
                                                , Float, x, Float, y, Float, w, Float, h)
   }
   
   DrawImage(pGraphics, pBitmap, dx, dy, dw, dh, sx, sy, sw, sh)  {
      Return DllCall(&quot;gdiplus\GdipDrawImageRectRect&quot;, Ptr, pGraphics, Ptr, pBitmap
                                                    , Float, dx, Float, dy, Float, dw, Float, dh
                                                    , Float, sx, Float, sy, Float, sw, Float, sh
                                                    , Int, 2, Ptr, 0, Ptr, 0, Ptr, 0)
   }

   SaveBitmap(pBitmap, ByRef info, Quality := 75, tobuff := &quot;&quot;)
   {
      ; info — если копируем в буфер, тогда расширение файла, если в файл, тогда путь к файлу
      if tobuff
         Extension := info
      else
         SplitPath, info,,, Extension
      if Extension not in BMP,DIB,RLE,JPG,JPEG,JPE,JFIF,GIF,TIF,TIFF,PNG
         return -1

      DllCall(&quot;gdiplus\GdipGetImageEncodersSize&quot;, UintP, nCount, UintP, nSize)
      VarSetCapacity(ci, nSize)
      DllCall(&quot;gdiplus\GdipGetImageEncoders&quot;, UInt, nCount, UInt, nSize, Ptr, &amp;ci)
      if !(nCount &amp;&amp; nSize)
         return -2
      
      Loop, % nCount  {
         sString := StrGet(NumGet(ci, (idx := (48+7*A_PtrSize)*(A_Index-1))+32+3*A_PtrSize), &quot;UTF-16&quot;)
         if !InStr(sString, &quot;*.&quot; Extension)
            continue
         
         pCodec := &amp;ci+idx
         break
      }
      
      if !pCodec
         return -3
      
      if RegExMatch(Extension, &quot;i)^J(PG|PEG|PE|FIF)$&quot;) &amp;&amp; Quality != 75  {
         DllCall(&quot;gdiplus\GdipGetEncoderParameterListSize&quot;, Ptr, pBitmap, Ptr, pCodec, UintP, nSize)
         VarSetCapacity(EncoderParameters, nSize, 0)
         DllCall(&quot;gdiplus\GdipGetEncoderParameterList&quot;, Ptr, pBitmap, Ptr, pCodec, UInt, nSize, Ptr, &amp;EncoderParameters)
         Loop, % NumGet(EncoderParameters, &quot;UInt&quot;)
         {
            elem := (24+A_PtrSize)*(A_Index-1) + 4 + (pad := A_PtrSize = 8 ? 4 : 0)
            if (NumGet(EncoderParameters, elem+16, &quot;UInt&quot;) = 1) &amp;&amp; (NumGet(EncoderParameters, elem+20, &quot;UInt&quot;) = 6)
            {
               p := elem+&amp;EncoderParameters-pad-4
               NumPut(Quality, NumGet(NumPut(4, NumPut(1, p+0)+20, &quot;UInt&quot;)), &quot;UInt&quot;)
               break
            }
         }      
      }
      if !tobuff
         E := DllCall(&quot;gdiplus\GdipSaveImageToFile&quot;, Ptr, pBitmap, WStr, info, Ptr, pCodec, UInt, p ? p : 0)
      else  {
         DllCall( &quot;ole32\CreateStreamOnHGlobal&quot;, UInt, 0, Int, 1, PtrP, pStream )
         if !E := DllCall( &quot;gdiplus\GdipSaveImageToStream&quot;, Ptr, pBitmap, Ptr, pStream, Ptr, pCodec, UInt, p ? p : 0 )  {
            DllCall( &quot;ole32\GetHGlobalFromStream&quot;, Ptr, pStream, PtrP, hData )
            pData := DllCall( &quot;GlobalLock&quot;, Ptr, hData, Ptr )
            nSize := DllCall( &quot;GlobalSize&quot;, Ptr, hData, Ptr )
            VarSetCapacity( info, 0), VarSetCapacity( info, nSize, 0 )
            DllCall( &quot;RtlMoveMemory&quot;, Ptr, &amp;info, Ptr, pData, UInt, nSize )
            DllCall( &quot;GlobalUnlock&quot;, Ptr, hData )
            DllCall( &quot;GlobalFree&quot;, Ptr, hData )
         }
         ObjRelease(pStream)
      }
      return E ? -4 : tobuff ? nSize : 0
   }
   
   DeleteBrush(pBrush) {
      return DllCall(&quot;gdiplus\GdipDeleteBrush&quot;, Ptr, pBrush)
   }
   
   DisposeImage(pBitmap)  {
      return DllCall(&quot;gdiplus\GdipDisposeImage&quot;, Ptr, pBitmap)
   }
   
   DeleteGraphics(pGraphics) {
      return DllCall(&quot;gdiplus\GdipDeleteGraphics&quot;, Ptr, pGraphics)
   }
}</code></pre></div><p>Пока всё это работает весьма приблизительно.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Tue, 03 Sep 2019 18:43:12 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=135937#p135937</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Замена области на растровом рисунке - на определенную картинку.]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=135936#p135936</link>
			<description><![CDATA[<div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>Если точно известно, что цвет пикселей рамки отличается от любых других, тогда можно использовать.</p></blockquote></div><p>Да, точно известно, что рамка красного цвета и нигде больше на рисунке красный цвет не используется кроме как в рамке.</p>]]></description>
			<author><![CDATA[null@example.com (ОсиповаТатьяна)]]></author>
			<pubDate>Tue, 03 Sep 2019 15:49:12 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=135936#p135936</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Замена области на растровом рисунке - на определенную картинку.]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=135935#p135935</link>
			<description><![CDATA[<p>PixelSearch тоже есть. Если точно известно, что цвет пикселей рамки отличается от любых других, тогда можно использовать. Если нет, тогда проще вручную указать, либо придётся какой-то сложный алгоритм разрабатывать, чтобы именно рамку определить.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Tue, 03 Sep 2019 15:20:23 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=135935#p135935</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Замена области на растровом рисунке - на определенную картинку.]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=135934#p135934</link>
			<description><![CDATA[<div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>Для начала нужно её координаты определить.</p></blockquote></div><p>А как определить ?<br />В автоите - используется функция PixelSearch<br />А в языке autohotkey -&nbsp; как ?</p>]]></description>
			<author><![CDATA[null@example.com (ОсиповаТатьяна)]]></author>
			<pubDate>Tue, 03 Sep 2019 15:15:28 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=135934#p135934</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Замена области на растровом рисунке - на определенную картинку.]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=135933#p135933</link>
			<description><![CDATA[<p>Я когда начинал, тоже совсем не разбирался. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /> Сейчас уже свободно на форуме болтаю, а начинал именно с разбора справки на английском.<br /></p><div class="quotebox"><cite>ОсиповаТатьяна пишет:</cite><blockquote><p>как удалить из растрового рисунка - ту область, которая находится внутри красной рамки</p></blockquote></div><p>Для начала нужно её координаты определить.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Tue, 03 Sep 2019 15:08:44 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=135933#p135933</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Замена области на растровом рисунке - на определенную картинку.]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=135932#p135932</link>
			<description><![CDATA[<p>Зачем вам нужно делать это в ахк?<br />Используйте графический редактор.</p>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Tue, 03 Sep 2019 15:03:57 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=135932#p135932</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Замена области на растровом рисунке - на определенную картинку.]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=135931#p135931</link>
			<description><![CDATA[<p>teadrinker, там все примеры на английском.<br />Их особо не почитаешь, если не очень хорошо разбираешься в языке.</p>]]></description>
			<author><![CDATA[null@example.com (ОсиповаТатьяна)]]></author>
			<pubDate>Tue, 03 Sep 2019 14:40:11 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=135931#p135931</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Замена области на растровом рисунке - на определенную картинку.]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=135930#p135930</link>
			<description><![CDATA[<p>Попробуйте почитать примеры <a href="https://github.com/mmikeww/AHKv2-Gdip/tree/master/Examples">отсюда</a>.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Tue, 03 Sep 2019 14:29:44 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=135930#p135930</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Замена области на растровом рисунке - на определенную картинку.]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=135929#p135929</link>
			<description><![CDATA[<p><span style="color: green"><strong>ОсиповаТатьяна</strong>, добавьте в название темы префикс скриптового языка.</span></p>]]></description>
			<author><![CDATA[null@example.com (ypppu)]]></author>
			<pubDate>Tue, 03 Sep 2019 14:19:21 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=135929#p135929</guid>
		</item>
		<item>
			<title><![CDATA[AHK: Замена области на растровом рисунке - на определенную картинку.]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=135928#p135928</link>
			<description><![CDATA[<p>Здравствуйте, уважаемые форумчане.</p><p>Подскажите - как удалить из растрового рисунка - ту область, которая находится внутри красной рамки (то есть заменить то что внутри - белым цветом), а потом на это место внутри красной рамки (которое было очищено) вставить рисунок &quot;Вставка.jpg&quot; с сохранением пропорций ?</p>]]></description>
			<author><![CDATA[null@example.com (ОсиповаТатьяна)]]></author>
			<pubDate>Tue, 03 Sep 2019 13:34:27 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=135928#p135928</guid>
		</item>
	</channel>
</rss>
