{"id":461,"date":"2009-08-01T08:08:31","date_gmt":"2009-08-01T11:08:31","guid":{"rendered":"http:\/\/leandroascierto.com\/blog\/?p=461"},"modified":"2011-08-27T08:23:57","modified_gmt":"2011-08-27T11:23:57","slug":"render-stretch-plus","status":"publish","type":"post","link":"https:\/\/leandroascierto.com\/blog\/render-stretch-plus\/","title":{"rendered":"Render Stretch Plus"},"content":{"rendered":"<p style=\"text-align: justify;\">Igual que la funci\u00f3n superior esta sirve para pintar una im\u00e1gen de forma ampliada pero manteniendo su contorno original utilizando\u00a0<strong>GDI PLUS<\/strong>, esto nos da como ventaja poder utilizar gr\u00e1ficos .PNG entre otros. N\u00f3tese que si ponemos el form con AutoRedraw = True la funci\u00f3n trabaja m\u00e1s r\u00e1pido.<\/p>\n<div><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/www.leandroascierto.com\/blog\/imagenes\/RenderStretchPlus.png\" alt=\"RenderStrechtPlus\" width=\"383\" height=\"273\" \/><\/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\nPrivate Declare Function GdipDrawImageRectRectI Lib &quot;gdiplus&quot; (ByVal hGraphics As Long, ByVal hImage As Long, ByVal dstX As Long, ByVal dstY As Long, ByVal dstWidth As Long, ByVal dstHeight As Long, ByVal SrcX As Long, ByVal SrcY As Long, ByVal SrcWidth As Long, ByVal SrcHeight As Long, ByVal srcUnit As Long, Optional ByVal imageAttributes As Long = 0, Optional ByVal Callback As Long = 0, Optional ByVal CallbackData As Long = 0) As Long\r\nPrivate Declare Function GdipSetInterpolationMode Lib &quot;gdiplus&quot; (ByVal graphics As Long, ByVal InterpolationMode As Long) As Long\r\nPrivate Declare Function GdipSetPixelOffsetMode Lib &quot;gdiplus&quot; (ByVal graphics As Long, ByVal PixelOffsetMode As Long) As Long\r\nPrivate Declare Function GdipCreateFromHDC Lib &quot;gdiplus&quot; (ByVal hdc As Long, ByRef graphics As Long) As Long\r\nPrivate Declare Function GdipDeleteGraphics Lib &quot;gdiplus&quot; (ByVal graphics As Long) As Long\r\nPrivate Declare Function GdipLoadImageFromFile Lib &quot;gdiplus&quot; (ByVal FileName As Long, ByRef image As Long) As Long\r\nPrivate Declare Function GdiplusStartup Lib &quot;gdiplus&quot; (ByRef token As Long, ByRef lpInput As GDIPlusStartupInput, Optional ByRef lpOutput As Any) As Long\r\nPrivate Declare Function GdiplusShutdown Lib &quot;gdiplus&quot; (ByVal token As Long) As Long\r\nPrivate Declare Function GdipDisposeImage Lib &quot;gdiplus&quot; (ByVal image As Long) As Long\r\n \r\nPrivate Type GDIPlusStartupInput\r\n    GdiPlusVersion                      As Long\r\n    DebugEventCallback                  As Long\r\n    SuppressBackgroundThread            As Long\r\n    SuppressExternalCodecs              As Long\r\nEnd Type\r\n \r\nPrivate Const GdiPlusVersion                        As Long = 1&amp;\r\nPrivate Const QualityModeHigh                       As Long = 2&amp;\r\nPrivate Const InterpolationModeNearestNeighbor      As Long = QualityModeHigh + 3\r\nPrivate Const PixelOffsetModeHalf                   As Long = QualityModeHigh + 2\r\n \r\nDim GdipToken As Long\r\nDim m_hImage As Long\r\n  \r\nPrivate Sub RenderStretchPlus(ByVal DestHdc 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 hImage 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 \r\n \r\n    Dim hGraphics As Long\r\n    Dim Sx2 As Long\r\n \r\n    Sx2 = Size * 2\r\n \r\n    If GdipCreateFromHDC(DestHdc, hGraphics) = 0 Then\r\n        Call GdipSetInterpolationMode(hGraphics, InterpolationModeNearestNeighbor)\r\n        Call GdipSetPixelOffsetMode(hGraphics, PixelOffsetModeHalf)\r\n \r\n        GdipDrawImageRectRectI hGraphics, hImage, DestX, DestY, Size, Size, x, y, Size, Size, &amp;H2, 0&amp;, 0&amp;, 0&amp; 'TOP_LEFT\r\n        GdipDrawImageRectRectI hGraphics, hImage, DestX + Size, DestY, DestW - Sx2, Size, x + Size, y, Width - Sx2, Size, &amp;H2, 0&amp;, 0&amp;, 0&amp; 'TOP_CENTER\r\n        GdipDrawImageRectRectI hGraphics, hImage, DestX + DestW - Size, DestY, Size, Size, x + Width - Size, y, Size, Size, &amp;H2, 0&amp;, 0&amp;, 0&amp; 'TOP_RIGHT\r\n        GdipDrawImageRectRectI hGraphics, hImage, DestX, DestY + Size, Size, DestH - Sx2, x, y + Size, Size, Height - Sx2, &amp;H2, 0&amp;, 0&amp;, 0&amp; 'MID_LEFT\r\n        GdipDrawImageRectRectI hGraphics, hImage, DestX + Size, DestY + Size, DestW - Sx2, DestH - Sx2, x + Size, y + Size, Width - Sx2, Height - Sx2, &amp;H2, 0&amp;, 0&amp;, 0&amp; 'MID_CENTER\r\n        GdipDrawImageRectRectI hGraphics, hImage, DestX + DestW - Size, DestY + Size, Size, DestH - Sx2, x + Width - Size, y + Size, Size, Height - Sx2, &amp;H2, 0&amp;, 0&amp;, 0&amp; 'MID_RIGHT\r\n        GdipDrawImageRectRectI hGraphics, hImage, DestX, DestY + DestH - Size, Size, Size, x, y + Height - Size, Size, Size, &amp;H2, 0&amp;, 0&amp;, 0&amp; 'BOTTOM_LEFT\r\n        GdipDrawImageRectRectI hGraphics, hImage, DestX + Size, DestY + DestH - Size, DestW - Sx2, Size, x + Size, y + Height - Size, Width - Sx2, Size, &amp;H2, 0&amp;, 0&amp;, 0&amp; 'BOTTOM_CENTER\r\n        GdipDrawImageRectRectI hGraphics, hImage, DestX + DestW - Size, DestY + DestH - Size, Size, Size, x + Width - Size, y + Height - Size, Size, Size, &amp;H2, 0&amp;, 0&amp;, 0&amp; 'BOTTOM_RIGHT\r\n\r\n        Call GdipDeleteGraphics(hGraphics)\r\n    End If\r\n \r\nEnd Sub\r\n \r\nPrivate Sub RenderPlusFromFile(ByVal DestHdc 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 FileName As String, _\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\nDim hImg As Long\r\n \r\nCall GdipLoadImageFromFile(StrPtr(FileName), hImg)\r\nCall RenderStretchPlus(DestHdc, DestX, DestY, DestW, DestH, hImg, x, y, Width, Height, Size)\r\nCall GdipDisposeImage(hImg)\r\nEnd Sub\r\n  \r\nPrivate Sub InitGDI()\r\n    Dim GdipStartupInput As GDIPlusStartupInput\r\n    GdipStartupInput.GdiPlusVersion = GdiPlusVersion\r\n    Call GdiplusStartup(GdipToken, GdipStartupInput, ByVal 0)\r\nEnd Sub\r\n \r\nPrivate Sub TerminateGDI()\r\n    Call GdiplusShutdown(GdipToken)\r\nEnd Sub\r\n \r\nPrivate Sub Command1_Click()\r\n    Cls\r\n    RenderPlusFromFile Me.hdc, 5, 5, 230, 230, App.Path &amp; &quot;\\Image2.png&quot;, 0, 0, 158, 93, 26\r\nEnd Sub\r\n \r\nPrivate Sub Form_Load()\r\n    Call InitGDI\r\n    Call GdipLoadImageFromFile(StrPtr(App.Path &amp; &quot;\\BotonesVista.png&quot;), m_hImage)\r\n    Me.AutoRedraw = True 'Utilizando GDIPlus + AutoRedraw = True, es mas rapido\r\nEnd Sub\r\n \r\nPrivate Sub Form_Terminate()\r\n    Call GdipDisposeImage(m_hImage)\r\n    Call TerminateGDI\r\nEnd Sub\r\n \r\nPrivate Sub Option1_Click(Index As Integer)\r\n    Cls\r\n    RenderStretchPlus Me.hdc, 10, 10, 120, 80, m_hImage, 0, 21 * Index, 11, 21, 3\r\nEnd Sub \r\n<\/pre>\n<\/p>\n<p align=\"center\"><a href=\"https:\/\/leandroascierto.com\/blog\/descarga.php?url=RenderStretchPlus.zip\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" title=\"Descargar\" src=\"https:\/\/leandroascierto.com\/blog\/descarga.php?file=RenderStretchPlus.zip\" alt=\"\" width=\"280\" height=\"61\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Igual que la funci\u00f3n superior esta sirve para pintar una im\u00e1gen de forma ampliada pero manteniendo su contorno original utilizando\u00a0GDI PLUS, esto nos da como ventaja poder utilizar gr\u00e1ficos .PNG entre otros. N\u00f3tese que si ponemos el form con AutoRedraw = True la funci\u00f3n trabaja m\u00e1s r\u00e1pido. Option Explicit &#8216; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- &#8216; Autor Leandro Ascierto <a href='https:\/\/leandroascierto.com\/blog\/render-stretch-plus\/' 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":[60,35],"class_list":["post-461","post","type-post","status-publish","format-standard","hentry","category-graficos","tag-gdi-plus","tag-gdi","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\/461","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=461"}],"version-history":[{"count":3,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/posts\/461\/revisions"}],"predecessor-version":[{"id":515,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/posts\/461\/revisions\/515"}],"wp:attachment":[{"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/media?parent=461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/categories?post=461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/tags?post=461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}