<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: Gdip - вырезание]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=15114</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=15114&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Gdip - вырезание».]]></description>
		<lastBuildDate>Tue, 07 Jan 2020 12:37:32 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: Gdip - вырезание]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=137194#p137194</link>
			<description><![CDATA[<p>Будет время, через WIC попробую.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Tue, 07 Jan 2020 12:37:32 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=137194#p137194</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Gdip - вырезание]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=137193#p137193</link>
			<description><![CDATA[<p>Наверное не поддерживается в Clipping.</p>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Tue, 07 Jan 2020 12:35:28 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=137193#p137193</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Gdip - вырезание]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=137186#p137186</link>
			<description><![CDATA[<p>Да, тоже это нашёл, так вышло:<br /></p><div class="codebox"><pre><code>#NoEnv

File = C:\Users\Public\Pictures\1538158694935.JPEG
Width := 200, Height := 200
Gui, New, -Caption -DPIScale +E0x80000 +hwndhGui 
Gui, Show, NA

pToken := Gdip_Startup()
hbm := CreateDIBSection(Width, Height)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetSmoothingMode(G, 2)
; Gdip_SetInterpolationMode(G, 7)

pBitmap := Gdip_CreateBitmapFromFile(File)
Path := Gdip_CreatePath()
Gdip_AddPathEllipse(Path, 0, 0, Width, Height)
Gdip_SetClipPath(G, Path)
Gdip_DrawImage(G, pBitmap)

UpdateLayeredWindow(hGui, hdc, 100, 100, Width, Height)

Gdip_DeletePath(Path)
Gdip_DisposeImage(pBitmap)
Gdip_DeleteGraphics(G)
SelectObject(hdc, obm)
DeleteDC(hdc)
DeleteObject(hbm)
Gdip_Shutdown(pToken)</code></pre></div><p>Но почему-то антиалиасинг не работает.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Tue, 07 Jan 2020 07:30:21 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=137186#p137186</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Gdip - вырезание]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=137184#p137184</link>
			<description><![CDATA[<p><a href="https://docs.microsoft.com/ru-ru/windows/win32/gdiplus/-gdiplus-clipping-about">https://docs.microsoft.com/ru-ru/window … ping-about</a><br />Наверное как то так лучше, но пока не понял как.</p>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Mon, 06 Jan 2020 22:05:55 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=137184#p137184</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Gdip - вырезание]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=137168#p137168</link>
			<description><![CDATA[<p>Спасибо, будем посмотреть.</p>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Mon, 06 Jan 2020 14:26:12 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=137168#p137168</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Gdip - вырезание]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=137167#p137167</link>
			<description><![CDATA[<p>Наверно правильнее будет <a href="https://docs.microsoft.com/en-us/windows/win32/gdiplus/-gdiplus-region-flat">регион</a> установить. Примеров кода нет, надо гуглить.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Mon, 06 Jan 2020 10:14:22 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=137167#p137167</guid>
		</item>
		<item>
			<title><![CDATA[AHK: Gdip - вырезание]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=137144#p137144</link>
			<description><![CDATA[<p>Написал код для вырезания круга из картинки, в примере надо прописать путь к картинке и она должна отобразится.<br />Как правильно вырезать например эллипс, или какие то другие фигуры неправильной формы. <br />То есть вырезать не их самих, это сделать просто с помощью заливки, а вырезать то что вокруг них.</p><p>В примере фигура рисуется с помощью толстой кисти, которая и затирает всё вокруг, какие есть альтернативы такому подходу?<br /></p><div class="codebox"><pre><code>

#SingleInstance, Force
#NoEnv

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


File =  

  ;	стороны квадрата в которые будет размещено исходное изображение. Height нужно для тестов с элипсами
 
 
Width := 800
Height := 800

Gui, New, -Caption -DPIScale +E0x80000 +hwndhGui 
Gui, Show, NA
hbm := CreateDIBSection(Width, Height)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)

Gdip_SetInterpolationMode(G, 7)
Gdip_SetSmoothingMode(G, 2)

; 1::
	pBitmap := Gdip_CreateBitmapFromFile(File)
	Gdip_GetImageDimensions(pBitmap, PicW, PicH)
	  ;	нужен прозрачный битмап для копирования в него исходного
	pBitmap2 := Gdip_CreateBitmap(Width, Height) 
	pGraphics := Gdip_GraphicsFromImage(pBitmap2) 

	Gdip_SetInterpolationMode(pGraphics, 7) 
	Gdip_SetSmoothingMode(pGraphics, 0)
	  ;	растягивание картинки в прозрачном битмапе
	Gdip_DrawImage(pGraphics, pBitmap, 0, 0, Width, Height, 0, 0, PicW, PicH)
	Gdip_DisposeImage(pBitmap)
	 ;	из гипотенузы / 2 вычитаем радиус. Это вычисление не работает с элипсами
	r := Sqrt(Height**2 + Width**2) - (Width &gt; Height ? Width : Height)  
	r := Ceil(r / 2), r2 := r / 2
	  ;	прозрачная кисть с заданной толщиной
	pPen := Gdip_CreatePen(0x90000000, r) 
	  ; меняем режим рисования. Их всего 2. 0 - Наложение рисунка(стандарт), 1 - замена. Для замены и требовался прозрачный битмап
	Gdip_SetCompositingMode(pGraphics, 1)
	  ;	делаем кольцо оббод которого чуть выходит за пределы картинки, и замещает собой пиксели картинки
	Gdip_DrawEllipse(pGraphics, pPen, -r2, -r2, Width + r, Height + r)
	Gdip_DeletePen(pPen)
	
	If 0  ;	обрамление
		 ;	Окружность вокруг вырезанного. b будет относительна Width и Height
		pPen := Gdip_CreatePen(0xffffffff, b := 10) 
		Gdip_DrawEllipse(pGraphics, pPen,  b / 2 - 1 ,  b / 2 - 1, Width - b + 1 , Height - b + 1) 
		Gdip_DeletePen(pPen)
	 
	Gdip_DrawImage(G, pBitmap2, 0, 0, Width, Height, 0, 0, Width, Height) 
	Gdip_DeleteGraphics(pGraphics)  
	Gdip_DisposeImage(pBitmap2) 
	 
	UpdateLayeredWindow(hGui, hdc, 55, 55, Width, Height, 255)
	Return

Esc::
GuiClose:
Exit:
	Gdip_DeleteGraphics(G)  
	SelectObject(hdc, obm)
	DeleteDC(hdc)
	DeleteObject(hbm) 
	Gdip_Shutdown(pToken) 
	exitapp
 
</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Sat, 04 Jan 2020 11:47:06 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=137144#p137144</guid>
		</item>
	</channel>
</rss>
