Solved

how to open resize and save jpegs

Posted on 2004-09-16
9
293 Views
Last Modified: 2013-11-19
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?

0
Comment
Question by:esdfesdf
  • 5
  • 3
9 Comments
 
LVL 51

Accepted Solution

by:
Ryan Chong earned 400 total points
ID: 12081363
Try see:

VB Image Editor
http://www.freevbcode.com/ShowCode.Asp?ID=4280

Which included info on how to use Intel® JPEG Library to save graphic to Jpg extension.

Also at:
http://www.vbaccelerator.com/codelib/gfx/vbjpeg.htm
0
 
LVL 51

Expert Comment

by:Ryan Chong
ID: 12081376
I also used an ocx called PicFormat32.ocx which can convert images to gif, bmp, jpg and vice versa easily.

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
0
 
LVL 3

Expert Comment

by:sgayatri
ID: 12082547
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,compressioninfo, saveatzoom,pagenumber

''' on the form click on imgedit control and press f1 to get full help on it.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:esdfesdf
ID: 12088736
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
0
 
LVL 51

Expert Comment

by:Ryan Chong
ID: 12090166
esdfesdf, can i know which example / link you refer to?

regards
0
 

Author Comment

by:esdfesdf
ID: 12090216
0
 
LVL 51

Expert Comment

by:Ryan Chong
ID: 12090581
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
0
 

Author Comment

by:esdfesdf
ID: 12091785
sorry, but how do I get the jpg into the picturebox using the intel jpeg lib?
0
 
LVL 51

Expert Comment

by:Ryan Chong
ID: 12091957
>>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)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
using Access 8 75
How to debug this code 7 64
passing parameter in sql procedure 9 65
Send outlook email from VBS Script 2 45
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Learn how to create interesting presentations by including videos to keep your audience engaged using Prezi. Select "Insert" from the top menu in your Prezi editor: Select "YouTube Video": Paste the video URL into the prompt: "Select "Insert":…
Learn how to download your full Prezi presentation for offline presenting. Prezi doesn’t have to be viewed and shared in a web browser, even with a free account you can download your full presentation to share with others. Be sure to download any vi…

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question