Sie sind auf Seite 1von 14

dim cnnimage as new adodb.

connection
dim rsimage as new adodb.recordset
dim strsql as string

dim chunk() as byte


dim lnglengh as long
dim intchunks as integer
dim intfragment as integer

const chunksize = 1000 '16384


const lngdatafile = 1

private sub cmdbrowse_click()


'select jpg or bitmap file to store in database
on error resume next
with cmdlfilepath
.filter = "jpg files|*.jpg|bitmaps|*.bmp"
.showopen
txtfilepath.text = .filename
end with
end sub

private sub cmdexit_click()


'close
end
end sub

private sub cmdlast_click()


'move last
on error resume next
rsimage.movelast
'show pic in picturebox
call showpic
end sub

private sub cmdnext_click()


'move next
on error resume next
rsimage.movenext
'show pic in picturebox
call showpic
end sub

private sub cmdprev_click()


'move previous
on error resume next
rsimage.moveprevious
'show pic in picturebox
call showpic
end sub

private sub cmdsave_click()


'save file
if trim(txtfilepath.text) = "" then
msgbox "plz select jpg or bitmap file to store in database.!!",
vbinformation + vbsystemmodal, "save"
exit sub
end if
if (dir(trim(txtfilepath.text)) = "") then exit sub
'open as binary
open trim(txtfilepath.text) for binary access read as lngdatafile
lnglengh = lof(lngdatafile) ' length of data in file
if lnglengh = 0 then close lngdatafile: exit sub
intchunks = lnglengh \ chunksize
intfragment = lnglengh mod chunksize
'add new record in database
rsimage.addnew
redim chunk(intfragment)
'read data from a file into a variable
get lngdatafile, , chunk()
'appends data to a large text or binary data field or parameter object.
rsimage!picimage.appendchunk chunk()

redim chunk(chunksize)
for i = 1 to intchunks
get lngdatafile, , chunk()
rsimage!picimage.appendchunk chunk()
next i
'update
rsimage.update
'close file
close lngdatafile
'show pic in picturebox
call showpic
end sub

private sub cmdfirst_click()


' on error resume next
rsimage.movefirst
'show pic in picturebox
call showpic
end sub

private sub form_load()

rsimage.locktype = adlockoptimistic
rsimage.cursortype = adopenkeyset

cnnimage.provider = "microsoft.jet.oledb.4.0"
strsql = app.path & "\image.mdb"
cnnimage.open strsql

strsql = "select * from imagestore"


rsimage.open strsql, cnnimage

if (rsimage.bof = true) and (rsimage.eof = true) then exit sub


'open record set
call cmdfirst_click
end sub

public sub showpic()


on error resume next

open "pictemp" for binary access write as lngdatafile


lnglengh = rsimage!picimage.actualsize
intchunks = lnglengh \ chunksize
intfragment = lnglengh mod chunksize
redim chunk(intfragment)
chunk() = rsimage!picimage.getchunk(intfragment)
put lngdatafile, , chunk()
for i = 1 to intchunks
redim buffer(chunksize)
'returns all or a portion of the contents of a large text or binary
data field object.
chunk() = rsimage!picimage.getchunk(chunksize)
'write data to a temp file
put lngdatafile, , chunk()
next i
close lngdatafile

filename = "pictemp"
picture1.picture = loadpicture(filename)
end sub

program 2 image comparision

'*********************************************
' this code was designed by ward jaradat
'
' e-mail & msn messanger handler:
' wardgalactica@bluebottle.com
'
' website:
' http://wardgalactica.blogspot.com
'*********************************************

'---------------------------------------------
' this code's purpose is to scan two given
' images' pixels to find out if they were
' identical or not!
'---------------------------------------------

option explicit

public enum mycolor ' rgb color values


r as long
g as long
b as long
end enum

public enum myresults


t as long ' for total pixels
i as long ' for identical pixels
n as long ' for non-identical pixels
p as long ' for how much percent the two images are identical
end enum

public result as myresults

' information:

' this code works on 16bpp format for images, actually i would like
' to make some points clear regarding this issue:
'
' ----------------------------------------------------------------------
'
' * rgb 5:5:5 is the default format so its actually 15bpp where the
' top bit is alwayz empty or not used!
'
' * in this format 16bpp, each of the red, green, & blue
' color components is presented by a 5 bit number giving
' 32 different levels of each and 32786 possible different
' colors in total; which means that the true 16bpp would be
' rgb 5:6:5 where there are 65536 possible colors!
'
' * there is no palette used to define the colors for the 16bpp images
' however the red, green, & blue values in the pixel are used to
' define the colors directly!
'
' ----------------------------------------------------------------------
' however if u like to know more about rgb formats u could do some search
' on google or something... :d
'
public function scanpixels(mypic1 as picturebox, mypic2 as picturebox)

