Buchempfehlung
MySQL kurz & gut
MySQL kurz & gut
Das preiswerte Taschen- buch stellt MySQL-rele- vante Inhalte systematisch und knapp dar, sodass es sich optimal zum Nach- schlagen beim Pro- grammieren eignet. [Mehr Infos...]
FreeBASIC-Chat
Es sind Benutzer im FreeBASIC-Chat online.
(Stand:  )
FreeBASIC bei Twitter
Twitter FreeBASIC-Nachrichten jetzt auch über Twitter erhalten. Follow us!

Code-Beispiel

Code-Beispiele » Grafik und Fonts

Alle Pixel aus einem Image Pointer holen

Lizenz:Erster Autor:Letzte Bearbeitung:
GPLMitgliedjakidomi 06.12.2009

Beispiel

#Include "getpixel.bi"
#include "jpeg4fb.bas"

screen 18,32

dim as any ptr img
dim as pixel pix()
img= jpegget("miloan.jpg")

dim as uinteger w,h
dim as double ti,tig=timer
imageinfo(img,w,h)
ti=timer
consprint"Generiere Pixel Liste"
getAllPixel(pix(),img)
consprint"Fertig - pixel: "+str(ubound(pix))
consprint str(abs(timer-ti))

ti=timer
consprint"Draw Pixels"
PutAllPixel(0,0,w,h,pix())
consprint"Fertig - pixel: "+str(ubound(pix))
consprint str(abs(timer-ti))
consprint str(abs(timer-tig))
getkey

<hr>

GetPixel.bi

#Include once "fbgfx.bi"
#include once "fonts.bi"
Using FB
type pixel
    r as ubyte
    g as ubyte
    b as ubyte
    a as ubyte
    f as uinteger
    declare sub i()
    declare constructor ()
end type
constructor pixel()
    this.f=rgba(this.r,this.g,this.b,this.a)
end constructor
sub pixel.i()
    this.f=rgba(this.r,this.g,this.b,this.a)
end sub
sub getAllPixel(pix() as pixel,img as any ptr)
    dim as uinteger u,t,w,h
    imageinfo(img,w,h)
    for y as integer=0 to h
        for x as integer=0 to w
            t=point(x,y,img)
            u+=1
            redim preserve pix(u)
            pix(u).r=getrot(t)' hole rot wert aus farbcode t
            pix(u).g=getgruen(t)' hole grün wert aus farbcode t
            pix(u).b=getblau(t)' hole blau wert aus farbcode t
            pix(u).a=getalpha(t)' hole alpha wert aus farbcode t
            pix(u).i
        next
    next
end sub
sub setAllPixel(pix() as pixel,img as any ptr)
    dim as uinteger u,t,w,h
    imageinfo(img,w,h)
    for y as integer=0 to h
        for x as integer=0 to w
            if u>ubound(pix) then exit for
            pset img,(x,y),pix(u).f
        next
    next
end sub
sub PutAllPixel(x as integer,y as integer,w as uinteger,h as uinteger,pix() as pixel)
    dim as uinteger u
    for yy as integer=0 to h
        if yy+y>scy then exit for
        for xx as integer=0 to w
            u+=1
            if u>ubound(pix) then exit for
            if xx+x>scx then u+=w-xx:exit for' consprint str(xx+x)+" - "+str(scx)+" - "+str(u)'exit for
            pset (x+xx,y+yy),pix(u).f
        next
    next
end sub

Zusätzliche Informationen und Funktionen
  • Das Code-Beispiel wurde am 06.12.2009 von Mitgliedjakidomi angelegt.
  • Die aktuellste Version wurde am 06.12.2009 von Mitgliedjakidomi gespeichert.
  Bearbeiten Bearbeiten  

  Versionen Versionen