Re: How to hide jpg



<itko59@xxxxxxxxx> wrote in message news:1148388757.889748.233150@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

ThanX Mike!
I'm Chris, Bulgaria

Okay. You're welcome. In case you're wondering why I was interested, I noticed that you were using the free aioe.org news server which is something I use myself for some groups since my own ISP decided to stop providing a news service. I would ditch my own ISP (Wanadoo) tomorrow and go with someone else if it were not for the fact that I use their wireless equipment which came "free" when I signed up for their service a couple of years ago to also connect my laptop, and it will only work with their own Internet service. I'll probably buy my own router hardware soon though. I don't like ISPs who charge for a service and then fail to provide part of that service whenever they feel the need to do so!

In further response to your initial question, you should start off by looking at VB resource files. Alternatively, here is a method which will enable you to store all your jpg files in one (or more than one) data file. To create your single large data file you could write a VB app to Open a new file for Binary and use Put to write an array of (say) 101 Longs into the file. This will enable you to store one Long value and 50 "pairs of Longs" with the first Long containing the number of images the file contains and each "pair of Longs" thereafter specifying an "offset from the beginning" in LongA and the image data length in LongB. Then load up your jpeg files one at a time (into a Byte array) and use Put to put the data into the new data file, starting just after the initial "101 Longs" and making the appropriate "starting point" and "data length" entries in the appropriate pair. In that way you'll end up with a data file that contains 100 pairs of Longs followed by 50 blocks of data of any length you wish (for up to 50 separate jpeg images). When you have written all your image data for however many imnages you need you can then Put the appropriate value (number of images in the file) into the first Long in the data file. Then you can use that single data file in your own main VB program by writing code to extract the "number of images in the file" and then "look at" each appropriate pair of Longs in turn and "Get" data of the appropriate size and starting at the appropriate point (as specified by the two "pointers") into a Picture Box or StdPicture object or whatever. In fact, it would probably be better to place these "101 Longs" at the end of your data file rather than at the beginning, and in that way you can store as many images as you wish (so that for example if you have 12 image files in the data you would terminate the file with 25 Longs, and for 33 images you would terminate it with 67 Longs. You could even start the data file off with some "dummy data" to confuse anyone who might be looking at it in raw format, and you could even "code" the image data using a simple algorithm of your own and "decode" it using an equivalent algorithm when you load the data into your main program. That part (the part I have just described for creating the raw data file) is fairly straightforward and you should have no trouble writing it, but obviously in order for that to work you will also need code that is capable of reading a block of data from a file into a Byte array and then treating that data as though it was a "picture file on disk". Here is some code that shows you how to do that. It is based on a sample that I found on the web somewhere, but I can't remember where now, which I have modified slightly in order to produce a "demo" of how to use it. The example first loads a real jpg file from disk into a Byte array and then it assigns the picture that the data represents to the Picture property of a VB Picture Box. In real use of course it would get an appropriate block of data from your large data file (created as described above) instead of from a jpg file on disk. Paste the following code into a VB Form containing a Picture Box and a Command Button. Change the hard coded .jpg picture path to a picture that exists on your own system. Then run the code and click the button.

Mike

Option Explicit
Private Const GMEM_MOVEABLE = &H2
Private Declare Function GlobalAlloc Lib "kernel32" _
(ByVal uFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GlobalLock Lib "kernel32" _
(ByVal hMem As Long) As Long
Private Declare Function GlobalUnlock Lib "kernel32" _
(ByVal hMem As Long) As Long
Private Declare Sub MoveMemory Lib "kernel32" _
Alias "RtlMoveMemory" (pDest As Any, _
pSource As Any, ByVal dwLength As Long)
Private Declare Function CLSIDFromString Lib "ole32" _
(ByVal lpsz As Any, pclsid As GUID) As Long
Private Declare Function OleLoadPicture Lib "olepro32" _
(pStream As Any, ByVal lSize As Long, _
ByVal fRunmode As CBoolean, riid As GUID, _
ppvObj As Any) As Long
Private Type GUID
dwData1 As Long
wData2 As Integer
wData3 As Integer
abData4(7) As Byte
End Type
Private Enum CBoolean
CFalse = 0
CTrue = 1
End Enum
Private Declare Function CreateStreamOnHGlobal _
Lib "ole32" (ByVal hGlobal As Long, _
ByVal fDeleteOnRelease As CBoolean, _
ppstm As Any) As Long
Private Const sIID_IPicture = _
"{7BF80980-BF32-101A-8BBB-00AA00300CAB}"
Private b1() As Byte

Private Function PictureFromBits(abPic() As Byte) _
As IPicture
Dim nLow As Long
Dim cbMem As Long
Dim hMem As Long
Dim lpMem As Long
Dim IID_IPicture As GUID
Dim istm As stdole.IUnknown
Dim ipic As IPicture
On Error GoTo Out
nLow = LBound(abPic)
On Error GoTo 0
cbMem = (UBound(abPic) - nLow) + 1
hMem = GlobalAlloc(GMEM_MOVEABLE, cbMem)
If hMem Then
lpMem = GlobalLock(hMem)
If lpMem Then
MoveMemory ByVal lpMem, abPic(nLow), cbMem
Call GlobalUnlock(hMem)
If (CreateStreamOnHGlobal(hMem, CTrue, istm) = 0) Then
If (CLSIDFromString(StrPtr(sIID_IPicture), _
IID_IPicture) = 0) Then
Call OleLoadPicture(ByVal ObjPtr(istm), _
cbMem, CFalse, IID_IPicture, PictureFromBits)
End If
End If
End If
End If
Out:
End Function

Private Sub Command1_Click()
' Test the PictureFromBits routine by loading a picture
' file (jpg in this example) from a disk file into a byte
' array (the entire file) and use the function to assign
' the byte array data to a VB picture box Picture property.
Open "c:\tulips.jpg" For Binary As #1
ReDim b1(1 To LOF(1)) 'set byte array to size of file
Get 1, , b1 ' get the file into the array
Close 1
Picture1.AutoSize = True
Picture1.Picture = PictureFromBits(b1)
' or, alternatively, if you want a stdPicture object
' without the the need for a VB picture box you
' could use:
' Dim p1 As StdPicture
' Set p1 = PictureFromBits(b1)
End Sub








.