<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: Gdi+ bitmap из bitmap]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=14478</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=14478&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Gdi+ bitmap из bitmap».]]></description>
		<lastBuildDate>Fri, 18 Jan 2019 08:52:23 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: Gdi+ bitmap из bitmap]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=131385#p131385</link>
			<description><![CDATA[<p>ИМХО использовать тормознутый gdi для скоростной обработки изображений не самый лучший вариант.</p>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Fri, 18 Jan 2019 08:52:23 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=131385#p131385</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Gdi+ bitmap из bitmap]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=131340#p131340</link>
			<description><![CDATA[<p>Ошибка до такой степени проста..<br /></p><div class="codebox"><pre><code>GDI_CreateBitmapFromFile(...w=0...)
...
H:=File_Open(&quot;Read&quot;,dir)
...
msgbox % h &quot;==&quot; H
</code></pre></div><p>UPDATE:<br />Даже при таком раскладе на выходе 266ms. <img src="//forum.script-coding.com/img/smilies/sad.png" width="15" height="15" /><br /></p><div class="codebox"><pre><code>GDI_CreateBitmapFromFile(dir,w=0,h=0,bkg=0) {
	if(w&lt;=0 || h&lt;=0)
		return bitmap:=Gdip_CreateBitmapFromFile(dir)
	handle:=File_Open(&quot;Read&quot;,dir),size:=File_Read(handle,data,File_Size(handle)),File_Close(handle)

	hData := DllCall(&quot;GlobalAlloc&quot;, &quot;UInt&quot;,2, &quot;UInt&quot;,size)
    pData := DllCall(&quot;GlobalLock&quot;, &quot;UInt&quot;,hData, &quot;Ptr&quot;)
    DllCall(&quot;RtlMoveMemory&quot;, &quot;Ptr&quot;,pData, &quot;Ptr&quot;,&amp;data, &quot;UInt&quot;,size)
    DllCall(&quot;GlobalUnlock&quot;, &quot;UInt&quot;,hData)
    rc3 := DllCall(&quot;ole32\CreateStreamOnHGlobal&quot;, &quot;UInt&quot;,hData, &quot;Int&quot;,True, &quot;Ptr*&quot;,pStream)

	DllCall(&quot;gdiplus\GdipCreateBitmapFromStream&quot;, &quot;UPtr&quot;, pStream, &quot;UPtr*&quot;, pBitmap, &quot;UInt&quot;)


	bOut:=Gdip_CreateBitmap(w,h)
	graphics:=Gdip_GraphicsFromImage(bOut)
	if(bkg)
		pBrush:=Gdip_BrushCreateSolid(bkg)
		,Gdip_FillRectangle(graphics,pBrush,0,0,w,h) ;for Transparence ;TO_EDIT (need +1?)
		,Gdip_DeleteBrush(pBrush)

	start:=A_TickCount
	Gdip_DrawImage(graphics,pBitmap, 0,0,w,h,0,0,Gdip_GetImageWidth(pBitmap),Gdip_GetImageHeight(pBitmap),1)
	msgbox % A_TickCount-start &quot;ms&quot;
	Gdip_DeleteGraphics(graphics)
	Gdip_DisposeImage(bitmap)
	return bOut
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (MandarinKa02)]]></author>
			<pubDate>Thu, 17 Jan 2019 12:41:59 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=131340#p131340</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Gdi+ bitmap из bitmap]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=131338#p131338</link>
			<description><![CDATA[<p>В pBitmap получаю загружаемое изображение. Проверял через Gdip_SaveBitmapToFile()</p>]]></description>
			<author><![CDATA[null@example.com (MandarinKa02)]]></author>
			<pubDate>Thu, 17 Jan 2019 12:08:15 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=131338#p131338</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Gdi+ bitmap из bitmap]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=131326#p131326</link>
			<description><![CDATA[<p>Проверяйте, что получаете в pBitmap.</p>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Thu, 17 Jan 2019 08:40:18 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=131326#p131326</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Gdi+ bitmap из bitmap]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=131306#p131306</link>
			<description><![CDATA[<p>Из статьи понял, что bitmapFromStream не валидирует/валидейтит изображение.<br />Из этого вышла следующая функция: (недописанная)<br /></p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header" data-lang-open="открыть спойлер" data-lang-close="скрыть спойлер"><strong>+</strong>&nbsp;открыть спойлер</div><div class="fancy_spoiler"><div class="codebox"><pre><code>GDI_CreateBitmapFromFile(dir,w=0,h=0,bkg=0) {
	bOut:=Gdip_CreateBitmap(w,h)
	graphics:=Gdip_GraphicsFromImage(bOut)

		start:=A_TickCount
	;Gdip_SetInterpolationMode(graphics,5)
	;Gdip_BitmapSetResolution()
	H:=File_Open(&quot;Read&quot;,dir)
	size:=File_Read(H,data,File_Size(H))

	hData := DllCall(&quot;GlobalAlloc&quot;, &quot;UInt&quot;,2, &quot;UInt&quot;,size)
    pData := DllCall(&quot;GlobalLock&quot;, &quot;UInt&quot;,hData, &quot;Ptr&quot;)
    DllCall(&quot;RtlMoveMemory&quot;, &quot;Ptr&quot;,pData, &quot;Ptr&quot;,&amp;data, &quot;UInt&quot;,size)
    DllCall(&quot;GlobalUnlock&quot;, &quot;UInt&quot;,hData)
    rc3 := DllCall(&quot;ole32\CreateStreamOnHGlobal&quot;, &quot;UInt&quot;,hData, &quot;Int&quot;,True, &quot;Ptr*&quot;,pStream)

	DllCall(&quot;gdiplus\GdipCreateBitmapFromStream&quot;, &quot;UPtr&quot;, pStream, &quot;UPtr*&quot;, pBitmap, &quot;UInt&quot;) &quot;`nh=&quot; H
	;DllCall(&quot;gdiplus\GdipImageForceValidation&quot;, Ptr, pBitmap)
	;Gdip_SetInterpolationMode(graphics,1)
	;Gdip_SetSmoothingMode(graphics,3)
	Gdip_DrawImage(graphics,pBitmap, 0,0,w,h,0,0,Gdip_GetImageWidth(pBitmap),Gdip_GetImageHeight(pBitmap),1)
	msgbox % A_TickCount-start &quot;ms&quot;
	Gdip_DeleteGraphics(graphics)
	Gdip_DisposeImage(bitmap)
	return bOut
}














File_Open(sType, sFile) {

	bRead := InStr(sType, &quot;READ&quot;)
	bSeq  := sType = &quot;READSEQ&quot;

	;Open the file for writing with GENERIC_WRITE/GENERIC_READ, NO SHARING/FILE_SHARE_READ &amp; FILE_SHARE_WRITE, and
	;OPEN_ALWAYS/OPEN_EXISTING, and FILE_FLAG_SEQUENTIAL_SCAN
	hFile := DllCall(&quot;CreateFile&quot;, &quot;Str&quot;, sFile, &quot;UInt&quot;, bRead ? 0x80000000 : 0x40000000, &quot;UInt&quot;, bRead ? 3 : 0, &quot;Ptr&quot;, 0
								 , &quot;UInt&quot;, bRead ? 3 : 4, &quot;UInt&quot;, bSeq ? 0x08000000 : 0, &quot;Ptr&quot;, 0, &quot;Ptr&quot;)
	If (hFile=-1 || ErrorLevel) { ;Check for any error other than ERROR_FILE_EXISTS
		ErrorLevel := ErrorLevel ? ErrorLevel : A_LastError
		Return 0 ;Return INVALID_HANDLE_VALUE
	} Else Return hFile
}

File_Read(hFile, ByRef bData, iLength = 0, bPtr=0) {

	;Check if we&#039;re reading up to the rest of the file
	If Not iLength ;Set the length equal to the remaining part of the file
		iLength := File_Size(hFile) - File_Pointer(hFile)

	;Prep the variable
	if(!bPtr)
	VarSetCapacity(bData, iLength, 0)

	;Read the file
	r := DllCall(&quot;ReadFile&quot;, &quot;Ptr&quot;, hFile, &quot;Ptr&quot;, (bPtr?bData:&amp;bData), &quot;UInt&quot;, iLength, &quot;UInt*&quot;, iLengthRead, &quot;Ptr&quot;, 0)
	If (Not r Or ErrorLevel) {
		ErrorLevel := ErrorLevel ? ErrorLevel : A_LastError
		Return 0
	} Else Return iLengthRead
}

File_Size(hFile) {
	r := DllCall(&quot;GetFileSizeEx&quot;, &quot;Ptr&quot;, hFile, &quot;Int64*&quot;, iFileSize)
	If (Not r Or ErrorLevel) {
		ErrorLevel := ErrorLevel ? ErrorLevel : A_LastError
		Return 0
	} Else Return iFileSize
}
</code></pre></div></div></div><p>Прирост производительности значителен, теперь 40-70мс. Похоже, получилось. <br />Но, один дефект таки имеется: функция не уменьшает изображения соблюдая пропорции, а как-то криво его обрезает.<br /><a href="https://imgur.com/a/etjFt0q">*тык*</a></p>]]></description>
			<author><![CDATA[null@example.com (MandarinKa02)]]></author>
			<pubDate>Wed, 16 Jan 2019 18:43:46 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=131306#p131306</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Gdi+ bitmap из bitmap]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=131188#p131188</link>
			<description><![CDATA[<p>Спасибо за наводку.<br /></p><div class="quotebox"><blockquote><p>У меня с изменением InterpolationMode на NearestNeighbor скорость увеличилась.</p></blockquote></div><p>Тоже пробовал с этим играться, скорость обработки уменьшилась на 20мс. (220-230мс)</p>]]></description>
			<author><![CDATA[null@example.com (MandarinKa02)]]></author>
			<pubDate>Mon, 14 Jan 2019 10:39:34 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=131188#p131188</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Gdi+ bitmap из bitmap]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=131182#p131182</link>
			<description><![CDATA[<p>Думаю не в этом дело.<br />Похоже зависит от многих факторов, например того каким способом загружаете картинку.<br />Изучайте и тестируйте (5 частей).<br /><a href="https://photosauce.net/blog/post/image-scaling-with-gdi-part-1-introducing-the-reference-resizer">https://photosauce.net/blog/post/image- … ce-resizer</a><br />У меня с изменением InterpolationMode на NearestNeighbor скорость увеличилась.<br />А если одну и ту же картинку требуется переконвертировать в несколько размеров, то скорость заметно увеличится если картинку предварительно форсированно отвалидейтить.<br /></p><div class="codebox"><pre><code>DllCall(&quot;gdiplus\GdipImageForceValidation&quot;, Ptr, bitmap)
loop 10
{
   bOut%A_Index%:=Gdip_CreateBitmap(w+A_Index,h+A_Index)
   graphics%A_Index%:=Gdip_GraphicsFromImage(bOut%A_Index%)
   Gdip_DrawImage(graphics%A_Index%,bitmap, 0,0,w,h,0,0,Gdip_GetImageWidth(bitmap),Gdip_GetImageHeight(bitmap),1)
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Mon, 14 Jan 2019 05:00:00 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=131182#p131182</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Gdi+ bitmap из bitmap]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=131170#p131170</link>
			<description><![CDATA[<p>Функция GdipDrawImageRectRect.<br />Скачал <a href="https://github.com/tariqporter/Gdip/blob/master/gdiplus.dll">*тут*</a> библиотеку и подгрузил ее через LoadLibrary.<br />Результат тот же.<br />Подумал, может все равно использует другую библиотеку? Так, похоже, и оказалось. Через ProcessMonitor видно, что подгружает gdiplus.dll из другого источника.<br /><span class="postimg"><img src="https://i.imgur.com/F1buStw.png" alt="https://i.imgur.com/F1buStw.png" /></span></p>]]></description>
			<author><![CDATA[null@example.com (MandarinKa02)]]></author>
			<pubDate>Sun, 13 Jan 2019 14:52:37 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=131170#p131170</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Gdi+ bitmap из bitmap]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=130920#p130920</link>
			<description><![CDATA[<p>Я бы посмотрел у какой функции&nbsp; dll идут тормоза. После чего уже можно гуглить, можно ли ее чем-то заменить или поправить,чтобы увеличить скорость.</p>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Tue, 08 Jan 2019 22:54:12 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=130920#p130920</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Gdi+ bitmap из bitmap]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=130916#p130916</link>
			<description><![CDATA[<p>P.P.S. забыл уточнить. Конвертирую изображение размером 4160х2340 в 72х72(или около-того).</p>]]></description>
			<author><![CDATA[null@example.com (MandarinKa02)]]></author>
			<pubDate>Tue, 08 Jan 2019 16:53:06 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=130916#p130916</guid>
		</item>
		<item>
			<title><![CDATA[AHK: Gdi+ bitmap из bitmap]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=130908#p130908</link>
			<description><![CDATA[<p>Есть следующая функция:<br /></p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header" data-lang-open="открыть спойлер" data-lang-close="скрыть спойлер"><strong>+</strong>&nbsp;открыть спойлер</div><div class="fancy_spoiler"><div class="codebox"><pre><code>
GDI_CreateBitmapFromFile(dir,w=0,h=0,bkg=0) {
	bitmap:=Gdip_CreateBitmapFromFile(dir)
	if(w&lt;=0 || h&lt;=0)
		return bitmap
	bOut:=Gdip_CreateBitmap(w,h)
	graphics:=Gdip_GraphicsFromImage(bOut)

	if(bkg)
		pBrush:=Gdip_BrushCreateSolid(bkg)
		,Gdip_FillRectangle(graphics,pBrush,0,0,w,h) ;for Transparence ;TO_EDIT (need +1?)
		,Gdip_DeleteBrush(pBrush)

		start:=A_TickCount
	Gdip_DrawImage(graphics,bitmap, 0,0,w,h,0,0,Gdip_GetImageWidth(bitmap),Gdip_GetImageHeight(bitmap),1)
	msgbox % A_TickCount-start &quot;ms&quot; &quot;`nuo&quot;
	Gdip_DeleteGraphics(graphics)
	Gdip_DisposeImage(bitmap)
	return bOut
}</code></pre></div></div></div><p>Если помимо директории файла, указать длину и ширину, то функция уменьшит/увеличит изображение, сохраняя пропорции.<br />MsgBox при этом выводит около 265мс, что не есть хорошо.<br />Кто-то сталкивался с таким, и если нет, подкиньте, пожалуйста документацию по этому поводу.</p><p><span style="color: gray">P.S. используемая <a href="https://www.autohotkey.com/boards/viewtopic.php?t=6517">библиотека</a></span></p>]]></description>
			<author><![CDATA[null@example.com (MandarinKa02)]]></author>
			<pubDate>Mon, 07 Jan 2019 19:59:33 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=130908#p130908</guid>
		</item>
	</channel>
</rss>
