This whas an simple experiment to test agk memblock commands.
It grabbs an image and shrinks it size and use in memory at runtime.
Dont work well on to large images ?
the image in the sample is 160x160.
You nead beta 8 or higher.
rem
rem AGK Application
rem
setvirtualresolution(480,480)
REM // load image to shrink
img = loadimage("agklogo.png")
Image_Minimizer(img)
// Create a sprite to display the shrinked image
spr=createsprite(img)
setspriteposition(spr,0,100)
REM // Create a memblock to display info text with
memShrink = CreateMemblockFromImage( img )
REM // Create a sprite to display the original
img = loadimage("agklogo.png")
spr=createsprite(img)
setspriteposition(spr,260,100)
memOriginal = CreateMemblockFromImage( img )
rem A Wizard Did It!
do
print("Shrinked Original")
print("width = "+str(GetMemblockByte( memShrink, 0 ))+" "+str(GetMemblockByte( memOriginal, 0 )))
print("height = "+str(GetMemblockByte( memShrink, 4 ))+" "+str(GetMemblockByte( memOriginal, 4 )))
print("depth = "+str(GetMemblockByte( memShrink, 8 ))+" "+str(GetMemblockByte( memOriginal, 8 )))
print("size = "+str(GetMemblockByte( memShrink, 0 )*GetMemblockByte( memShrink, 4 )*4)+" "+str(GetMemblockByte( memOriginal, 0 )*GetMemblockByte( memOriginal, 4 )*4))
print("size2 = "+str(GetMemblockSize( memShrink ))+" "+str(GetMemblockSize( memOriginal )))
sync()
loop
Function Image_Minimizer(id)
REM // Memblock for original
memA = CreateMemblockFromImage( id )
REM // Lets get the image data for width,height and bit depth
width = GetMemblockByte( memA, 0 )
height = GetMemblockByte( memA, 4 )
depth = GetMemblockByte( memA, 8 )
size = GetMemblockSize( memA )
REM // Memblock for shrinked
memB = CreateMemblock( size )
t2=0
lenByte=12+(width/2)*(height/2)*4
tpX=width*4
tpY=height*4
startX=12
t2=12
for t=0 to lenByte-1
REM // Grabb the bit depth
if t<12 then setMemblockByte( memB, t, GetMemblockbyte( memA,t) )
REM // Grabb the width and height
if t<9 then SetMemblockByte( memB, t, GetMemblockbyte( memA,t)/2 )
REM Lets grabb every second pixel on the x coord from the original and write it to the new one
if t=>startX
setMemblockByte( memB, t, GetMemblockbyte( memA,t2+count) )
inc count
if count>3
inc t2,8
count=0
endif
REM // Skip every second y coord
if t=startX+tpX
inc startX,tpX
inc t2,tpX+tpy
endif
endif
next t
DeleteMemblock( memA )
REM Delete original
DeleteImage(id)
REM // Create our shrinked
CreateImageFromMemblock(id,memB)
DeleteMemblock( memB )
Endfunction
Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz