-
Nov 7th, 2022, 04:45 AM
#1
Thread Starter
Member
Reduce dimension of JPEG without losing quality
Hello,
How can I scale down a JPEG without losing quality with vb6?
Example: an image from 1024x768 to 640x480, but I don't want to lose quality.
Photoshop already does this well.
Is there a vb6 algorithm to do this?
Many Thanks
-
Nov 7th, 2022, 05:03 AM
#2
Re: Reduce dimension of JPEG without losing quality
It's impossible to not lose quality when reducing image size; it's just a question of how much quality you lose.
GDIPlus has different interpolation modes that will produce better quality than e.g. just letting the VB picturebox do it. There's lots of sample code for gdip in VB6; use GdipSetInterpolationMode HighQualityBicubic.
-
Nov 7th, 2022, 05:23 AM
#3
Re: Reduce dimension of JPEG without losing quality
So much missing in the requirements above. Is this meant to create a new file compressed in JPEG format, or are you merely scaling for display?
Most of the time you can simply use the PaintPicture method and get perfectly good results.
-
Nov 7th, 2022, 06:06 AM
#4
Thread Starter
Member
Re: Reduce dimension of JPEG without losing quality
I need to resize photos for my website.
I've got a list of vehicle
https://www.labycar.com/veicoli
Actually, I use this resolution: 640x480 but is too small and there is a low quality
I need to resize the photo with vb6.
Which size do you advise?
-
Nov 7th, 2022, 06:51 AM
#5
Thread Starter
Member
Re: Reduce dimension of JPEG without losing quality
I need a lossless scaling
-
Nov 7th, 2022, 07:00 AM
#6
Re: Reduce dimension of JPEG without losing quality
By definition scaling down is a lossy operation, if you have fewer pixels then you can't have as much information visible as when you had more pixels.
-
Nov 7th, 2022, 07:01 AM
#7
Re: Reduce dimension of JPEG without losing quality
Originally Posted by Attilio
I need a lossless scaling
Bet after this you would ask for saving the result in a lossless JPG, wouldn't you? :-))
cheers,
</wqw>
-
Nov 7th, 2022, 07:03 AM
#8
Re: Reduce dimension of JPEG without losing quality
And I need a lossless video compression algorithm to store a blu-ray in a 10kb file. Also some vibranium.
-
Nov 7th, 2022, 07:10 AM
#9
Thread Starter
Member
Re: Reduce dimension of JPEG without losing quality
Sorry for the misunderstanding.
I badly explained myself.
Actually I use GOGO Picture Viewer Pro for scale down.
I know there is a loss of quality but is too much.
I have done the scale down by javascript at the same dimension of 640x480. There is a lose of quality but not so much.
My question is: there is a way to do a scale down but without lose much quality?
-
Nov 7th, 2022, 07:36 AM
#10
Re: Reduce dimension of JPEG without losing quality
Originally Posted by fafalone
And I need a lossless video compression algorithm to store a blu-ray in a 10kb file. Also some vibranium.
10Kb, why do that when you can store an entire mkv file in 10 bytes https://www.vbforums.com/showthread....=1#post5331577
-
Nov 7th, 2022, 08:00 AM
#11
Re: Reduce dimension of JPEG without losing quality
why bother create a tool yourself. u can find tool that can batch-resize for u using good-enough algorithm.
also, most of the time u can go to settings and decide the compression quality (that is important as well)
Attachment 186163
https://i.postimg.cc/3wf14ngB/Image5.jpg
-
Nov 7th, 2022, 08:01 AM
#12
Re: Reduce dimension of JPEG without losing quality
Originally Posted by Attilio
I have done the scale down by javascript at the same dimension of 640x480. There is a lose of quality but not so much.
My question is: there is a way to do a scale down but without lose much quality?
You have to understand that JPG is lossy format. When you are saving a picture in JPG format usually there is a quality setting you can choose from 1 to 99 where 1 means low-quality (but small) and 99 means high-quality (but large file). There is no lossless version of JPG i.e. you have some loss of quality even w/ 99 quality setting.
Now consider this scenario:
1. you open your Picture1.JPG and save it to Picture2.JPG with 80 quality setting which is the most common (average) quality used for web images.
2. then you open Picture2.JPG and save it to Picture3.JPG with 80 quality setting
3. then you repeat the same until you save Picture10.JPG with 80 quality setting
Now it is very possible on Picure10 you will hardly recognize the original Picture1 because the 10 fold re-compression would have introduced significant artifacts in the compressed image.
Coming back to your original question: you have some complaints about the quality of the scaling/resizing with whatever application you are using to do it.
This is hardly the problem in your case because even mspaint.exe can down-scale very well because down-scaling is easy and so every image processing program does it very well.
Where do you think then loss of quality must creep in your final image in JPG format? Could it be the JPG re-compression being detrimental? Could it be you are using default (too low) quality setting on JPG save?
cheers,
</wqw>
-
Nov 7th, 2022, 09:29 AM
#13
Thread Starter
Member
Re: Reduce dimension of JPEG without losing quality
Originally Posted by baka
Attach file doesn't work
-
Nov 7th, 2022, 05:15 PM
#14
Re: Reduce dimension of JPEG without losing quality
Here's an example of using the Windows Imaging Component to resize using higher quality algorithms with the ability to specify the quality setting of the JPG it's saved to.
The Demo uses WICBitmapInterpolationModeFant as it's meant to support Win7, but if you're just supporting Windows 10+, WICBitmapInterpolationModeHighQualityCubic is also an option.
-
Nov 8th, 2022, 03:20 AM
#15
Thread Starter
Member
Re: Reduce dimension of JPEG without losing quality
Many Thanks fafalone,
sorry for previous misandestanding.
I don't speak english very well and many times I'm not able to explain what I want.
Thanks to all inside this special community
-
Nov 9th, 2022, 02:47 AM
#16
Member
Re: Reduce dimension of JPEG without losing quality
Hi, Attilio.
Here's an excellent class to load and save JPGs files on a perfect quality.
Korejwa JPEG Encoder
When you save a JPG using GDI+, the final colors seems to look washed (Poor quality). That's because GDI+ use an standar Sampling frequencies (Chroma Subsampling like 4:2:0). So, you need a none Sampling frequencies when you save your JPG file.
Put this two classes in to your project:
cImage.cls & cJpeg.cls
Then, add this two functions (subs) in to your project:
Code:
Public Sub SaveJPG(ByVal vImageFile As String, ByVal vNewImageFile As String, Optional ByVal vNewWidth As Long, Optional ByVal vNewHeight As Long, Optional ByVal vQuality As Long = 100)
Dim vIMG As cImage
Dim vNewIMG As cImage
Dim vJPG As cJpeg
Set vIMG = New cImage
Set vJPG = New cJpeg
vIMG.CopyStdPicture LoadPicture(vImageFile), 24
If Not ((vNewWidth > 0) And (vNewHeight > 0)) Then ScaledSize vIMG.Width, vIMG.Height, vNewWidth, vNewHeight
Set vNewIMG = vIMG.Resample(vNewWidth, vNewHeight)
vJPG.Quality = vQuality
vJPG.SetSamplingFrequencies 1, 1, 1, 1, 1, 1
vJPG.SampleHDC vNewIMG.hDC, vNewWidth, vNewHeight
vJPG.SaveFile vNewImageFile
Set vNewIMG = Nothing
Set vIMG = Nothing
Set vJPG = Nothing
End Sub
Public Sub ScaledSize(ByVal vOldWidth As Long, ByVal vOldHeight As Long, vNewWidth As Long, vNewHeight As Long)
Dim vRatio As Double: vRatio = vOldWidth / vOldHeight
If vNewWidth > 0 Then
vNewHeight = vNewWidth / vRatio
ElseIf vNewHeight > 0 Then
vNewWidth = vNewHeight * vRatio
End If
End Sub
You can call it in this way:
Code:
SaveJPG "C:\My Folder\My Image.jpg", "C:\My Folder\My NEW Image.jpg", 640, 480
Thats it!
The function autodetects if the resized image needs to preserve the aspect ratio. If you need a image with a fixed Width and Height, then use boths parameters (vNewWidth & vNewHeight). If you need a specific Width but you don't know the final Height (and needs to preserve the aspect ratio), put your desired Width and leave empty the vNewHeight parameter. Something like this:
Code:
SaveJPG "C:\My Folder\My Image.jpg", "C:\My Folder\My NEW Image.jpg", 640
Or...
Code:
SaveJPG "C:\My Folder\My Image.jpg", "C:\My Folder\My NEW Image.jpg", , 480
See ya!
(Tested on Windows XP and Windows 10)
The class cJpeg.cls accepts the following file types:
.jpg, .jpeg, .gif, .bmp, .wmp, .rle, .cur, .ico, .emf
-
Nov 9th, 2022, 03:22 AM
#17
Re: Reduce dimension of JPEG without losing quality
Excuse me if I say nonsense, I am not very expert in web pages, but this type of thing is not usually done with php?, that is, http://www.yourweb.com/Photos.php?Im...4&Size=640x480
and then with Photos.php you create your own image on the fly, this will now create a copy of another size.
-
Nov 9th, 2022, 04:47 AM
#18
Re: Reduce dimension of JPEG without losing quality
Doing it in PHP doesn't really make sense for designing the website itself... php is more something you'd use to automatically handle user uploads.
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
|