dim pointx as long


dim pointy as long

dim x as long
dim y as long

dim colorx as mycolor


dim colory as mycolor

' note that the resolution of mypic1 & mypic2 should be identical
if not (mypic1.height = mypic2.height) then
exit function
elseif not (mypic1.width = mypic2.width) then
exit function
end if

do until (y > mypic1.height)

pointx = picture1.point(x, y)
pointy = picture2.point(x, y)

myrgb pointx, colorx.r, colorx.g, colorx.b


myrgb pointy, colory.r, colory.g, colory.b

if (colorx.r = colory.r) and (colorx.g = colory.g) and (colorx.b =


colory.b) then
result.i = result.i + 1
else
result.n = result.n + 1
end if

result.t = result.t + 1

x = x + 15 ' why 15? check the information above!

if x > mypic1.width then


x = 0
y = y + 15
end if

loop

result.p = (100 - ((result.n / result.t) * 100))

end function

public function myrgb(byval mypoint as long, red as long, green as long, blue as
long)

g = int(colorvalue / 65536)
b = int((colorvalue - (65536 * g)) / 256)
r = colorvalue - (65536 * g + 256 * b)

' however, just if u wanna know how to get rgb values in the reverse order
' of bytes u could return the value of the following code:
'
' clng(blue + (green * 256) + (red * 65536)
'
' i did truly find that useful in making other functions regarding rgb :d

end function

program 3

option explicit
' date : 05/10/2006.
' time : 08:10:00 pm.
' created by : amr zakaria zaki.
' work's with vb 0.6 and vb 0.5.
' to read picture and convert it to byte's.
' e-mail : amrzakaria73@gmail.com , amrzakaria73@yahoo.com
'***********************************************************************
' 1 = clsimage
' 1 = function , 2 = sub , 3 = property get , 4 = property let
' 1 = convertrgb => function
' private = 0 , public = 1
'-------- my new udt
' regsvr32 c:\windows\system\cam.dll
'? len("00/00/0000") + len("00:00:00") + len(string$(255," " )) +
len("000.000.000.000") + len("32000")+ len("32000")
' picread.paintpicture piccls.image, 0, 0, pic.width + 200, pic.height + 150

private type image_to_byte


msg as string * 254
idate as string * 10
itime as string * 8
portmsg as long
portdata as long
myip as string * 15
end type
private type rgb_
rd as byte
gn as byte
bl as byte
end type

private type objectpicture


ppicture as object
readbyte() as byte
readbyteindex as long
headerbyte() as byte
header as image_to_byte
rheade as image_to_byte
end type

'---------------------
private type bitmap
bmtype as long
bmwidth as long
bmheight as long
bmwidthbytes as long
bmplanes as integer
bmbitspixel as integer
bmbits as long
end type

'-------- api calling


'private declare sub copymemory lib "kernel32" alias "rtlmovememory" (destination
as any, source as any, byval length as long)
private declare function getobject lib "gdi32" alias "getobjecta" (byval hobject
as long, byval ncount as long, lpobject as any) as long
private declare function getbitmapbits lib "gdi32" (byval hbitmap as long, byval
dwcount as long, lpbits as any) as long
private declare function setbitmapbits lib "gdi32" (byval hbitmap as long, byval
dwcount as long, lpbits as any) as long
'---------------------
'to fire this event, use raiseevent with the following syntax:
'raiseevent clserr[(arg1, arg2, ... , argn)]
public event clserr(byval vsouce as string, verrid as string, byval verrmsg as
string)
public event clsmsg(byval vsouce as string, vmsg as string)
'---------------------
private pobj as objectpicture

public property get gui_picture() as object


' 1.3.1.2 = clsimage.property_get.gui_picture
gui_picture = pobj.ppicture
raiseevent clsmsg("1.3.1.2", "object is returned.")
end property

public property let gui_picture(byval vdata as object)


' 1.4.1.3 = clsimage.property_let.gui_picture
on error goto errgui_picture

with vdata
.scalemode = vbpixels
.autoredraw = true
.width = 100
.height = 66
' .paintpicture tmppic, 0, 0, 100, 66
end with
''-------------------------
set pobj.ppicture = vdata
pobj.ppicture.scalemode = vbpixels ' i have to use pixel size for video confronc
if readpixels2() <> true then
err.raise 143, "1.4.3", "can not read pixel from image."
end if
'--------------------------
raiseevent clsmsg("1.4.1.3", "object is passed.")
exit property
errgui_picture:
set pobj.ppicture = nothing
raiseevent clserr("1.4.1.3", err.number, err.description)
err.clear
end property

