esdfesdf
asked on
how to open resize and save jpegs
HI, I need to open resize and then (preferably) save jpegs with a selectable level of compression
does anyone have any code or a control or something to do this?
does anyone have any code or a control or something to do this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
From vb running on windows 98 you can do:
Add Kodal image edit control from Project >> components
Create a blank.jpg file; (You can scan a blank page and name it blank.jpg; as it is required to do so before display)
ImgEdit1.Image = "c:\yourfile.jpg"
ImgEdit2.Image = "c:\blank.jpg"
ImgEdit1.Display
ImgEdit2.Display
''' select your values to resize the image
ImgEdit1.DrawSelectionRect 10, 10, 1000, 1000
''' copy the selected image from image1
ImgEdit1.ClipboardCopy '10, 10, 10, 10
'''paste it on the blank page of image2
ImgEdit2.ClipboardPaste
imgedit2.savepage x.tif", filetype, pagetype, compressiontype,compressio ninfo, saveatzoom,pagenumber
''' on the form click on imgedit control and press f1 to get full help on it.
Add Kodal image edit control from Project >> components
Create a blank.jpg file; (You can scan a blank page and name it blank.jpg; as it is required to do so before display)
ImgEdit1.Image = "c:\yourfile.jpg"
ImgEdit2.Image = "c:\blank.jpg"
ImgEdit1.Display
ImgEdit2.Display
''' select your values to resize the image
ImgEdit1.DrawSelectionRect
''' copy the selected image from image1
ImgEdit1.ClipboardCopy '10, 10, 10, 10
'''paste it on the blank page of image2
ImgEdit2.ClipboardPaste
imgedit2.savepage x.tif", filetype, pagetype, compressiontype,compressio
''' on the form click on imgedit control and press f1 to get full help on it.
ASKER
ryancs -
Your code works well for opening and saving with compression, but I don't know how to resize the image. I tried this.. which doesnt work (as expected)
Dim cD As New cDIBSection
LoadJPG cD, Text1.Text
cD.Height = cD.Height * 0.5
cD.Width = cD.Width * 0.5
Dim SaveTo As String
SaveTo = App.Path & "\tessdf.jpg"
SaveJPG cD, SaveTo, tQual.Text
End Sub
sgayatri - I don't have the kodal image edit control so I couldn't use your code
Your code works well for opening and saving with compression, but I don't know how to resize the image. I tried this.. which doesnt work (as expected)
Dim cD As New cDIBSection
LoadJPG cD, Text1.Text
cD.Height = cD.Height * 0.5
cD.Width = cD.Width * 0.5
Dim SaveTo As String
SaveTo = App.Path & "\tessdf.jpg"
SaveJPG cD, SaveTo, tQual.Text
End Sub
sgayatri - I don't have the kodal image edit control so I couldn't use your code
esdfesdf, can i know which example / link you refer to?
regards
regards
ASKER
http://www.vbaccelerator.com/codelib/gfx/vbjpeg.htm
using intel jpeg lib
using intel jpeg lib
Hi,
I would resize the picture into a temporary picturebox, instead of modify the existing code from vbaccelerator, so try like:
Private Sub Command1_Click()
picTmp.AutoRedraw = True
picTmp.Visible = False
picTmp.Width = picTest.Width * 0.5
picTmp.Height = picTest.Height * 0.5
picTmp.PaintPicture picTest.Picture, 0, 0, picTmp.Width, picTmp.Height, 0, 0, picTest.Width, picTest.Height, vbSrcCopy
picTmp.Picture = picTmp.Image
picTmp.Refresh
DoEvents
Dim sI As String
Dim c As New cDIBSection
Dim i As Long
Set c = New cDIBSection
c.CreateFromPicture picTmp.Picture
sI = App.Path & "\Tempvb.jpg"
If VBGetSaveFileName(sI, , , "JPEG Files (*.JPG)|*.JPG|All Files (*.*)|*.*", 1, , , "JPG", Me.hwnd) Then
If SaveJPG(c, sI) Then
' OK!
Else
MsgBox "Failed to save the picture to the file: '" & sI & "'", vbExclamation
End If
End If
End Sub
Hope this helps
I would resize the picture into a temporary picturebox, instead of modify the existing code from vbaccelerator, so try like:
Private Sub Command1_Click()
picTmp.AutoRedraw = True
picTmp.Visible = False
picTmp.Width = picTest.Width * 0.5
picTmp.Height = picTest.Height * 0.5
picTmp.PaintPicture picTest.Picture, 0, 0, picTmp.Width, picTmp.Height, 0, 0, picTest.Width, picTest.Height, vbSrcCopy
picTmp.Picture = picTmp.Image
picTmp.Refresh
DoEvents
Dim sI As String
Dim c As New cDIBSection
Dim i As Long
Set c = New cDIBSection
c.CreateFromPicture picTmp.Picture
sI = App.Path & "\Tempvb.jpg"
If VBGetSaveFileName(sI, , , "JPEG Files (*.JPG)|*.JPG|All Files (*.*)|*.*", 1, , , "JPG", Me.hwnd) Then
If SaveJPG(c, sI) Then
' OK!
Else
MsgBox "Failed to save the picture to the file: '" & sI & "'", vbExclamation
End If
End If
End Sub
Hope this helps
ASKER
sorry, but how do I get the jpg into the picturebox using the intel jpeg lib?
>>how do I get the jpg into the picturebox using the intel jpeg lib?
You can try use the loadpicture function, no need use intel jpeg lib, in order to load a picture to picturebox, like:
picTest.Picture = LoadPicture(fPath)
You can try use the loadpicture function, no need use intel jpeg lib, in order to load a picture to picturebox, like:
picTest.Picture = LoadPicture(fPath)
More useful links regarding this can be found here:
http://www.martin2k.co.uk/vb6/tips/q16.php
http://www.visualbasiconline.net/download.php?categoria=ocx