Does anyone know how to resize a pic and Save it as JPG (if it was a BMP)
Many thanks
Printable View
Does anyone know how to resize a pic and Save it as JPG (if it was a BMP)
Many thanks
I can give code to resize the picture in a picturebox.
But to store it as a jpeg, you will have to search on the web. I know there are add-ons that will do the job.
To resize you just use StretchBlt.
I've posted numerous examples on the forums. Here's one too ;
VB Code:
' By Jamie Plenderleith ' [email][email protected][/email] ' ' This code will stretch the 'background' picture of a form to the size of the form ' Change the picDc = GeneradeDC(..) line to point to an appropriate graphic ' Option Explicit Private picDc As Long Private picWidth As Long Private picHeight As Long Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long Public Function GenerateDC(FileName As String) As Long Dim DC As Long, picTemp As IPictureDisp DC = CreateCompatibleDC(0) If DC < 1 Then Exit Function End If Set picTemp = LoadPicture(FileName) picWidth = ScaleX(picTemp.Width) picHeight = ScaleY(picTemp.Height) SelectObject DC, picTemp DeleteObject picTemp Set picTemp = Nothing GenerateDC = DC End Function Private Sub Form_Load() ScaleMode = 3 picDc = GenerateDC("c:\jamie\barrk.bmp") With Picture1 .AutoRedraw = True .Move 0, 0, ScaleWidth, ScaleHeight .ScaleMode = 3 End With doStretch End Sub Private Function doStretch() Debug.Print StretchBlt(Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, picDc, 0, 0, picWidth, picHeight, vbSrcCopy) Picture1.Refresh End Function Private Sub Form_Resize() Picture1.Move 0, 0, ScaleWidth, ScaleHeight doStretch End Sub
Jamie/Chris
Thanks. I want to point a control at a (JPG or BMP file) on disk and resize it so that it is lets say 400x400 instead of its original size, then save it as a JPG file. Ultimately changing a JPG or BMP file from 1024x768(for example) to 800x600 lets say. Not just resize for the screen but ACTUALLY resize the image.
have you got any code that code do any of this?
:)
Blobby
Search on www.planetsourcecode.com for code for working with JPEGs
plenderleith ?
:eek:
hahahah
also,
blobby
have a look at this thread ;)
http://www.vbforums.com/showthread.php?s=&postid=702615
da_Silvy.....What is your real name? I cant keep calling you that!
Thanks for the info. Im a bit puzzled though.
It doesnt really say what the outcome was as some people had problems doing it the way suggested. All I can find in search engines are ActiveX/DLL's that you have to pay 100 bucks for.
It must be possible in that case so how come there is no code around to do it available for cut and paste?
I still have little information on whether it is actually possible at all.
Blob
I'm also very interested in this topic!
I developed a thumbnail viewer.
There is also a possibility to save the thumbs.
This happens as BMP, which consumes a lot of disk space of course...
I really wonder...is it possible to save as a jpeg?
With an API or whatever?
Christophe
Chris,
Yes, I need to load a pic in either BMP or JPG format and RESIZE it to a specific size and then save it as JPG.
I have searched the web for weeks and found NOTHING but DLL's you have to pay between 30 and 100 bucks for.
There has to be someone who knows how to do this!
If I find anything Ill let you know!
I'll post the code in a few minutes.
Jamie if you can do this, you are a God!
Putting the code together as we speak
Bet you cant do it really! :P
Hm, I found this link:
http://www.planet-source-code.com/xq...s/ShowCode.htm
It is a dll but it's free! I 'll give it a try, it looks good...
Chris,
yes i saw it but it uses a DLL from Intel. I wanted to do it with no 3rd party controls :)
Here ya go.
Read instructions before use.
Cheers jamie, ill check it out!! Prepare for a big girly kiss! :)
Big girly kiss ?
'tis a brave man that gives me a kiss I can tell ya ... ;)
But this uses also a third party OCX or what?
Yes it does.
I never said it didnt :D
Written in Delphi 4 with a memory leak and possibly a virus...
If a believe all the user comments on the site... :(
But I'll give it a try !
Thanks for the help!
My virus scanner never said nothing about no virus.
Anyway most of the people who post on planetsourcecode are absolute morons. I tested the jpg jobby here myself and it worked a dream.
Jamie,
Yeah, Norton 2002 said nothing about a virus.
Im not sure about the memory leak tho!
The only place a decent sized memory leak could be is in the GenerateDC function, and even thats not substantial (well not on mu laptop anyway).
Some people were saying on psc that they'd use it to convert 500 images or so. So I wouldn't worry about it.
But it matters to me!!!
I have to convert up to 10.000 images :D :D :D
It'll be grand.
I can do a test if you'd like
That's very nice of you but I don't want to occupy your computer for a whole day :D
10.000 images...count on +700 MB!:eek:
hang on.
Bombed after about the 700th 33kb bitmap
Hm, Ok, so this is not a solution for me :(
Perhaps I'll try that other dll I found...
Thanks for testing! ;)
I dont think the other link allows yu to resize the image. Only convert to JPG
True, but resizing is not a problem for me, that was already solved in a previous thread :)
A thought.
If you use an Image control set to a small size and use the STRETCH property = True then load a large Image.........Does that shrinke the image internally too or just the display version of it. ie. Is the image still its original size if you resave it or is it only now as big as the shrunk imagebox image?
In other words (if thats confusing) If you had an image box 100x100 on the screen set to Stretch=true and loaded a 1000x1000 image into it.....does it still contain the full image (1000x1000) if you resave the image1.Picture or is it now the reduced 100x100 picture that gets saved?
that'll stretch the imagebox, not the picture
Thats what i thought
Ta.
I use this to resize a picture in a picturebox:
Assume you have loaded a picture in a picturebox called picTmp.
Be sure autoredraw is False!
Now, set the width and height of the picturebox as you like:
picTmp.height = ...
picTmp.Width = ...
Now use the following code:
picTmp.AutoRedraw = True
picTmp.PaintPicture picTmp, 0, 0, picTmp.Width, picTmp.Height
Set picTmp = picTmp.Image
picTmp.AutoRedraw = False
This should do the trick.
Jamie, Ive tried your code bit the quality is.......well......not too good. The quality of the smaller picture looks nothing like the quality of the original. i was expecting it to be like VB when you load a 1024x768 image into a 400x300 picture box. The code gives quality similar to changing the colour depth to 256 colours.
Is there any other way of resizing the image and keeping the quality ?
The only way to improve it is it use SetStretchBltMode() with HALFTONE
Blimey it gets complicated dont it?