private function readpixels2() as boolean


'1.1.0.8 = clsimage.function.readpixels2
on error goto errreadpixels2

dim picinfo as bitmap


dim picbits() as byte

getobject pobj.ppicture.image, len(picinfo), picinfo


redim picbits(0 to picinfo.bmwidth * picinfo.bmheight * 4) as byte
getbitmapbits pobj.ppicture.image, ubound(picbits), picbits(1)
doevents
pobj.readbyteindex = ubound(picbits)
pobj.readbyte = picbits()
readpixels2 = true
erase picbits()
raiseevent clsmsg("1.1.0.8", "read image as byte's.")
exit function
errreadpixels2:
erase picbits()
readpixels2 = false
raiseevent clserr("1.1.0.8", err.number, err.description)
err.clear
end function

public function gui_showpicture(optional byval vobject as object = nothing, _


optional byval useheader as boolean = true) as
boolean
' 1.1.1.4 = clsimage.function.gui_showpicture
on error goto errgui_showpicture

dim hb() as byte, db() as byte


dim l as long, c as long
dim picinfo as bitmap
dim x as image_to_byte

'588 , 297
'c = 0
'c = 9
'c = 10
'c = 17
'c = 18
'c = 271
'c = 272
'c = 286
'c = 287
'c = 291
'c = 292
'c = 296

c = 0
for l = 0 to ubound(pobj.headerbyte)
if l <= 296 then
redim preserve hb(l)
hb(l) = pobj.headerbyte(l)
else
redim preserve db(c)
db(c) = pobj.headerbyte(l)
c = c + 1
end if
' doevents
next l
'--------------------------
if useheader = true then
pobj.header.idate = readbyte_from_to(pobj.headerbyte(), 0, 9)
pobj.header.itime = readbyte_from_to(pobj.headerbyte(), 10, 17)
pobj.header.msg = trim(readbyte_from_to(pobj.headerbyte(), 18, 271))
pobj.header.myip = readbyte_from_to(pobj.headerbyte(), 272, 286)

if isnumeric(trim(readbyte_from_to(pobj.headerbyte(), 287, 291))) = true then


pobj.header.portdata = trim(readbyte_from_to(pobj.headerbyte(), 287, 291))
else
pobj.header.portdata = 0
end if

if isnumeric(trim(readbyte_from_to(pobj.headerbyte(), 292, 296))) = true then


pobj.header.portmsg = trim(readbyte_from_to(pobj.headerbyte(), 292, 296))
else
pobj.header.portmsg = 0
end if
end if
'--------------------------
'debug.print "clsimage.gui_showpicture2 = ", ubound(hb), ubound(db),
ubound(pobj.headerbyte), lenb(pobj.header)
'stop
'copymemory pobj.header, hb(0), lenb(pobj.header)
'copymemory x, hb(0), lenb(x)
'pobj.header = x
'stop
'----------------
vobject.scalemode = vbpixels ' i have to use pixel size for video confronc
setbitmapbits vobject.image, ubound(db), db(1)
vobject.refresh
'----------------
gui_showpicture = true
erase hb()
erase db()
raiseevent clsmsg("1.1.1.4", "image displed on its owner.")
exit function
errgui_showpicture:
gui_showpicture = false
erase hb()
erase db()
raiseevent clserr("1.1.1.4", err.number, err.description)
err.clear
end function

private function convertrgb(byval lcolour as long) as rgb_


' 1.1.0.1 = clsimage.function.convertrgb
on error goto errconvertrgb
dim ired as integer, igreen as integer, iblue as integer
lcolour = lcolour and &hffffff
convertrgb.rd = lcolour and &hff
convertrgb.gn = (lcolour \ &h100) and &hff
convertrgb.bl = lcolour \ &h10000
raiseevent clsmsg("1.1.0.1", "color converted to (r,g,b).")

exit function
errconvertrgb:
convertrgb.bl = 0: convertrgb.gn = 0: convertrgb.rd = 0
raiseevent clserr("1.1.0.1", err.number, err.description)
err.clear
end function

private sub class_initialize()


'1.2.0.17 = clsimage.sub.class_initialize
pobj.rheade.idate = date
pobj.rheade.itime = format$(time, "hh:mm:ss")
pobj.rheade.msg = "noting"
pobj.rheade.myip = "000.000.000.000"
pobj.rheade.portdata = 2777
pobj.rheade.portmsg = 2888
raiseevent clsmsg("1.2.0.17", "class initialize.")
end sub

