|
-
Dec 13th, 2001, 03:28 AM
#1
Thread Starter
Frenzied Member
Resizing/changing pic type
Does anyone know how to resize a pic and Save it as JPG (if it was a BMP)
Many thanks
There are 3 types of people in this world.........those that can count, and those that can't.
Blobby
-
Dec 13th, 2001, 04:36 AM
#2
Addicted Member
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.
-
Dec 13th, 2001, 05:53 AM
#3
Retired VBF Adm1nistrator
To resize you just use StretchBlt.
I've posted numerous examples on the forums. Here's one too ;
VB Code:
' By Jamie Plenderleith
'
' 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
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Dec 15th, 2001, 05:30 AM
#4
Thread Starter
Frenzied Member
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
There are 3 types of people in this world.........those that can count, and those that can't.
Blobby
-
Dec 15th, 2001, 05:48 AM
#5
Retired VBF Adm1nistrator
Search on www.planetsourcecode.com for code for working with JPEGs
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Dec 15th, 2001, 06:40 AM
#6
Conquistador
plenderleith ?

hahahah
-
Dec 16th, 2001, 04:23 PM
#7
Conquistador
-
Dec 17th, 2001, 03:13 AM
#8
Thread Starter
Frenzied Member
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
There are 3 types of people in this world.........those that can count, and those that can't.
Blobby
-
Dec 17th, 2001, 03:31 AM
#9
Addicted Member
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
I do not have a specific statement...
so I will use one of my wife
Veni, Vidi, Visa ... I came, I saw, I shopped

-
Dec 17th, 2001, 03:43 AM
#10
Thread Starter
Frenzied Member
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!
There are 3 types of people in this world.........those that can count, and those that can't.
Blobby
-
Dec 17th, 2001, 03:52 AM
#11
Retired VBF Adm1nistrator
I'll post the code in a few minutes.
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Dec 17th, 2001, 03:58 AM
#12
Thread Starter
Frenzied Member
Jamie if you can do this, you are a God!
There are 3 types of people in this world.........those that can count, and those that can't.
Blobby
-
Dec 17th, 2001, 04:14 AM
#13
Retired VBF Adm1nistrator
Putting the code together as we speak
-
Dec 17th, 2001, 04:19 AM
#14
Thread Starter
Frenzied Member
Bet you cant do it really! :P
There are 3 types of people in this world.........those that can count, and those that can't.
Blobby
-
Dec 17th, 2001, 04:52 AM
#15
Addicted Member
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...
I do not have a specific statement...
so I will use one of my wife
Veni, Vidi, Visa ... I came, I saw, I shopped

-
Dec 17th, 2001, 04:55 AM
#16
Thread Starter
Frenzied Member
Chris,
yes i saw it but it uses a DLL from Intel. I wanted to do it with no 3rd party controls
There are 3 types of people in this world.........those that can count, and those that can't.
Blobby
-
Dec 17th, 2001, 04:58 AM
#17
Retired VBF Adm1nistrator
Here ya go.
Read instructions before use.
-
Dec 17th, 2001, 05:00 AM
#18
Thread Starter
Frenzied Member
Cheers jamie, ill check it out!! Prepare for a big girly kiss!
There are 3 types of people in this world.........those that can count, and those that can't.
Blobby
-
Dec 17th, 2001, 05:02 AM
#19
Retired VBF Adm1nistrator
Big girly kiss ?
'tis a brave man that gives me a kiss I can tell ya ...
-
Dec 17th, 2001, 05:03 AM
#20
Addicted Member
But this uses also a third party OCX or what?
I do not have a specific statement...
so I will use one of my wife
Veni, Vidi, Visa ... I came, I saw, I shopped

-
Dec 17th, 2001, 05:04 AM
#21
Retired VBF Adm1nistrator
Yes it does.
I never said it didnt
-
Dec 17th, 2001, 05:08 AM
#22
Addicted Member
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!
I do not have a specific statement...
so I will use one of my wife
Veni, Vidi, Visa ... I came, I saw, I shopped

-
Dec 17th, 2001, 05:15 AM
#23
Retired VBF Adm1nistrator
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.
-
Dec 17th, 2001, 05:45 AM
#24
Thread Starter
Frenzied Member
Jamie,
Yeah, Norton 2002 said nothing about a virus.
Im not sure about the memory leak tho!
There are 3 types of people in this world.........those that can count, and those that can't.
Blobby
-
Dec 17th, 2001, 05:48 AM
#25
Retired VBF Adm1nistrator
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.
-
Dec 17th, 2001, 05:50 AM
#26
Addicted Member
-
Dec 17th, 2001, 05:54 AM
#27
Retired VBF Adm1nistrator
It'll be grand.
I can do a test if you'd like
-
Dec 17th, 2001, 06:07 AM
#28
-
Dec 17th, 2001, 06:09 AM
#29
Retired VBF Adm1nistrator
-
Dec 17th, 2001, 06:22 AM
#30
Retired VBF Adm1nistrator
Bombed after about the 700th 33kb bitmap
-
Dec 17th, 2001, 06:47 AM
#31
-
Dec 17th, 2001, 07:01 AM
#32
Thread Starter
Frenzied Member
I dont think the other link allows yu to resize the image. Only convert to JPG
There are 3 types of people in this world.........those that can count, and those that can't.
Blobby
-
Dec 17th, 2001, 07:11 AM
#33
Addicted Member
True, but resizing is not a problem for me, that was already solved in a previous thread
I do not have a specific statement...
so I will use one of my wife
Veni, Vidi, Visa ... I came, I saw, I shopped

-
Dec 17th, 2001, 08:54 AM
#34
Thread Starter
Frenzied Member
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?
Last edited by Blobby; Dec 17th, 2001 at 08:59 AM.
There are 3 types of people in this world.........those that can count, and those that can't.
Blobby
-
Dec 17th, 2001, 08:56 AM
#35
Retired VBF Adm1nistrator
that'll stretch the imagebox, not the picture
-
Dec 17th, 2001, 09:01 AM
#36
Thread Starter
Frenzied Member
There are 3 types of people in this world.........those that can count, and those that can't.
Blobby
-
Dec 17th, 2001, 09:09 AM
#37
Addicted Member
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.
I do not have a specific statement...
so I will use one of my wife
Veni, Vidi, Visa ... I came, I saw, I shopped

-
Dec 19th, 2001, 03:52 AM
#38
Thread Starter
Frenzied Member
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 ?
There are 3 types of people in this world.........those that can count, and those that can't.
Blobby
-
Dec 19th, 2001, 04:30 AM
#39
Retired VBF Adm1nistrator
The only way to improve it is it use SetStretchBltMode() with HALFTONE
-
Dec 19th, 2001, 04:31 AM
#40
Thread Starter
Frenzied Member
Blimey it gets complicated dont it?
There are 3 types of people in this world.........those that can count, and those that can't.
Blobby
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|