Jump to content


Photo

GDI+ resizing is blurry?


  • Please log in to reply
5 replies to this topic

#1 joedf

joedf
  • Members
  • 289 posts

Posted 19 July 2012 - 12:04 AM

Im a fan of pixel art, here is a turtle using GDI+ by tic
but the problem is that draw it pixel by pixel, am I doing it this right?
second, I tried resizing it, but it is blurry.
Is there a way to turn off antialiasing?
I want sharp corners not burry-rounded ones! :D :mrgreen:
thank you for any help and suggestions about the methods to be using this
to draw pixel art!

I am open to any comments! :D

#SingleInstance, Force
#NoEnv
SetBatchLines, -1

#Include, Gdip.ahk

If !pToken := Gdip_Startup()
{
    MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
    ExitApp
}
pBitmap := Gdip_CreateBitmap(16, 16)
G := Gdip_GraphicsFromImage(pBitmap)
Gdip_SetSmoothingMode(G, 3)
blue := Gdip_BrushCreateSolid(0xff0000ff)
green := Gdip_BrushCreateSolid(0xff00FF00)
darkgreen := Gdip_BrushCreateSolid(0xff008C00)
black := Gdip_BrushCreateSolid(0xff000000)
beige := Gdip_BrushCreateSolid(0xffDFFEA0)

;draw turtle
Gdip_FillRectangle(G, blue, 0, 0, 16, 16)
Gdip_DeleteBrush(blue)
Gdip_FillRectangle(G, black, 5, 1, 8, 1)
Gdip_FillRectangle(G, black, 4, 2, 2, 1)
Gdip_FillRectangle(G, darkgreen, 6, 2, 2, 1)
Gdip_FillRectangle(G, black, 7, 2, 1, 1)
Gdip_FillRectangle(G, darkgreen, 8, 2, 3, 1)
Gdip_FillRectangle(G, black, 11, 2, 3, 1)
Gdip_FillRectangle(G, black, 4, 3, 1, 1)
Gdip_FillRectangle(G, darkgreen, 5, 3, 1, 1)
Gdip_FillRectangle(G, black, 6, 3, 3, 1)
Gdip_FillRectangle(G, darkgreen, 9, 3, 1, 1)
Gdip_FillRectangle(G, black, 10, 3, 2, 1)
Gdip_FillRectangle(G, darkgreen, 12, 3, 1, 1)
Gdip_FillRectangle(G, black, 13, 3, 1, 1)
Gdip_FillRectangle(G, black, 3, 4, 4, 1)
Gdip_FillRectangle(G, darkgreen, 7, 4, 1, 1)
Gdip_FillRectangle(G, black, 8, 4, 3, 1)
Gdip_FillRectangle(G, darkgreen, 11, 4, 2, 1)
Gdip_FillRectangle(G, black, 13, 4, 2, 1)
Gdip_FillRectangle(G, black, 3, 5, 1, 1)
Gdip_FillRectangle(G, darkgreen, 4, 5, 1, 1)
Gdip_FillRectangle(G, black, 5, 5, 1, 1)
Gdip_FillRectangle(G, darkgreen, 6, 5, 3, 1)
Gdip_FillRectangle(G, black, 9, 5, 4, 1)
Gdip_FillRectangle(G, darkgreen, 13, 5, 1, 1)
Gdip_FillRectangle(G, black, 14, 5, 1, 1)
Gdip_FillRectangle(G, black, 1, 6, 10, 1)
Gdip_FillRectangle(G, darkgreen, 11, 6, 1, 1)
Gdip_FillRectangle(G, black, 12, 6, 3, 1)
Gdip_FillRectangle(G, black, 1, 7, 1, 1)
Gdip_FillRectangle(G, green, 2, 7, 4, 1)
Gdip_FillRectangle(G, black, 6, 7, 1, 1)
Gdip_FillRectangle(G, beige, 7, 7, 1, 1)
Gdip_FillRectangle(G, black, 8, 7, 3, 1)
Gdip_FillRectangle(G, darkgreen, 11, 7, 1, 1)
Gdip_FillRectangle(G, black, 12, 7, 1, 1)
Gdip_FillRectangle(G, darkgreen, 13, 7, 1, 1)
Gdip_FillRectangle(G, black, 14, 7, 1, 1)
Gdip_FillRectangle(G, black, 1, 8, 1, 1)
Gdip_FillRectangle(G, green, 2, 8, 2, 1)
Gdip_FillRectangle(G, black, 4, 8, 1, 1)
Gdip_FillRectangle(G, green, 5, 8, 1, 1)
Gdip_FillRectangle(G, black, 6, 8, 2, 1)
Gdip_FillRectangle(G, beige, 8, 8, 2, 1)
Gdip_FillRectangle(G, black, 10, 8, 3, 1)
Gdip_FillRectangle(G, darkgreen, 13, 8, 1, 1)
Gdip_FillRectangle(G, black, 14, 8, 1, 1)
Gdip_FillRectangle(G, black, 1, 9, 2, 1)
Gdip_FillRectangle(G, green, 3, 9, 4, 1)
Gdip_FillRectangle(G, black, 7, 9, 3, 1)
Gdip_FillRectangle(G, beige, 10, 9, 1, 1)
Gdip_FillRectangle(G, black, 11, 9, 5, 1)
Gdip_FillRectangle(G, black, 1, 10, 1, 1)
Gdip_FillRectangle(G, green, 2, 10, 5, 1)
Gdip_FillRectangle(G, black, 7, 10, 1, 1)
Gdip_FillRectangle(G, green, 8, 10, 1, 1)
Gdip_FillRectangle(G, black, 9, 10, 2, 1)
Gdip_FillRectangle(G, beige, 11, 10, 4, 1)
Gdip_FillRectangle(G, black, 15, 10, 1, 1)
Gdip_FillRectangle(G, black, 1, 11, 3, 1)
Gdip_FillRectangle(G, green, 4, 11, 3, 1)
Gdip_FillRectangle(G, black, 7, 11, 2, 1)
Gdip_FillRectangle(G, green, 9, 11, 1, 1)
Gdip_FillRectangle(G, black, 10, 11, 6, 1)
Gdip_FillRectangle(G, black, 3, 12, 7, 1)
Gdip_FillRectangle(G, green, 10, 12, 4, 1)
Gdip_FillRectangle(G, black, 14, 12, 1, 1)
Gdip_FillRectangle(G, black, 2, 13, 2, 1)
Gdip_FillRectangle(G, green, 4, 13, 1, 1)
Gdip_FillRectangle(G, black, 5, 13, 1, 1)
Gdip_FillRectangle(G, green, 6, 13, 2, 1)
Gdip_FillRectangle(G, black, 8, 13, 2, 1)
Gdip_FillRectangle(G, green, 10, 13, 1, 1)
Gdip_FillRectangle(G, black, 11, 13, 1, 1)
Gdip_FillRectangle(G, green, 12, 13, 2, 1)
Gdip_FillRectangle(G, black, 14, 13, 2, 1)
Gdip_FillRectangle(G, black, 2, 14, 1, 1)
Gdip_FillRectangle(G, green, 3, 14, 2, 1)
Gdip_FillRectangle(G, black, 5, 14, 4, 1)
Gdip_FillRectangle(G, green, 9, 14, 2, 1)
Gdip_FillRectangle(G, black, 11, 14, 3, 1)
Gdip_FillRectangle(G, green, 14, 14, 1, 1)
Gdip_FillRectangle(G, black, 15, 14, 1, 1)
Gdip_FillRectangle(G, black, 2, 15, 5, 1)
Gdip_FillRectangle(G, black, 8, 15, 4, 1)
Gdip_FillRectangle(G, black, 13, 15, 3, 1)

