| | |
Multiple images to a single bmp/jpg image
![]() |
•
•
Join Date: Sep 2006
Posts: 4
Reputation:
Solved Threads: 0
•
•
•
•
Like, by having all the images side by side? If you can give me a better description, I can see what I can do.
Thanks for the interest.
Its like - the user has a choice of 15 -20 images, he may select some images, usually in 2 x 2 or 2 x 3 or 2 x 4 or 3 x 3 formats. At present I am displaying them in single picture boxes, placed according to the selected format on the form.
The requirement now is to group all these images to form a single jpg image, through the VB program, without the user opening any other programs like Photoshop or anything else.
I tried displaying them on Crystal report, but it becomes bulky.
I tried exporting the Crystal report to pdf and saving it, but the requirement is to save as jpg.
Anyway to convert pdf to jpg? There are a few softwares available, but can we do it through VB code?
None that I know of.... in fact, to my knowledge, I haven't found VB code that will save a picturebox to a jpg.... all the methods I know of, save the files as bitmaps. I can tell you how to put all the pictures in 1 picturebox, and I can tell you how to save that picture to a .bmp file.... but that doesn't do you any good. Now, I have found this class, but I've never used it before, and it claims to work: http://www.planet-source-code.com/vb...50065&lngWId=1.
•
•
Join Date: Sep 2006
Posts: 36
Reputation:
Solved Threads: 1
Saving images as .jpg, .png, .gif, etc. from within VB is possible with GDI+, but since GDI+ is a technology that came around after VB6, you either have to upgrade to .NET (which I'm avoiding ATM), or get something which will allow you to access the GDI+ library.
You're in luck when it comes to the latter option. At vbAccelerator there is a project - still in development, unfortunately, but read on - which exposes the GDI+ library to VB6 (and likely VB5). The most important part is the GDI+ type library (which is fully functional and not in development). This gives you direct access to the GDI+ API. However, since any API is hard to work with in VB, there is also a GDI+ wrapper DLL (the part which is in development) designed to abstract all of the API stuff with VB classes, objects, methods, and properties. So far, image and bitmap support are complete. For more details, see the links.
As to drawing multiple images in the same PictureBox, here's where you would use the PaintPicture method of the PictureBox. Also, just so you know, Forms also have the PaintPicture method.
Let's say you use your current set-up, and you only want to make everything into a single image during the save process. You could in fact use this same code if you were to allow the user to move the PictureBoxes around on the form into whatever position pleases them most. The code is deliberately designed to work no matter how many PictureBoxes you have on the form - just be sure to set their Tag properties to "Collage" before you run this Sub. The Sub uses a hidden PictureBox control large enough to hold everything you want to save (pbxHiddenCollage), so don't forget to create that, too.
Hope this helps!
- Sendoshin
You're in luck when it comes to the latter option. At vbAccelerator there is a project - still in development, unfortunately, but read on - which exposes the GDI+ library to VB6 (and likely VB5). The most important part is the GDI+ type library (which is fully functional and not in development). This gives you direct access to the GDI+ API. However, since any API is hard to work with in VB, there is also a GDI+ wrapper DLL (the part which is in development) designed to abstract all of the API stuff with VB classes, objects, methods, and properties. So far, image and bitmap support are complete. For more details, see the links.
As to drawing multiple images in the same PictureBox, here's where you would use the PaintPicture method of the PictureBox. Also, just so you know, Forms also have the PaintPicture method.
Let's say you use your current set-up, and you only want to make everything into a single image during the save process. You could in fact use this same code if you were to allow the user to move the PictureBoxes around on the form into whatever position pleases them most. The code is deliberately designed to work no matter how many PictureBoxes you have on the form - just be sure to set their Tag properties to "Collage" before you run this Sub. The Sub uses a hidden PictureBox control large enough to hold everything you want to save (pbxHiddenCollage), so don't forget to create that, too.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Public Sub CombineCollage() ' This array is needed because of the way the ZOrder works. Dim colPbx() As PictureBox ReDim colPbx(0) ' Common Dialog to let the user pick a filename for saving. cdlImage.DefaultExt = ".bmp" cdlImage.DialogTitle = "Save Collage to an Image" cdlImage.Filter = "Bitmap File (*.bmp)|*.bmp" ' CancelError is set to True. I always do this. On Error GoTo SaveImageCancelled cdlImage.ShowSave On Error GoTo 0 ' Get the hidden PictureBox set up to create the combined image. pbxHiddenCollage.AutoRedraw = True pbxHiddenCollage.Cls ' Find every PictureBox on the form whose Tag is "Collage". For Each ctlObj In Me.Controls If ((TypeOf ctlObj Is PictureBox)) And ctlObj.Tag = "Collage" Then ReDim Preserve colPbx(UBound(colPbx) + 1) Set colPbx(UBound(colPbx)) = ctlObj End If Next ' Draw the combined image on the hidden PictureBox. For countVar = UBound(colPbx) To 1 Step -1 pbxHiddenCollage.PaintPicture colPbx(countVar).Image, _ colPbx(countVar).Left, colPbx(countVar).Top, _ colPbx(countVar).Width, colPbx(countVar).Height, _ 0, 0, colPbx(countVar).Width, colPbx(countVar).Height Next ' Here's where you save to .bmp SavePicture pbxHiddenCollage.Image, cdlImage.FileName ' Be careful not to execute the error handler! Exit Sub SaveImageCancelled: ' Error handler - the user pressed Cancel On Error GoTo 0 Exit Sub ' Makes adding new error handlers easier. End Sub
- Sendoshin
Last edited by sendoshin; Sep 30th, 2006 at 6:04 pm.
Well said, beyond that you could also use the bitblt API call, with device contexts (which, is how making Video games with just VB and API is done). I don't suggest building an app that relies on GDI+, since it's added overhead, and possibly an install requirement for the user using the application, but you are very limited to working with JPEGs in VB6. The bitblt API call will be much faster in processing the images, but chances are you are not going to notice a difference either way.... since delving into the API can become a fairly complex playground, I suggest the code above.
![]() |
Similar Threads
- Css Fixed Background Attachment (Site Layout and Usability)
- need help with PICTURE (Visual Basic 4 / 5 / 6)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: RunTime 3075, cant see the problem? And Values are as they should be...
- Next Thread: Urgent Macro Help needed
| Thread Tools | Search this Thread |
* 6 2007 access activex add age basic beginner birth bmp calculator cd cells.find click client code college connection connectionproblemusingvb6usingoledb creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit excel excelmacro file filename form header iamthwee image inboxinvb internetfiledownload listbox listview liveperson login looping microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading remotesqlserverdatabase report save search sendbyte sites sql sql2008 sqlserver subroutine tags time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web windows






