Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need an image container wider than picturebox !!

Status
Not open for further replies.

HoustonGuy

Programmer
Jun 29, 2000
165
US
My VB brothers and sisters -

I need a container to hold images that can be displayed wider than the default 16,383 of a picturebox.

I have images that are programatically displayed at runtime, but the picturebox I am using stops displaying the images after it reaches its max width of 16,383.

Help! Any suggestions? Third party OCX's? Anything?

Thanks!

Cody ford
Data Mining, Cleansing and Reporting Specialist
codyjford@hotmail.com

SQL, VB6, Seagate Info/Crystal Reports

 

Use a picture variable and the form itself, or use the picture variable, a picture box, a couple of scroll bars, and the BitBlt API.

Good Luck

 
Can't use the form itself - too many restrictions due to layout, proper GUI interaction, etc.

The picturebox is the problem, so I can't use it as a container. I don't have a problem getting the images into the picturebox, so I don't have to incorporate the BitBlt method.

I'm currently loading the images into a picturebox, that is contained inside another picturebox to allow for scrolling.

Thanks anyway. :)

Cody ford
Data Mining, Cleansing and Reporting Specialist
codyjford@hotmail.com

SQL, VB6, Seagate Info/Crystal Reports

 
An image control inside the picture box and scrollbars to move the image inside the picturebox should do the trick. I will suggest to contain these in a usercontrol.
 
An image control can't act as a container.

Also, I have found no way of scrolling an image inside the picturebox without using the standard Parent/Child pictureboxes to create a viewport. Do you have sample code for this? Typical scrollbar constraints don't seem to apply.

Thanks for any and all suggestions!


Cody ford
Data Mining, Cleansing and Reporting Specialist
codyjford@hotmail.com

SQL, VB6, Seagate Info/Crystal Reports

 
Only suggestion that I would have is that the images be loaded into an array ( for example, a square of 4 picture boxes set to the max size) that are inside the main "viewport" picturebox. When you scroll each of the 4 boxes are adjusted as needed. With no border and the right alignment, you will see no edges, so it will all look like one big box. The images would have to be placed in the appropriate container ( one of the 4 pictureboxes ).

This would double the height and width beyond what you have now.

I am assuming that placeing the images directly in the main viewport picturebox and moveing them as necessary when scrolled is not a solution, as changing the positions of that many images is probably too slow or jerky. There is probably a way wround this using bitBlt, but I'm not up on that.

Hope this helps,

Robert
 
I think it would be useful if you could explain to us why something that, on a 1024 x 768 screen, represents something like 16 x 21 screens worth of graphics data. Once we understand this we may be able to suggest alternative strategies.
 
I can appreciate wanting to understand the problem more. Let me explain more fully:

The issue is simply wanting to view dynamically loaded images in an application - not thumbnails, mind you. If you have a directory of 500 images in a folder there appears to be no way to view them consecutively, side by side, before the width limitation of the picturebox cuts the list of images prematurely. Many of the images are left unviewed.

Resolution will make some difference - but the picturebox width limitation is at 16,383. I'm running 1280 X 1024.

Here's what the app has for displaying the images:

Two picturebox controls - one parent, one child.
An image array that is dynamically created side by side for each image found in the directory.

As the folder is chosen, the images load dynamically side by side, but the display runs out of room in the picturebox and may even cut the last image in half.

The width limitation 0f the picturebox is a known limitation, so off the cuff I'm thinking there must be a workaround somewhere out there.

Does this help?






Cody ford
Data Mining, Cleansing and Reporting Specialist
codyjford@hotmail.com

SQL, VB6, Seagate Info/Crystal Reports

 
So, in reality, you actually only need to display about 1280 x 1024 pixels at any given time - which leads to the possibility that you might only need that much loaded at any given time...
 
At any given time I can only see images that are scrolled past the window. I'm not sure if I understand your point.