; Delete the brush created to save memory
Gdip_DeleteBrush(black)
Gdip_DeleteBrush(green)
Gdip_DeleteBrush(darkgreen)
Gdip_DeleteBrush(beige)

;resize picture so that all pixels are now ten times bigger
Gdip_DrawImage(G, pBitmap2, dx="0", dy="0", dw="160", dh="160", sx="0", sy="0", sw="16", sh="16")

;save
Gdip_SaveBitmapToFile(pBitmap, "File.png")
Gdip_SaveBitmapToFile(pBitmap2, "Fileresized.png")

; The bitmaps can be deleted
Gdip_DisposeImage(pBitmap)
Gdip_DisposeImage(pBitmap2)

; The graphics may now be deleted
Gdip_DeleteGraphics(G)

; ...and gdi+ may now be shutdown
Gdip_Shutdown(pToken)

run, mspaint.exe file.png
run, mspaint.exe fileresized.png
ExitApp
Return


#2 tomoe_uehara

tomoe_uehara
  • Members
  • 2077 posts

Posted 19 July 2012 - 03:21 AM

My advice is to scan the pixels, multiply it by ten and redraw.

#3 Roninz

Roninz
  • Guests

Posted 19 July 2012 - 04:01 AM

Look at gdip_setsmoothingmode in gdip.ahk.. There is a comment there which tells how to remove antialiasing option.. I guess it was replacing the number "3" with "0"..
Hope this helped..

#4 joedf

joedf
  • Members
  • 289 posts

Posted 19 July 2012 - 10:02 AM

No 3 is default
0 is none

#5 lain

lain
  • Members
  • 183 posts

Posted 19 July 2012 - 02:31 PM

You need setting of interpolation mode to 5:

Gdip_SetInterpolationMode(G, 5)

I only tried it with png file as input.

The InterpolationMode enumeration specifies the algorithm that is used when images are scaled or rotated.



#6 Guests

  • Guests

Posted 19 July 2012 - 09:19 PM

Oh that exactly what I wanted ! :D
interpolation!