<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Gdip - вырезание]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=15114&amp;type=atom" />
	<updated>2020-01-07T12:37:32Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=15114</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Gdip - вырезание]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=137194#p137194" />
			<content type="html"><![CDATA[<p>Будет время, через WIC попробую.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2020-01-07T12:37:32Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=137194#p137194</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Gdip - вырезание]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=137193#p137193" />
			<content type="html"><![CDATA[<p>Наверное не поддерживается в Clipping.</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2020-01-07T12:35:28Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=137193#p137193</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Gdip - вырезание]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=137186#p137186" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2020-01-07T07:30:21Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=137186#p137186</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Gdip - вырезание]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=137184#p137184" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2020-01-06T22:05:55Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=137184#p137184</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Gdip - вырезание]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=137168#p137168" />
			<content type="html"><![CDATA[<p>Спасибо, будем посмотреть.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2020-01-06T14:26:12Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=137168#p137168</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Gdip - вырезание]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=137167#p137167" />
			<content type="html"><![CDATA[<p>Наверно правильнее будет <a href="https://docs.microsoft.com/en-us/windows/win32/gdiplus/-gdiplus-region-flat">регион</a> установить. Примеров кода нет, надо гуглить.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2020-01-06T10:14:22Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=137167#p137167</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Gdip - вырезание]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=137144#p137144" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2020-01-04T11:47:06Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=137144#p137144</id>
		</entry>
</feed>
