You'll need to find/ download the DILib.dll
Or I could email it to you.
Here's the module that goes with it:
modJpgDISave
Code:
Option Explicit
'the mod requires DILIB.DLL, either in the folder with the app
'or in the proper windows dir and registered
'It takes a .bmp (the only image type VB can save) from a picture control
'then converts/saves it as a .jpg
Public Declare Function DIWriteJpg Lib "DILib.dll" Alias "#1" _
(DestPath As String, _
SrcPath As String, _
ByVal Quality As Long, _
Optional ByVal progressive As Long) As Long
Public Const DI_SUCCESS = 0
Public Const DI_ERR_CALL = 1
Public Const DI_ERR_INFILE = 2
Public Const DI_ERR_OUTFILE = 3
Public g_sPicFile As String
Public Function SaveAsJPG(ByRef objPicCntrl As Object, _
ByRef DestFilePath As String, _
Optional ByRef Quality As Long = 100) As String
'Takes the image from any VB picture control with a Picture Property
'and saves it to file
'Returns and empty string if Successful
'otherwise returns the error msg
Dim sTempBmp As String
Dim rtnVal As Long
Dim sMsg As String
If Quality > 100 Then
Quality = 100
ElseIf Quality < 1 Then
Quality = 1
End If
sTempBmp = AddSep(App.Path) & "temp.bmp"
SavePicture objPicCntrl.Picture, sTempBmp
DoEvents
rtnVal = DIWriteJpg(ByVal DestFilePath, ByVal sTempBmp, Quality) ', Abs(chkProg.Value))
DoEvents
SaveAsJPG = ErrMsg(rtnVal, DestFilePath, sTempBmp)
Kill sTempBmp
End Function
Private Function ErrMsg(ByRef ErrNumber As Long, ByRef JpgPath As String, ByRef SourcePath As String) As String
'converts the error number from the dll to a string
Dim sMsg As String
If ErrNumber <> DI_SUCCESS Then
sMsg = "DIWriteJpg did not succeed" & vbCrLf
Select Case ErrNumber
' Case DI_SUCCESS 'Success
' picJpg.Picture = LoadPicture(loadStr)
Case DI_ERR_CALL 'An error occured
sMsg = sMsg & "Error Call (0x00000001)"
Case DI_ERR_INFILE
sMsg = sMsg & "Error InFile (0x00000002): " & SourcePath
Case DI_ERR_OUTFILE
sMsg = sMsg & "Error OutFile (0x00000003): " & JpgPath
End Select
ErrMsg = sMsg
End If
End Function
Public Function AddSep(ByVal Path As String) As String
If RIGHT(Path, 1) = "\" Then
AddSep = Path
Else
AddSep = Path & "\"
End If
End Function
Jpegs are both too big and too lossy. I'm really looking for GIF.
I found many solutions, all of which require vic32.dll. After downloading several different versions of vic32.dll, I can't get past the following error message:
I don't need this to be a clean or professional solution, since as I said I'm the only one who will ever run it. If there were some way to open the file in paint and automate a Save As, that would be fine. Can you use Sendkeys to manipulate the file menu of paint?
Or a shareware conversion utility with command line processing would be fine as well. Mostly I need the compression I'm getting from paint, since I'm attaching these images to a messageboard with a small attachment limit.
Paint compresses the 9.4mb bitmaps down to 179k gifs.
Jpegs are both too big and too lossy. I'm really looking for GIF
GIFs can be worse, depending on how many colors are in the BMP. GIFs have a max of 256 colors.
MS Paint for example, uses a default 216 color palette. Using some advanced adaptive palette algorithms +/- dithering can make the GIF appear better. Converting BMP to GIF can be done manually since the compression algorithm is pretty much open source -- but the the palette will determine the overall quality.
Insomnia is just a byproduct of, "It can't be done"
imagemagick might be a bit bulky for what you want but it will do the job, possibly better than many others, in theory it can be used in VB. As LaVolpe is saying the conversion from (presumably) 24 or 32 bit down to 8 bit is the key to the quality.
Alternatively you might want to consider converting to Ping, depending on the nature of the image Pings can compress to a similar size to Gifs without any data loss. (Photos convert badly)
Attached is a zip of one of the original bitmap images plus its gif counterpart after converting with paint so you guys can get a feel for what might work best.
I run a crawler each day and post the results to the group forum, but it is tedious to have to open paint and convert the image manually each day. Edgemeal's suggestion looks promising. It's slow -- which I don't care about at all -- but it creates a gif of 185k compared to the 177k in the archive. (Converting the same bitmap.) That's probably close enough.
Is there any way for a PNG or JPG to compress smaller while still leaving the text clearly legible? I'm open to any ideas; I'm not married to GIFs. Anything I can do to reduce the final image size would be highly desirable.
Attached is a zip of one of the original bitmap images plus its gif counterpart after converting with paint so you guys can get a feel for what might work best.
I run a crawler each day and post the results to the group forum, but it is tedious to have to open paint and convert the image manually each day. Edgemeal's suggestion looks promising. It's slow -- which I don't care about at all -- but it creates a gif of 185k compared to the 177k in the archive. (Converting the same bitmap.) That's probably close enough.
Is there any way for a PNG or JPG to compress smaller while still leaving the text clearly legible? I'm open to any ideas; I'm not married to GIFs. Anything I can do to reduce the final image size would be highly desirable.
Using GDI+ I created a 177K GIF from that BMP, quality looks OK, guess you'll just have to try it.
Did some playing with it.
The bmp only uses 7 colors so a gif is the way to go.
Using PSP and reducing the colorDepth to 8, took the gif size down to 129 kb.
The lowest setting I tried with the jpg code I posted was 20% quality.
It was almost 4 times the size of the gif, and artifacting badly.
Last edited by longwolf; Nov 4th, 2008 at 02:06 AM.
Is there any way for a PNG or JPG to compress smaller while still leaving the text clearly legible? I'm open to any ideas; I'm not married to GIFs. Anything I can do to reduce the final image size would be highly desirable.
The nature or your image is not suited to jpeg compression which is best suited for photographs. Ping works well, down to 40k without any data loss (66k if not indexed).
Edit: Hmm, it seems photobucket has messed with the file by reducing the dimensions making the file size larger(??) attached is the 40KB version.
The nature or your image is not suited to jpeg compression which is best suited for photographs. Ping works well, down to 40k without any data loss (66k if not indexed).
That is phenomenal; an ideal format. I have no clue how to automate the conversion, though. Little help?
EDIT: Actually, looks like Edgemeal's posted solution can convert to png. I'll see if I can get it to work.
Hmm, Edgemeal's solution -- which is fantastic, thanks! -- creates a 195k png. How did you make the 40k version?
Edge, I'd rate you but it says I have to spread it around.
EDIT: Milk, did you create that 40k png using ImageMagick? I was quickly overwhelmed when looking at that site. Are there instructions on how to download a simple exe version anywhere?
Last edited by Ellis Dee; Nov 4th, 2008 at 09:32 AM.
Ellis Dee, will your app always run on XP or higher? Or will it always run on Win2K with GDI+ installed (not installed by default but is a free download for 2K). If not, converting to PNG requires a bunch more work.
Insomnia is just a byproduct of, "It can't be done"
Ellis Dee, will your app always run on XP or higher? Or will it always run on Win2K with GDI+ installed (not installed by default but is a free download for 2K). If not, converting to PNG requires a bunch more work.
Yes, only XP or higher. (It will only ever be run by me on my personal machine, which is XP.)
Hmm, Edgemeal's solution -- which is fantastic, thanks! -- creates a 195k png. How did you make the 40k version?
Edge, I'd rate you but it says I have to spread it around.
EDIT: Did you create that using ImageMagick? I was quickly overwhelmed when looking at that site. Are there instructions on how to download a simple exe version anywhere?
PNG uses several different filtering mechanisms to try and compress images more and more. The app is probably testing all 5 filters and picking the best one.
I can beat the 195k -- how about 66kb? But I didn't use an application, I used old fashioned parsing, bit shifting & compression via the official zLIB.dll.
Edited: Found a miscalc in my routines, got it down to 51kb.
Last edited by LaVolpe; Nov 4th, 2008 at 09:50 AM.
Insomnia is just a byproduct of, "It can't be done"
You can also do this simply using WIA if you have it installed:
Code:
Option Explicit
'
'Requires a reference to:
' Microsoft Windows Image Acquisition Library v2.0
'
Public Sub ImgConvert( _
ByVal InFileName As String, _
ByVal OutFileName As String, _
ByVal OutFormat As String)
Dim Img As WIA.ImageFile
Dim ImgProc As WIA.ImageProcess
Set Img = New WIA.ImageFile
Img.LoadFile InFileName
Set ImgProc = New WIA.ImageProcess
With ImgProc.Filters
.Add ImgProc.FilterInfos("Convert").FilterID
.Item(1).Properties("FormatID").Value = OutFormat
End With
Set Img = ImgProc.Apply(Img)
On Error Resume Next
Kill OutFileName
On Error GoTo 0
Img.SaveFile OutFileName
End Sub
Private Sub Main()
ImgConvert "Western City.bmp", "Western City.gif", wiaFormatGIF
ImgConvert "Western City.bmp", "Western City.png", wiaFormatPNG
MsgBox "Complete"
End Sub
It does not do any extensive optimization of compression (yielding the same 176K to 194K files as already described).
The PNGOUT plugin for IrfanView (relying on KZIP deflation) can produce a PNG output at about 34.4KB. The stand alone command line PNGOUT utility might be useful from a VB6 program. PNGOUT Tutorial.
I do not know how to do that. Could you post the code you used?
Attached is probably more than what you are expecting. Just unzip it to a new folder and run the project. I created a special form, for you, when it starts up. Let me know what you think; the best part is that because it is raw source code, you can customize/automate to your heart's desire.
Edited: attachments removed
Last edited by LaVolpe; Nov 10th, 2008 at 12:27 PM.
Insomnia is just a byproduct of, "It can't be done"
Using GDI+ I created a 177K GIF from that BMP, quality looks OK, guess you'll just have to try it.
Edgemeal, this is driving me crazy. Why doesn't my picturebox have a numeric .Picture property like yours does? What's the trick?
I'd really like to use your technique because it's the only one that uses pure VB6 code; no references required. But no matter what I do, the following line always returns false:
If GdipCreateBitmapFromHBITMAP(hBitmap, 0&, lBitmap) = 0 Then
hBitmap is always 0 in my project, and always has a nice juicy number in yours. Even when I copied all your code over verbatim, and even copied the picturebox control from your project directly into mine. Still nada.
Please help!
Last edited by Ellis Dee; Nov 8th, 2008 at 11:04 AM.
Ellis Dee. Actually GDI+ is an external reference for systems less than XP. Win2k, NT4, and lower requires users to download the dll or get it from elsewhere (i.e., some other app installed it).
Regarding the error, hBitmap should be the GDI bitmap (i.e., picturebox's image handle), lBitmap should be non-zero if all went fine -- that would be the GDI+ reference.
Regarding the error, hBitmap should be the GDI bitmap (i.e., picturebox's image handle), lBitmap should be non-zero if all went fine -- that would be the GDI+ reference.
I copied all of his code verbatim, but the .Picture property of the picturebox gets passed as 0, which causes the call to fail.
Why would his picturebox's .Picture property have a value in his project, but then return 0 when I copy & paste it into my project?
And LaVolpe, not sure what's going on with the project you attached, but I get a blizzard of popups.
When opening the project, it first tells me an rtf file isn't found, which I ignore and continue to load anyway.
Then when I run it, it tells me I need to extract a dll from a RES file, which I say yes to. Then it tells me it wrote the dll to the app.path and that I should try again.
Lather, rinse, repeat. All it ever does is repeat these three messages, endlessly.
And LaVolpe, not sure what's going on with the project you attached, but I get a blizzard of popups.
When opening the project, it first tells me an rtf file isn't found, which I ignore and continue to load anyway.
Then when I run it, it tells me I need to extract a dll from a RES file, which I say yes to. Then it tells me it wrote the dll to the app.path and that I should try again.
Lather, rinse, repeat. All it ever does is repeat these three messages, endlessly.
Ellis, sorry about that. The zLIB1.dll it wrote to your project folder obviously isn't in the system's DLL path. If you toss that DLL into your system path, all should be fine. I didn't include the RTF because it is rather large. If you decide you like the project, I can post the rtf too. Let me know.
Insomnia is just a byproduct of, "It can't be done"
Try using the CommonDialog control to Open, change the extension. And then Close it, using those commands. Also I am not quite sure on the command to change the filename, but it will either be in a batch file usage or in VB.
I have a huge free products range, of computer software in which you can download using any kind of 64-Bit Web Browser. Also there is coming a Social Networking section that I am making on my Website...
|Ambra Productions Inc. | The Black Sun Society | The Black Shield | Ambra College | Church of the Black Sun | Ambra Productions Inc's Homepage | Boomtick Venues: Ambar Nightclub, Jack Rabbit Slim's, Villa Nightclub and Lucy's Love Shack | Pasta Ambra | Fish Feast Company | Wallet Wizard | Ambrose Liquor | Ambar Tavern | Ambra University | Ambra Cheese |
Do you wish to do unpaid work for me??? If so, the PM me on this Forum, and then we can get to work, programming for the future of computers go by the name of ThEiMp. This is my ghost writers name. Also my nickname, means that I am: The Imperial of the Technology Industry, so then to make it really short, I just then wrote: The Imp, which is where I get the nickname from...
Also you shouldn't try to use image compression, becuase it will remove chunks of code away from the file itself and then continue use of file compression will screw with the file's image quality. Image compression, is the last process on any image that you make using an image processing package, like Paint Shop Pro or even Photo Shop.
I have a huge free products range, of computer software in which you can download using any kind of 64-Bit Web Browser. Also there is coming a Social Networking section that I am making on my Website...
|Ambra Productions Inc. | The Black Sun Society | The Black Shield | Ambra College | Church of the Black Sun | Ambra Productions Inc's Homepage | Boomtick Venues: Ambar Nightclub, Jack Rabbit Slim's, Villa Nightclub and Lucy's Love Shack | Pasta Ambra | Fish Feast Company | Wallet Wizard | Ambrose Liquor | Ambar Tavern | Ambra University | Ambra Cheese |
Do you wish to do unpaid work for me??? If so, the PM me on this Forum, and then we can get to work, programming for the future of computers go by the name of ThEiMp. This is my ghost writers name. Also my nickname, means that I am: The Imperial of the Technology Industry, so then to make it really short, I just then wrote: The Imp, which is where I get the nickname from...
Or instead of using .Picture in the save command try using the .Image.
' AutoRedraw on
' Draw stuff
SavePictureFromHDC(Picture1.Image,.... ' save it
Finally got around to trying your suggestions.
This works flawlessly; you rock. Thanks!
I'm marking this thread resolved, though I may post some followup questions as I get time to play with the PNG format. GIF will suffice in the meantime.