I need to be able to browse the entire folder of images - even though only the width of the screen can be seen at any given time, I need a means of scrolling through all of the images.

The resolution will only allow me to see a certain number of images at once, but i need to be able to scroll and browse through them all.

Cody ford
Data Mining, Cleansing and Reporting Specialist
codyjford@hotmail.com

SQL, VB6, Seagate Info/Crystal Reports

 
The point is that you don't need to load all your images at any time. You only ever need to load enough to fill the display.
 
In fact, here's an example I've not together to illustrate the point. You'll need a form with two picture boxes on it, one called picDisplay and the other picLoad. You'll also need to add a reference to the Microsoft Scripting Runtime library. Finally you'll need a horizontal scroll bar
[tt]
Option Explicit

Private Type PictureDisp
width As Long
positionleft As Long
filename As String
End Type

Private myPictures() As PictureDisp
Private ScrollRatio As Double

Private Sub Form_Load()
picLoader.Visible = False
picLoader.ScaleMode = vbPixels
picDisplay.ScaleMode = vbPixels
picDisplay.AutoRedraw = True
Form1.ScaleMode = vbPixels
GetImages "c:\downloads\jpegs" ' You would choose your image folder here
End Sub

Private Sub Form_Resize()
picDisplay.Move 0, 0, Form1.ScaleWidth, Form1.ScaleHeight - 16
HScroll1.Move 0, picDisplay.ScaleHeight, Form1.ScaleWidth, 16
Form1.Refresh
DisplayImages
End Sub

Private Sub HScroll1_Change()
DisplayImages
End Sub

Private Sub GetImages(strSourceFolder As String)
Dim filename As File
Dim myPicture As Picture

Dim lp As Long
Dim FullWidth As Long

With New FileSystemObject
For Each filename In .GetFolder(strSourceFolder).Files
If filename.Type = "JPEG Image" Then
Set picLoader = LoadPicture(filename.Path)
With picLoader
ReDim Preserve myPictures(lp)
myPictures(lp).width = .width + 16 ' the 16 is to put a gap between the images when displayed
myPictures(lp).positionleft = FullWidth
FullWidth = FullWidth + myPictures(lp).width
myPictures(lp).filename = filename.Path
End With
lp = lp + 1
End If
Next
End With
HScroll1.Min = 0
HScroll1.Max = 32767 'max it can be
ScrollRatio = FullWidth / HScroll1.Max ' we may well have a maximum theoretical width greater than Hscroll can deal with, so use a ratio
HScroll1.SmallChange = 32 ' pixels
HScroll1.LargeChange = 320 ' pixels
picDisplay.Cls
End Sub

Private Sub DisplayImages()
Dim lp As Long
Dim InView As Boolean
Dim LeftPosition As Long
Dim RightPosition As Long

picDisplay.Cls
For lp = LBound(myPictures) To UBound(myPictures)

' Here's where we verify whether an image is in our viewport before bothering to either load or display it
InView = False
LeftPosition = myPictures(lp).positionleft - HScroll1 * ScrollRatio
RightPosition = myPictures(lp).positionleft + myPictures(lp).width - HScroll1 * ScrollRatio
If LeftPosition >= 0 And LeftPosition < picDisplay.width Then
InView = True
ElseIf LeftPosition < 0 And RightPosition > 0 Then
InView = True
End If

' If it is in view, then load and display at the appropriate position in the viewport
If InView Then
Set picLoader = LoadPicture(myPictures(lp).filename)
picDisplay.PaintPicture picLoader, myPictures(lp).positionleft - HScroll1 * ScrollRatio, 0
End If
Next

End Sub
 
Ah, I see - why load more than the control can show?

I'll take a look at this code.
Thanks for taking the time - very kind of you.



Cody ford
Data Mining, Cleansing and Reporting Specialist
codyjford@hotmail.com

SQL, VB6, Seagate Info/Crystal Reports

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top