Multiple images to a single bmp/jpg image

Reply

Join Date: Sep 2006
Posts: 4
Reputation: rroygaga is an unknown quantity at this point 
Solved Threads: 0
rroygaga rroygaga is offline Offline
Newbie Poster

Multiple images to a single bmp/jpg image

 
0
  #1
Sep 19th, 2006
I need help. I am developing an application wherein the user selects multiple images and are displayed on a form. With this application, i need to convert these multiple images into a single image. Any ideas?
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Multiple images to a single bmp/jpg image

 
0
  #2
Sep 19th, 2006
Like, by having all the images side by side? If you can give me a better description, I can see what I can do.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 4
Reputation: rroygaga is an unknown quantity at this point 
Solved Threads: 0
rroygaga rroygaga is offline Offline
Newbie Poster

Re: Multiple images to a single bmp/jpg image

 
0
  #3
Sep 21st, 2006
Originally Posted by Comatose View Post
Like, by having all the images side by side? If you can give me a better description, I can see what I can do.
Hello,
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?
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Multiple images to a single bmp/jpg image

 
0
  #4
Sep 21st, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 4
Reputation: rroygaga is an unknown quantity at this point 
Solved Threads: 0
rroygaga rroygaga is offline Offline
Newbie Poster

Re: Multiple images to a single bmp/jpg image

 
0
  #5
Sep 27th, 2006
I will download the class and try it.
You mentioned about displaying multiple images in one picture box and save it as a bmp, how is this done?
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 36
Reputation: sendoshin is an unknown quantity at this point 
Solved Threads: 1
sendoshin sendoshin is offline Offline
Light Poster

Re: Multiple images to a single bmp/jpg image

 
0
  #6
Sep 30th, 2006
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.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Public Sub CombineCollage()
  2. ' This array is needed because of the way the ZOrder works.
  3. Dim colPbx() As PictureBox
  4. ReDim colPbx(0)
  5. ' Common Dialog to let the user pick a filename for saving.
  6. cdlImage.DefaultExt = ".bmp"
  7. cdlImage.DialogTitle = "Save Collage to an Image"
  8. cdlImage.Filter = "Bitmap File (*.bmp)|*.bmp"
  9. ' CancelError is set to True. I always do this.
  10. On Error GoTo SaveImageCancelled
  11. cdlImage.ShowSave
  12. On Error GoTo 0
  13. ' Get the hidden PictureBox set up to create the combined image.
  14. pbxHiddenCollage.AutoRedraw = True
  15. pbxHiddenCollage.Cls
  16. ' Find every PictureBox on the form whose Tag is "Collage".
  17. For Each ctlObj In Me.Controls
  18. If ((TypeOf ctlObj Is PictureBox)) And ctlObj.Tag = "Collage" Then
  19. ReDim Preserve colPbx(UBound(colPbx) + 1)
  20. Set colPbx(UBound(colPbx)) = ctlObj
  21. End If
  22. Next
  23. ' Draw the combined image on the hidden PictureBox.
  24. For countVar = UBound(colPbx) To 1 Step -1
  25. pbxHiddenCollage.PaintPicture colPbx(countVar).Image, _
  26. colPbx(countVar).Left, colPbx(countVar).Top, _
  27. colPbx(countVar).Width, colPbx(countVar).Height, _
  28. 0, 0, colPbx(countVar).Width, colPbx(countVar).Height
  29. Next
  30. ' Here's where you save to .bmp
  31. SavePicture pbxHiddenCollage.Image, cdlImage.FileName
  32. ' Be careful not to execute the error handler!
  33. Exit Sub
  34. SaveImageCancelled: ' Error handler - the user pressed Cancel
  35. On Error GoTo 0
  36. Exit Sub ' Makes adding new error handlers easier.
  37. End Sub
Hope this helps!

- Sendoshin
Last edited by sendoshin; Sep 30th, 2006 at 6:04 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Multiple images to a single bmp/jpg image

 
0
  #7
Sep 30th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 4
Reputation: rroygaga is an unknown quantity at this point 
Solved Threads: 0
rroygaga rroygaga is offline Offline
Newbie Poster

Re: Multiple images to a single bmp/jpg image

 
0
  #8
Oct 3rd, 2006
Thanks. I will try this.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC