I need either the source of a method like Loadpicture or a method that loads pictures from a position in a file with a specified length.
Any ideas?
Printable View
I need either the source of a method like Loadpicture or a method that loads pictures from a position in a file with a specified length.
Any ideas?
WOW I didn't think that a Guru would ever be asking a question.
but this might work:
Code:Private Sub Command1_Click()
Image1.Picture = ".../******.bmp" 'every * stands for a character
End Sub
I think that is the great thing about Kedaman. Status is unimportant to him.
Ked! Maybe you can search for it in the Microsoft site. Not sure!
You're doing this for your PAK-Type Project, Aren't you? Well, I think you've already done it, because you sent me the dll. If not, here goes:
NOTES:
Pos = StartPos of this file
NPos = StartPos of the file after this one
MyFile = The File you will be getting the data from
Instead of:Code:Dim f
dim OCx as long
dim Cx as long
dim Length as Long
dim Chunk as long
dim OChunk as long
dim TEMP
dim MyPicToSave
dim Start as byte
length = npos - pos
do
cx=cx+1
chunk = space$(pos / cx)
if pos / cx = int(pos / cx) then
exit loop
end if
loop
start = pos
do
ocx=ocx+1
ochunk = space$(length / ocx)
if length / ocx = int(length / ocx) then
exit loop
end if
loop
f=freefile
open myfile for binary as f
for a = 1 to cx
get f,,chunk
next a
for a = 1 to ocx
get f,,ochunk
mypictosave=mypictosave & ochunk
next a
mypictosave = trim$(mypictosave)
close f
open app.path & "\temp.bmp" for binary as f
put f,,mypictosave
close f
picture1.picture = loadpicture(app.path & "\temp.bmp")
Open MyFile For Binary as F
For A = 1 to CX
Get f,,chunk
Next A
You could do this:
Open MyFile For Binary as F
Get F,Start,Temp
I'm not sure that this will work, but I'm pretty confident.
Nah, i could as well you the fileextract function and loadpicture. BTW, that's 64 bit and slow.
Just need a method like Loadpicture that loads the file from within a file, in this case my package.
Or i would need the source for such kind of function so that i can modify it.
But does it work? (Even though it's 64 bit + slow?)
Not sure, haven't tested, but what i need is something that reads once, not read, write and read again.
What do you mean by load a picture from within a file? Do you mean that the whole bitmap file is just a part of a larger file? If so then this could be done if you could extract the bitmap portion, header and all, into a byte array.
You would use the first 1078 bits to fill an info structure containing the image header and color table. The last part of the file would then be passed to another array to contain only the image bits.
With these structures you can then use CreateDiBitmap to create the bitmap in a memory DC.
If you need code I will supply it.
Hehe, i knew somone would find something usefull,
thanks Illuminator, i'll need the code :)
Yes, creating a bitmap in memory from a BMP byte array sounds very feasible, although I've never done it. But reading JPGs or GIFs from memory would probably require you to first save the pic(s) temporarily and then use the LoadPicture function.
Illuminator, I would also like to see the code. This idea could be used in many of my and others' projects.
Thanks
(Just wondering, is it possible to store an OLE object in a text file and then read it back?)
I will assume you are familliar with creating a memory DC and proficient at finding the API function definitions.
Code:'API Functions
CreateCompatibleDC
DeleteDC
SelectObject
DeleteObject
CreateDIBitmap
BitBlt ' or simialr function
'Bitmap Structure Types
Public Type BITMAPFILEHEADER
bfType As Integer
bfSize As Long
bfReserved1 As Integer
bfReserved2 As Integer
bfOffBits As Long
End Type
Public Type BITMAPINFOHEADER '40 bytes
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type
Public Type RGBQUAD
rgbBlue As Byte
rgbGreen As Byte
rgbRed As Byte
rgbReserved As Byte
End Type
Public Type BITMAPINFO
bmiHeader As BITMAPINFOHEADER
bmiColors(256) As RGBQUAD
End Type
'Varibles
Public FileHeader As BITMAPFILEHEADER
Public Info As BITMAPINFO
Public FilePath as string
Public Image_Array() as byte 'An array that will contain only the image bits
Public hDC as Long 'the handle to the memory DC'
Sub Create_Bitmap()
Dim Temp As String
Temp = FreeFile
Dim Image_Start as Long
Image_Start = ???? '<- set the start position of the image within the file
Open FilePath For Binary Access Read As #Temp
Get #Temp, Image_Start, FileHeader
Get #Temp, , Info.bmiHeader
Get #Temp, , Info.bmiColors
Redim Image_array(Info.bmiHeader.biWidth-1, Info.bmiHeader.biHeight-1) as byte
Get #Temp, , Image_Array()
Close Temp
SelectObject hDC, CreateDIBitmap(hDC, Info.bmiHeader, &H4, Image_Array(0, 0), Info, 2)
'from here on you can use the Hdc to reference the image and use bitblt and other functions.
End Sub
Slightly off-topic, but for things like this where there are lots of complex API declarations, try using Bruce McKinney's Win32 API Type Library. I've had it for a while and it makes development so much quicker.
Well, i'm just interested in loading directly from withing a file, I guess i can't get directly onto a directdrawsurface but getting to a DC is enough, I can use createsurfacefromDC.
Many thanks to you Illuminator. :)
Hey Kedaman, are you going to include that in the next version of KedaPack? Or should I make it a part of my DLL? :) I hope you don't mind, Illuminator, but I need to use that code as well. !
I'll include, i'll try to include as much as possible in the DLL.
So you call it like:
Kedapack1.LoadBitmap path, Picture1.hDC
i need to do the same thing but with jpg and gif as well as the bmp... Anyone come across something since this thread was started?
If you don't want to dive into those formats yourself, you should do the temporary file way (as illustrated above).