Re: loading, Flipping and saving jpgs
- From: "Mike Williams" <mikea@xxxxxxxxxxxxxxxxx>
- Date: Sun, 23 Mar 2008 13:24:11 -0000
"Jim" <jmlawler@@xxxxxxxxxxxxx> wrote in message
news:uUoYi3HjIHA.5280@xxxxxxxxxxxxxxxxxxxxxxx
Since the camera is mounted in a way that the picture
is upside down I need to automatically flip the picture
right side up.(The camer has a setting to do this but it
only changes the real-time view, not the jpgs).
If you want a ready made solution then Irfanview, as suggested by Steve Easton and Jim Mack, is probably your best bet.
My research indicates that I should use the StretchBlt
API for speed since in a given day over 10,000 jpgs
may be generated.
Actually when dealing with blitting and stretching operations, especially on large bitmaps, there is very little difference in speed between the API methods and the VB native methods. You're talking about milliseconds to flip an image, and 10,000 of them could be flipped in very short order. The code posted by Larry will be fine, with a slight modification to make it flip in both directions so as to properly turn the image upside down. Something like:
Private Sub Command1_Click()
With Picture1
.PaintPicture .Picture, 0, 0, _
.ScaleWidth, .ScaleHeight, _
.ScaleWidth, .ScaleHeight, _
-.ScaleWidth, -.ScaleHeight
.Picture = .Image
End With
End Sub
You will still need to use a third party library to convert flipped bitmap back into a jpeg, but there are many such libraries freely available that work well with VB6. However, when using such simple methods you really need to ensure that the system is running at full colour depth because loading a jpeg into a PictureBox or into a StdPicture object using the LoadPicture function or by setting a Picture property will degrade the colours when the code is run on a system running at 16 bit colour depth or less. This is not too much of a problem these days though because I think most systems nowadays run at full colour depth.
You can actually load jpegs into a full colour DIBSection in VB6, even on machines that are running at 16 bits or less, and without using GDI+, but it takes quite a bit of work to do so. You'll find some code to do that at the vbaccelerator site if you're interested.
Otherwise you can use GDI+, which can do these things quite easily. You don't need to go to dotnet to use GDI+. VB6 can use it quite easily. One place to start if you decide to use this method is:
http://www.vbaccelerator.com/home/VB/Code/vbMedia/Using_GDI_Plus/Reading_and_Writing_JPG__PNG__TIF_and_GIF_Files/article.asp
The only thing is I have never used GDI+ in earnest myself and so I don't know whether or not the GDI+ routines to get jpegs into DIBs and then back again without degrading the colours when used on a system running at 16 bit colour depth or less. Someone here who actually used GDI+ will be able to help you there. Of course if you are prepared to use only machines running at standard full colour depth (which is in fact most machines these day) then you don't need to worry about those things anyway.
One thing I would certainly suggest though is that you think carefully about whether you actually do want to perform this flipping of the jpeg in code. Most code that does so first converts the jpeg into a bitmap and then works on the bitmap and finally saves the result back out again as a jpeg. I don't know whether or not IrfanView or the GDI+ stuff does that, but certainly most code does. The problem with that is you end up with "not quite what you started with" because you are effcetively decompressing some image data and then working on it and then compressing it once more and then saving it again. This is a bit like copying a song "tape to tape" in the old fashioned way, and then copying the copy. Each time you make a copy, even if you do it just once, there is bound to be some loss of quality. So, perhaps you might like to look at a completely different method, one which manipulates the jpeg data itself and effectively flips it in a lossless way. As I've said, I don't know whether or not IrfanView performs this feat, but if it doesn't then there certainly are programs out there that do, so you end up with completely lossles flipping of your jpeg. Again, I've never done that myself but a few minutes on Google has turned up quite a few possibilities, most of which cost money of course, but very little money. Here is one example that works in the way I have described and that is very cheap. I can't vouch for it myself because I have never tried it, but I'm sure it is worth looking at:
http://www.batchimage.com/product/batchjpegrotator/index.html
This sort of thing can almost certainly be done in straight VB code by loading the jpoeg into a Byte array and working directly on the data, but you would need a lot of knowledge about the jpeg file format in order to do it and I'm afraid I don't have that knowledge myself. Someone else here might come forward with such a solution though?
Having said that, the lossless jpeg rotator at the above link costs just 10 Euros, little more than the price of a hamburger and a can of Coke® ;-)
Mike
.
- References:
- loading, Flipping and saving jpgs
- From: Jim
- loading, Flipping and saving jpgs
- Prev by Date: Re: vista and VB6
- Next by Date: Re: loading, Flipping and saving jpgs
- Previous by thread: Re: loading, Flipping and saving jpgs
- Next by thread: Re: loading, Flipping and saving jpgs
- Index(es):