<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Поместить изображение по ссылке в буфер обмена]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=18082&amp;type=atom" />
	<updated>2024-02-04T13:51:51Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=18082</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поместить изображение по ссылке в буфер обмена]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=160216#p160216" />
			<content type="html"><![CDATA[<p>Да, заметил тоже, в некоторые приложения второй вариант вставляется некорректно, позже попробую исправить.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2024-02-04T13:51:51Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=160216#p160216</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поместить изображение по ссылке в буфер обмена]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=160214#p160214" />
			<content type="html"><![CDATA[<p><a href="https://forum.script-coding.com/viewtopic.php?pid=160198#p160198">Второй вариант</a> в стандартном Paint (Win 10) всё нормально вставляется. В старом v3.31 ошибка (установлен был на жёсткий диск с Win 7 вроде ~2013г):<br /></p><div class="quotebox"><blockquote><p>Paint.NET<br />Изображение в Буфере обмена не удается распознать. Попробуйте скопировать его еще раз с помощью приложения, через которое оно было получено.</p></blockquote></div><p><a href="https://forum.script-coding.com/viewtopic.php?pid=160181#p160181">Первый вариант</a> работает в обоих версиях Paint.</p>]]></content>
			<author>
				<name><![CDATA[__Михаил__]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=40928</uri>
			</author>
			<updated>2024-02-04T12:31:18Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=160214#p160214</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поместить изображение по ссылке в буфер обмена]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=160205#p160205" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Phoenixxx_Czar пишет:</cite><blockquote><p>А без GDIp можно как-то?</p></blockquote></div><p>А почему спросили, разве GDIp может не быть в системе?</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2024-02-03T11:07:47Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=160205#p160205</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поместить изображение по ссылке в буфер обмена]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=160198#p160198" />
			<content type="html"><![CDATA[<p>Вот так вышло без GDIp:<br /></p><div class="codebox"><pre><code>#Requires AutoHotkey v1

url := &quot;https://www.etonline.com/_next/image?url=https%3A%2F%2Fwww.etonline.com%2Fsites%2Fdefault%2Ffiles%2Fstyles%2F640x360%2Fpublic%2Fimages%2F2023-06%2FGettyImages-1258514215.jpg%3Fh%3D71ff8dab&amp;w=1024&amp;q=75&quot;
whr := ComObjCreate(&quot;WinHttp.WinHttpRequest.5.1&quot;)
whr.Open(&quot;GET&quot;, url, true)
whr.Send()
whr.WaitForResponse()
StreamToClipboard(whr.ResponseStream)

StreamToClipboard(Stream) {
    static flags := (GMEM_MOVEABLE := 0x2) | (GMEM_ZEROINIT := 0x40)
         , szBITMAP := 16 + A_PtrSize * 2, szBITMAPINFOHEADER := 40, CF_DIB := 0x8
         , IID_IStream := &quot;{0000000C-0000-0000-C000-000000000046}&quot;

    DllCall(&quot;Ole32\GetHGlobalFromStream&quot;, &quot;Ptr&quot;, IStream := ComObjQuery(Stream, IID_IStream), &quot;PtrP&quot;, pData)

    DllCall(&quot;OpenClipboard&quot;, &quot;Ptr&quot;, A_ScriptHwnd)
    DllCall(&quot;EmptyClipboard&quot;)

    pngFormat := DllCall(&quot;RegisterClipboardFormat&quot;, &quot;Str&quot;, &quot;PNG&quot;)
    DllCall(&quot;SetClipboardData&quot;, &quot;UInt&quot;, pngFormat, &quot;Ptr&quot;, pData)

    hBitmap := HBitmapFromStream(IStream)
    VarSetCapacity(DIBSECTION, size := A_PtrSize = 4 ? 84 : 104, 0)
    DllCall(&quot;GetObject&quot;, &quot;Ptr&quot;, hBitmap, &quot;Int&quot;, size, &quot;Ptr&quot;, &amp;DIBSECTION)
    dataSize := NumGet(DIBSECTION, szBITMAP + 20, &quot;UInt&quot;)
    objSize := szBITMAPINFOHEADER + dataSize
    hObj := DllCall(&quot;GlobalAlloc&quot;, &quot;UInt&quot;, flags, &quot;Ptr&quot;, objSize, &quot;Ptr&quot;)
    pObj := DllCall(&quot;GlobalLock&quot;, &quot;Ptr&quot;, hObj, &quot;Ptr&quot;)
    DllCall(&quot;RtlMoveMemory&quot;, &quot;Ptr&quot;, pObj, &quot;Ptr&quot;, &amp;DIBSECTION + szBITMAP, &quot;Ptr&quot;, szBITMAPINFOHEADER)
    DllCall(&quot;RtlMoveMemory&quot;, &quot;Ptr&quot;, pObj + szBITMAPINFOHEADER, &quot;Ptr&quot;, NumGet(DIBSECTION, 16 + A_PtrSize), &quot;Ptr&quot;, dataSize)
    NumPut(-NumGet(pObj + 8, &quot;Int&quot;), pObj + 8, &quot;Int&quot;)
    DllCall(&quot;SetClipboardData&quot;, &quot;UInt&quot;, CF_DIB, &quot;Ptr&quot;, hObj)

    DllCall(&quot;CloseClipboard&quot;)
    DllCall(&quot;DeleteObject&quot;, &quot;Ptr&quot;, hBitmap)
    ObjRelease(IStream)
}

HBitmapFromStream(IStream) {
    static CLSID_WICImagingFactory      := &quot;{CACAF262-9370-4615-A13B-9F5539DA4C0A}&quot;
         ,  IID_IWICImagingFactory      := &quot;{EC5EC8A9-C395-4314-9C77-54D7A935FF70}&quot;
         , GUID_WICPixelFormat32bppBGRA := &quot;{6FDDC324-4E03-4BFE-B185-3D77768DC90F}&quot;
         , opt := WICDecodeMetadataCacheOnDemand := 0

    IWICImagingFactory := ComObjCreate(CLSID_WICImagingFactory, IID_IWICImagingFactory)
    ; IWICImagingFactory::CreateDecoderFromFilename
    DllCall(NumGet(NumGet(IWICImagingFactory + 0) + A_PtrSize * 4), &quot;Ptr&quot;, IWICImagingFactory, &quot;Ptr&quot;, IStream
                                                                  , &quot;Ptr&quot;, 0, &quot;UInt&quot;, opt, &quot;PtrP&quot;, IWICBitmapDecoder)
    ; IWICBitmapDecoder::GetFrame
    DllCall(NumGet(NumGet(IWICBitmapDecoder + 0) + A_PtrSize * 13), &quot;Ptr&quot;, IWICBitmapDecoder, &quot;UInt&quot;, 0, &quot;PtrP&quot;, IWICBitmapFrameDecode)
    ; IWICBitmapFrameDecode::GetSize
    DllCall(NumGet(NumGet(IWICBitmapFrameDecode + 0) + A_PtrSize * 3), &quot;Ptr&quot;, IWICBitmapFrameDecode, &quot;UIntP&quot;, width, &quot;UIntP&quot;, height)

    VarSetCapacity(GUID, 16, 0)
    DllCall(&quot;Ole32\CLSIDFromString&quot;, &quot;WStr&quot;, GUID_WICPixelFormat32bppBGRA, &quot;Ptr&quot;, &amp;GUID)
    hr := DllCall(&quot;Windowscodecs\WICConvertBitmapSource&quot;, &quot;Ptr&quot;, &amp;GUID, &quot;Ptr&quot;, IWICBitmapFrameDecode, &quot;PtrP&quot;, DestBitmapFrameDecode)
    if (hr = 0)
        ObjRelease(IWICBitmapFrameDecode), IWICBitmapFrameDecode := DestBitmapFrameDecode

    stride := width * 4, size := stride * height, VarSetCapacity(buf, size, 0)
    ; IWICBitmapFrameDecode::CopyPixels
    DllCall(NumGet(NumGet(IWICBitmapFrameDecode + 0) + A_PtrSize * 7), &quot;Ptr&quot;, IWICBitmapFrameDecode, &quot;Ptr&quot;, 0, &quot;UInt&quot;, stride, &quot;UInt&quot;, size, &quot;Ptr&quot;, &amp;buf)
    hBitmap := CreateDIBSection(width, height, pBits)
    
    DllCall(&quot;RtlMoveMemory&quot;, &quot;Ptr&quot;, pBits, &quot;Ptr&quot;, &amp;buf, &quot;Ptr&quot;, size)
    for k, v in [ IWICBitmapFrameDecode, IWICBitmapDecoder, IWICImagingFactory ]
        ObjRelease(v)
    return hBitmap
}

CreateDIBSection(w, h, ByRef ppvBits := 0, bpp := 32) {
    hDC := DllCall(&quot;GetDC&quot;, &quot;Ptr&quot;, 0, &quot;Ptr&quot;)
    VarSetCapacity(BITMAPINFO, 40, 0)
    NumPut(40 , BITMAPINFO,  0)
    NumPut( w , BITMAPINFO,  4)
    NumPut(-h , BITMAPINFO,  8)
    NumPut( 1 , BITMAPINFO, 12)
    NumPut(bpp, BITMAPINFO, 14)
    hBM := DllCall(&quot;CreateDIBSection&quot;, &quot;Ptr&quot;, hDC, &quot;Ptr&quot;, &amp;BITMAPINFO, &quot;UInt&quot;, 0
                                     , &quot;PtrP&quot;, ppvBits, &quot;Ptr&quot;, 0, &quot;UInt&quot;, 0, &quot;Ptr&quot;)
    DllCall(&quot;ReleaseDC&quot;, &quot;Ptr&quot;, 0, &quot;Ptr&quot;, hDC)
    return hBM
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2024-02-01T12:21:51Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=160198#p160198</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поместить изображение по ссылке в буфер обмена]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=160186#p160186" />
			<content type="html"><![CDATA[<p>Наверняка можно, но на v1 наработок нет, могу посмотреть на v2.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2024-01-31T20:28:08Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=160186#p160186</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поместить изображение по ссылке в буфер обмена]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=160182#p160182" />
			<content type="html"><![CDATA[<p>А без GDIp можно как-то?</p>]]></content>
			<author>
				<name><![CDATA[Phoenixxx_Czar]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34426</uri>
			</author>
			<updated>2024-01-31T19:40:27Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=160182#p160182</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поместить изображение по ссылке в буфер обмена]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=160181#p160181" />
			<content type="html"><![CDATA[<p>На скорую руку как-то так:<br /></p><div class="codebox"><pre><code>#Requires AutoHotkey v1

url := &quot;https://www.etonline.com/_next/image?url=https%3A%2F%2Fwww.etonline.com%2Fsites%2Fdefault%2Ffiles%2Fstyles%2F640x360%2Fpublic%2Fimages%2F2023-06%2FGettyImages-1258514215.jpg%3Fh%3D71ff8dab&amp;w=1024&amp;q=75&quot;
whr := ComObjCreate(&quot;WinHttp.WinHttpRequest.5.1&quot;)
whr.Open(&quot;GET&quot;, url, true)
whr.Send()
whr.WaitForResponse()
StreamToClipboard(whr.ResponseStream)

StreamToClipboard(Stream) {
    static flags := (GMEM_MOVEABLE := 0x2) | (GMEM_ZEROINIT := 0x40)
         , szBITMAP := 16 + A_PtrSize*2, szBITMAPINFOHEADER := 40, CF_DIB := 0x8

    DllCall(&quot;Ole32\GetHGlobalFromStream&quot;, &quot;Ptr&quot;, ComObjValue(Stream), &quot;PtrP&quot;, pData)

    DllCall(&quot;OpenClipboard&quot;, &quot;Ptr&quot;, A_ScriptHwnd)
    DllCall(&quot;EmptyClipboard&quot;)

    pngFormat := DllCall(&quot;RegisterClipboardFormat&quot;, &quot;Str&quot;, &quot;PNG&quot;)
    DllCall(&quot;SetClipboardData&quot;, &quot;UInt&quot;, pngFormat, &quot;Ptr&quot;, pData)

    hBitmap := (new GDIp).HBitmapFromStream(Stream)
    VarSetCapacity(DIBSECTION, size := A_PtrSize = 4 ? 84 : 104, 0)
    DllCall(&quot;GetObject&quot;, &quot;Ptr&quot;, hBitmap, &quot;Int&quot;, size, &quot;Ptr&quot;, &amp;DIBSECTION)
    dataSize := NumGet(DIBSECTION, szBITMAP + 20, &quot;UInt&quot;)
    objSize := szBITMAPINFOHEADER + dataSize
    hObj := DllCall(&quot;GlobalAlloc&quot;, &quot;UInt&quot;, flags, &quot;Ptr&quot;, objSize, &quot;Ptr&quot;)
    pObj := DllCall(&quot;GlobalLock&quot;, &quot;Ptr&quot;, hObj, &quot;Ptr&quot;)
    DllCall(&quot;RtlMoveMemory&quot;, &quot;Ptr&quot;, pObj, &quot;Ptr&quot;, &amp;DIBSECTION + szBITMAP, &quot;Ptr&quot;, szBITMAPINFOHEADER)
    DllCall(&quot;RtlMoveMemory&quot;, &quot;Ptr&quot;, pObj + szBITMAPINFOHEADER, &quot;Ptr&quot;, NumGet(DIBSECTION, 16 + A_PtrSize), &quot;Ptr&quot;, dataSize)
    DllCall(&quot;SetClipboardData&quot;, &quot;UInt&quot;, CF_DIB, &quot;Ptr&quot;, hObj)

    DllCall(&quot;CloseClipboard&quot;)
    DllCall(&quot;DeleteObject&quot;, &quot;Ptr&quot;, hBitmap)
}

class GDIp {
    __New() {
        if !DllCall(&quot;GetModuleHandle&quot;, &quot;Str&quot;, &quot;gdiplus&quot;, &quot;Ptr&quot;)
            DllCall(&quot;LoadLibrary&quot;, &quot;Str&quot;, &quot;gdiplus&quot;)
        VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1)
        DllCall(&quot;gdiplus\GdiplusStartup&quot;, &quot;PtrP&quot;, pToken, &quot;Ptr&quot;, &amp;si, &quot;Ptr&quot;, 0)
        this.token := pToken
    }

    __Delete() {
        DllCall(&quot;gdiplus\GdiplusShutdown&quot;, &quot;Ptr&quot;, this.token)
        if hModule := DllCall(&quot;GetModuleHandle&quot;, &quot;Str&quot;, &quot;gdiplus&quot;, &quot;Ptr&quot;)
            DllCall(&quot;FreeLibrary&quot;, &quot;Ptr&quot;, hModule)
    }

    HBitmapFromStream(Stream) {
        pIStream := ComObjQuery(Stream, &quot;{0000000C-0000-0000-C000-000000000046}&quot;)
        DllCall(&quot;gdiplus\GdipCreateBitmapFromStream&quot;, &quot;Ptr&quot;, pIStream, &quot;PtrP&quot;, pBitmap)
        ObjRelease(pIStream)
        DllCall(&quot;gdiplus\GdipCreateHBITMAPFromBitmap&quot;, &quot;Ptr&quot;, pBitmap, &quot;PtrP&quot;, hBitmap, &quot;UInt&quot;, 0xFFFFFFFF)
        DllCall(&quot;gdiplus\GdipDisposeImage&quot;, &quot;Ptr&quot;, pBitmap)
        Return hBitmap
    }
}</code></pre></div><p>Не факт, что тут всё идеально корректно, давно не пишу сложных кодов на AHK v1.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2024-01-31T19:35:18Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=160181#p160181</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Поместить изображение по ссылке в буфер обмена]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=160177#p160177" />
			<content type="html"><![CDATA[<p>Мне необходимо поместить изображение в буфер обмена, я пытаюсь сделать это следующим кодом:</p><div class="codebox"><pre><code>
hObject:=comObjCreate(&quot;WinHttp.WinHttpRequest.5.1&quot;)
hObject.open(&quot;GET&quot;, &quot;https://www.etonline.com/_next/image?url=https%3A%2F%2Fwww.etonline.com%2Fsites%2Fdefault%2Ffiles%2Fstyles%2F640x360%2Fpublic%2Fimages%2F2023-06%2FGettyImages-1258514215.jpg%3Fh%3D71ff8dab&amp;w=1024&amp;q=75&quot;)

hObject.send()
clipboard := hObject.responseBody
</code></pre></div><p>Но получаю ошибку, что hObject.responseBody является объектом.<br />Пытался найти другие способы это сделать, допустим так:<br /></p><div class="codebox"><pre><code>
hObject:=comObjCreate(&quot;WinHttp.WinHttpRequest.5.1&quot;)
hObject.open(&quot;GET&quot;, &quot;https://www.etonline.com/_next/image?url=https%3A%2F%2Fwww.etonline.com%2Fsites%2Fdefault%2Ffiles%2Fstyles%2F640x360%2Fpublic%2Fimages%2F2023-06%2FGettyImages-1258514215.jpg%3Fh%3D71ff8dab&amp;w=1024&amp;q=75&quot;)

hObject.send()
copyImage(hObject.responseBody)

copyImage(rawImage)
{
	hMem := DllCall(&quot;GlobalAlloc&quot;, &quot;UInt&quot;, 0x42, &quot;Ptr&quot;, rawImage.MaxIndex() + 1)
    pMem := DllCall(&quot;GlobalLock&quot;, &quot;Ptr&quot;, hMem, &quot;Ptr&quot;)
    DllCall(&quot;RtlMoveMemory&quot;, &quot;Ptr&quot;, pMem, &quot;Ptr&quot;, &amp;rawImage, &quot;Ptr&quot;, rawImage.MaxIndex() + 1)
    DllCall(&quot;GlobalUnlock&quot;, &quot;Ptr&quot;, hMem)
    DllCall(&quot;OpenClipboard&quot;, &quot;Ptr&quot;, 0)
    DllCall(&quot;EmptyClipboard&quot;)
    DllCall(&quot;SetClipboardData&quot;, &quot;UInt&quot;, 2, &quot;Ptr&quot;, hMem)
    DllCall(&quot;CloseClipboard&quot;)
}
</code></pre></div><p>Но ничего не происходит.</p><p>Важно! Я НЕ хочу чтобы изображение сначала сохранялось в файл.</p>]]></content>
			<author>
				<name><![CDATA[Phoenixxx_Czar]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34426</uri>
			</author>
			<updated>2024-01-31T18:26:02Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=160177#p160177</id>
		</entry>
</feed>