private sub class_terminate()


'1.2.0.18 = clsimage.sub.class_terminate
erase pobj.readbyte()
erase pobj.headerbyte()
pobj.readbyteindex = 0
set pobj.ppicture = nothing
raiseevent clsmsg("1.2.0.18", "class terminate.")
end sub

public function infoaboutme(optional byval vdate as string = "00/00/0000", _


optional byval vtime as string = "00:00:00", _
optional byval vmsg as string = "", _
optional byval vmyip as string = "000.000.000.000", _
optional byval vportdata as long = 0, _
optional byval vportmsg as long = 0) as boolean
'1.1.1.5 = clsimage.function.infoaboutme
on error goto errinfoaboutme

dim tb() as byte


dim th() as byte
dim l as long
dim c as long
'------ i have to send data from picture or form to my udt.
if isdate(vdate) = true then
pobj.rheade.idate = formatdatetime(vdate, vbshortdate)
else
pobj.rheade.idate = formatdatetime(date, vbshortdate)
end if
'---------------------------
if isdate(vtime) = true then
pobj.rheade.itime = format$(vtime, "hh:mm:ss")
else
pobj.rheade.itime = format$(time, "hh:mm:ss")
end if
'---------------------------
pobj.rheade.msg = vmsg
pobj.rheade.myip = vmyip
pobj.rheade.portdata = vportdata
pobj.rheade.portmsg = vportmsg
'------------- 588 old , new 297
'redim tb(lenb(pobj.header)) as byte
'call copymemory(tb(0), pobj.rheade, lenb(pobj.rheade))
tb = udt_to_byte(pobj.rheade.idate, pobj.rheade.itime, vmsg, vmyip, vportdata,
vportmsg)
'-----------------------------------
redim th(ubound(tb) + pobj.readbyteindex + 1)
c = 0
for l = 0 to (ubound(tb) + pobj.readbyteindex + 1)
if l <= ubound(tb) then
th(l) = tb(l)
else
th(l) = pobj.readbyte(c)
c = c + 1
end if
' doevents
next l
'-------------
pobj.headerbyte = th()
infoaboutme = true
'-------------
erase th()
erase tb()

raiseevent clsmsg("1.1.1.5", "info passed to the class.")

exit function
errinfoaboutme:

infoaboutme = false
erase th()
erase tb()

raiseevent clserr("1.1.1.5", err.number, err.description)


err.clear
end function

public property get rh_ip() as string


'1.3.1.11 = clsimage.property_get.rh_ip
rh_ip = pobj.header.myip
raiseevent clsmsg("1.3.1.11", "ip returned.")
end property

public property get rh_msg() as string


'1.3.1.12 = clsimage.property_get.rh_msg
rh_msg = pobj.header.msg
raiseevent clsmsg("1.3.1.12", "msg returned.")
end property

public property get rh_date() as string


'1.3.1.10 = clsimage.property_get.rh_date
rh_date = pobj.header.idate
raiseevent clsmsg("1.3.1.10", "date returned.")
end property

public property get rh_time() as string


'1.3.1.15 = clsimage.property_get.rh_time
rh_time = pobj.header.itime
raiseevent clsmsg("1.3.1.15", "time returned.")
end property

public property get rh_portmsg() as long


'1.3.1.14 = clsimage.property_get.rh_portmsg
rh_portmsg = pobj.header.portmsg
raiseevent clsmsg("1.3.1.14", "date returned.")
end property

public property get rh_portdata() as long


'1.3.1.13 = clsimage.property_get.rh_portdata
rh_portdata = pobj.header.portdata
raiseevent clsmsg("1.3.1.13", "date returned.")
end property

private function udt_to_byte(optional byval vdate as string = "00/00/0000", _


optional byval vtime as string = "00:00:00", _
optional byval vmsg as string = "", _
optional byval vmyip as string = "000.000.000.000", _
optional byval vportdata as long = 0, _
optional byval vportmsg as long = 0) as byte()
'1.1.0.16 = clsimage.function.udt_to_byte
on error goto errudt_to_byte

