{"id":455,"date":"2009-07-23T07:57:03","date_gmt":"2009-07-23T10:57:03","guid":{"rendered":"http:\/\/leandroascierto.com\/blog\/?p=455"},"modified":"2011-08-27T08:25:35","modified_gmt":"2011-08-27T11:25:35","slug":"render-stretch","status":"publish","type":"post","link":"https:\/\/leandroascierto.com\/blog\/render-stretch\/","title":{"rendered":"Render Stretch"},"content":{"rendered":"<p style=\"text-align: justify;\">Esta es una funci\u00f3n que sirve para pintar una im\u00e1gen de forma ampliada pero manteniendo su contorno original, para que se entienda, cuando utilizamos PaintPicture o StretchBlt en una im\u00e1gen, \u00e9sta se estira proporcionalmente y en un caso como \u00e9ste (im\u00e1gen) el borde del bot\u00f3n se deformar\u00eda, en esta funci\u00f3n debe pasarse un par\u00e1metro en el cual debe indicarse un ancho\/alto en com\u00fan para los bordes.<\/p>\n<div><img decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/www.leandroascierto.com\/blog\/imagenes\/RenderStretch.png\" alt=\"RenderStrecht\" \/><\/div>\n<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nOption Explicit\r\n\r\n' -------------------------------------------------\r\n' Autor: Leandro Ascierto\r\n' Web:   www.leandroascierto.com.ar\r\n' -------------------------------------------------\r\n\r\nPrivate Declare Function StretchBlt Lib &quot;gdi32.dll&quot; (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long\r\nPrivate Declare Function SetStretchBltMode Lib &quot;gdi32.dll&quot; (ByVal hdc As Long, ByVal nStretchMode As Long) As Long\r\nPrivate Declare Function BitBlt Lib &quot;gdi32.dll&quot; (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long\r\nPrivate Declare Function CreateCompatibleDC Lib &quot;gdi32.dll&quot; (ByVal hdc As Long) As Long\r\nPrivate Declare Function CreateCompatibleBitmap Lib &quot;gdi32.dll&quot; (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long\r\nPrivate Declare Function DeleteObject Lib &quot;gdi32.dll&quot; (ByVal hObject As Long) As Long\r\nPrivate Declare Function DeleteDC Lib &quot;gdi32.dll&quot; (ByVal hdc As Long) As Long\r\nPrivate Declare Function GdiTransparentBlt Lib &quot;gdi32.dll&quot; (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal crTransparent As Long) As Boolean\r\nPrivate Declare Function GetDC Lib &quot;user32.dll&quot; (ByVal hwnd As Long) As Long\r\nPrivate Declare Function SelectObject Lib &quot;gdi32.dll&quot; (ByVal hdc As Long, ByVal hObject As Long) As Long\r\n  \r\nPrivate Function RenderStretchFromDC(ByVal DestDC As Long, _\r\n                                ByVal DestX As Long, _\r\n                                ByVal DestY As Long, _\r\n                                ByVal DestW As Long, _\r\n                                ByVal DestH As Long, _\r\n                                ByVal SrcDC As Long, _\r\n                                ByVal x As Long, _\r\n                                ByVal y As Long, _\r\n                                ByVal Width As Long, _\r\n                                ByVal Height As Long, _\r\n                                ByVal Size As Long, _\r\n                                Optional MaskColor As Long = -1)\r\n \r\nDim Sx2 As Long\r\n \r\nSx2 = Size * 2\r\n \r\nIf MaskColor &lt;&gt; -1 Then\r\n    Dim mDC         As Long\r\n    Dim mX          As Long\r\n    Dim mY          As Long\r\n    Dim DC          As Long\r\n    Dim hBmp        As Long\r\n    Dim hOldBmp     As Long\r\n \r\n    mDC = DestDC\r\n    DC = GetDC(0)\r\n    DestDC = CreateCompatibleDC(0)\r\n    hBmp = CreateCompatibleBitmap(DC, DestW, DestH)\r\n    hOldBmp = SelectObject(DestDC, hBmp) ' save the original BMP for later reselection\r\n    mX = DestX: mY = DestY\r\n    DestX = 0: DestY = 0\r\nEnd If\r\n \r\nSetStretchBltMode DestDC, vbPaletteModeNone\r\n \r\nBitBlt DestDC, DestX, DestY, Size, Size, SrcDC, x, y, vbSrcCopy  'TOP_LEFT\r\nStretchBlt DestDC, DestX + Size, DestY, DestW - Sx2, Size, SrcDC, x + Size, y, Width - Sx2, Size, vbSrcCopy 'TOP_CENTER\r\nBitBlt DestDC, DestX + DestW - Size, DestY, Size, Size, SrcDC, x + Width - Size, y, vbSrcCopy 'TOP_RIGHT\r\nStretchBlt DestDC, DestX, DestY + Size, Size, DestH - Sx2, SrcDC, x, y + Size, Size, Height - Sx2, vbSrcCopy 'MID_LEFT\r\nStretchBlt DestDC, DestX + Size, DestY + Size, DestW - Sx2, DestH - Sx2, SrcDC, x + Size, y + Size, Width - Sx2, Height - Sx2, vbSrcCopy 'MID_CENTER\r\nStretchBlt DestDC, DestX + DestW - Size, DestY + Size, Size, DestH - Sx2, SrcDC, x + Width - Size, y + Size, Size, Height - Sx2, vbSrcCopy 'MID_RIGHT\r\nBitBlt DestDC, DestX, DestY + DestH - Size, Size, Size, SrcDC, x, y + Height - Size, vbSrcCopy 'BOTTOM_LEFT\r\nStretchBlt DestDC, DestX + Size, DestY + DestH - Size, DestW - Sx2, Size, SrcDC, x + Size, y + Height - Size, Width - Sx2, Size, vbSrcCopy   'BOTTOM_CENTER\r\nBitBlt DestDC, DestX + DestW - Size, DestY + DestH - Size, Size, Size, SrcDC, x + Width - Size, y + Height - Size, vbSrcCopy 'BOTTOM_RIGHT\r\n\r\nIf MaskColor &lt;&gt; -1 Then\r\n    GdiTransparentBlt mDC, mX, mY, DestW, DestH, DestDC, 0, 0, DestW, DestH, MaskColor\r\n    SelectObject DestDC, hOldBmp\r\n    DeleteObject hBmp\r\n    DeleteDC DC\r\n    DeleteDC DestDC\r\nEnd If\r\n \r\nEnd Function \r\n \r\nPrivate Function RenderStretchFromPicture(ByVal DestDC As Long, _\r\n                                ByVal DestX As Long, _\r\n                                ByVal DestY As Long, _\r\n                                ByVal DestW As Long, _\r\n                                ByVal DestH As Long, _\r\n                                ByVal SrcPicture As StdPicture, _\r\n                                ByVal x As Long, _\r\n                                ByVal y As Long, _\r\n                                ByVal Width As Long, _\r\n                                ByVal Height As Long, _\r\n                                ByVal Size As Long, _\r\n                                Optional MaskColor As Long = -1)\r\n \r\n    Dim DC          As Long\r\n    Dim hOldBmp     As Long\r\n \r\n    DC = CreateCompatibleDC(0)\r\n    hOldBmp = SelectObject(DC, SrcPicture.Handle)\r\n \r\n    RenderStretchFromDC DestDC, DestX, DestY, DestW, DestH, DC, x, y, Width, Height, Size, MaskColor \r\n\r\n    hOldBmp = SelectObject(DC, hOldBmp)\r\n    DeleteDC DC\r\n\r\nEnd Function\r\n<\/pre>\n<\/p>\n<p align=\"center\"><a href=\"https:\/\/leandroascierto.com\/blog\/descarga.php?url=RenderStretch.zip\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" title=\"Descargar\" src=\"https:\/\/leandroascierto.com\/blog\/descarga.php?file=RenderStretch.zip\" alt=\"\" width=\"280\" height=\"61\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Esta es una funci\u00f3n que sirve para pintar una im\u00e1gen de forma ampliada pero manteniendo su contorno original, para que se entienda, cuando utilizamos PaintPicture o StretchBlt en una im\u00e1gen, \u00e9sta se estira proporcionalmente y en un caso como \u00e9ste (im\u00e1gen) el borde del bot\u00f3n se deformar\u00eda, en esta funci\u00f3n debe pasarse un par\u00e1metro en <a href='https:\/\/leandroascierto.com\/blog\/render-stretch\/' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[41],"tags":[77,73,78],"class_list":["post-455","post","type-post","status-publish","format-standard","hentry","category-graficos","tag-bitblt","tag-gdi32","tag-stretchblt","category-41-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"_links":{"self":[{"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/posts\/455","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/comments?post=455"}],"version-history":[{"count":4,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/posts\/455\/revisions"}],"predecessor-version":[{"id":518,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/posts\/455\/revisions\/518"}],"wp:attachment":[{"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/media?parent=455"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/categories?post=455"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/tags?post=455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}