dim l as integer
dim c as integer
dim tmp() as byte
dim tp as string
' 297
c = 0
' debug.print "c= "; c
for l = 1 to len(vdate)
redim preserve tmp(c)
tmp(c) = cbyte(asc(mid(vdate, l, 1)))
' debug.print tmp(c), chr(tmp(c)), l, len(vdate)
c = c + 1
next l
' debug.print "c= "; c - 1
'--------------------------------------
' debug.print "c= "; c
for l = 1 to len(vtime)
redim preserve tmp(c)
tmp(c) = cbyte(asc(mid(vtime, l, 1)))
' debug.print tmp(c), chr(tmp(c)), l, len(vdate)
c = c + 1
next l
' debug.print "c= "; c - 1
'--------------------------------------
if len(vmsg) < 254 then
vmsg = vmsg & string$((254 - len(vmsg)), " ")
end if
'----
' debug.print "c= "; c
for l = 1 to len(vmsg)
redim preserve tmp(c)
tmp(c) = cbyte(asc(mid(vmsg, l, 1)))
' debug.print tmp(c), l, len(vmsg)
c = c + 1
next l
' debug.print "c= "; c - 1
'--------------------------------------
if len(vmyip) < 15 then
vmyip = vmyip & string$((15 - len(vmyip)), " ")
end if
'----
' debug.print "c= "; c
for l = 1 to len(vmyip)
redim preserve tmp(c)
tmp(c) = cbyte(asc(mid(vmyip, l, 1)))
' debug.print tmp(c), l, len(vmyip)
c = c + 1
next l
' debug.print "c= "; c - 1
'--------------------------------------
tp = cstr(vportdata)
'-----------
if len(tp) < 5 then
tp = string$((5 - len(tp)), "0") & tp
end if
'-----------
' debug.print "c= "; c
for l = 1 to len(tp)
redim preserve tmp(c)
tmp(c) = cbyte(asc(mid(tp, l, 1)))
' debug.print tmp(c), l, len(tp)
c = c + 1
next l
' debug.print "c= "; c - 1
'--------------------------------------
tp = cstr(vportmsg)
'-----------
if len(tp) < 5 then
tp = string$((5 - len(tp)), "0") & tp
end if
'-----------
' debug.print "c= "; c
for l = 1 to len(tp)
redim preserve tmp(c)
tmp(c) = cbyte(asc(mid(tp, l, 1)))
' debug.print tmp(c), l, len(tp)
c = c + 1
next l
' debug.print "c= "; c - 1
udt_to_byte = tmp()
erase tmp()
raiseevent clsmsg("1.1.0.16", "data type's converted to byte's.")

exit function
errudt_to_byte:
redim tmp(0)
udt_to_byte = tmp()
erase tmp()
raiseevent clserr("1.1.0.16", err.number, err.description)
err.clear
end function

private function readbyte_from_to(byref vbyte() as byte, byval vstart as integer,


byval vend as integer) as string
'1.1.0.7 = clsimage.function.readbyte_from_to
on error goto errreadbyte_from_to
dim c as integer
dim tmp as string

for c = vstart to vend


tmp = tmp & chr$(vbyte(c))
next c
readbyte_from_to = tmp

raiseevent clsmsg("1.1.0.7", "image displed on its owner.")


exit function
errreadbyte_from_to:
readbyte_from_to = "error"
raiseevent clserr("1.1.0.7", err.number, err.description)
err.clear
end function

public function return_header_byte() as byte()


'1.1.1.9 = clsimage.function.return_header_byte
return_header_byte = pobj.headerbyte()
raiseevent clsmsg("1.1.1.9", "return the header as byte's.")
end function

public function read_header_byte(byref vbyte() as byte) as boolean


'1.1.1.6 = clsimage.function.read_header_byte
pobj.headerbyte = vbyte()
read_header_byte = true
raiseevent clsmsg("1.1.1.6", "import the header as byte's.")
end function

public function regsvr32_clsimage(optional byval vuser as boolean = false) as


boolean
'1.1.1.19 = clsimage.function.regsvr32_clsimage
on error goto errregsvr32_clsimage
dim tmp as string

if vuser = true then


tmp = "regsvr32 " & app.path & "\" & app.exename & ".dll"
call shell(tmp)
' debug.print app.path, app.exename
regsvr32_clsimage = true
else
regsvr32_clsimage = false
end if

raiseevent clsmsg("1.1.1.19", "to [regsvr32] my class.")


exit function

errregsvr32_clsimage:
regsvr32_clsimage = false
raiseevent clserr("1.1.1.19", err.number, err.description)
err.clear
end function

public function image_height_width() as string


'1.1.1.20 = clsimage.function.image_height_width
image_height_width = "image : height = 66 , width = 100"
raiseevent clsmsg("1.1.1.20", "return the size of picture.")
end function

Das könnte Ihnen auch gefallen