 |
|
 |
First of all, please, try to put your image alone in the "input folder", then open the Resizer tool and run it.
If it still fails, then the problem is not in a missing disposal of memory resources but in their allocation, so I'll start to suppose the issue is not in the program, but in the fact that your picture is really really huge.
AV
|
|
|
|
 |
|
 |
Hi!
Awesome work, but one thing bothers me, what is this Ffull string youre using? I cant see it being set at any point. So would you explain this:
For Each Ffull In fs
FromFile(Ffull)
Application.DoEvents()
Fshort = Ffull.Substring(Ffull.LastIndexOf("\") + 1)
Particularly those things with Ffull. I just need some info 'cause I'm gonna do a script that also puts them in numbered order.
Thanks in advance
EDIT: Nevermind, already got it. Heres my code:
Dim Ffull, Fshort As String
Dim n As Integer = 0
For Each Ffull In fs
n = n + 1
FromFile(Ffull)
Application.DoEvents()
box1.Text = Ffull
Fshort = Ffull.Substring(Ffull.LastIndexOf("\") + 1)
lblName.Text = Fshort
Application.DoEvents()
Dim dr As DialogResult
If chkBatchProc.Checked Then
dr = DialogResult.Yes
Else
dr = MessageBox.Show("Convert?", Fshort, MessageBoxButtons.YesNoCancel)
End If
If dr = DialogResult.Cancel Then
Exit For
ElseIf dr = DialogResult.Yes Then
Reduce(Double.Parse(txtRedFactor.Text, New System.Globalization.CultureInfo("EN-us")))
Application.DoEvents()
ToFile(txtOUTpath.Text & "\" & n & ".jpg")
End If
Next
modified on Wednesday, July 2, 2008 11:06 AM
|
|
|
|
 |
|
 |
Fine. You eventually were not used to use ForEach loops.
Regards, AV
|
|
|
|
 |
|
 |
I added to the Reduce subroutine the ability to send the desired width and height.
Private Sub Reduce(ByVal width As Integer, ByVal height As Integer)
img = New Bitmap(img, New Size(width, height))
picPhoto.Image = img
Dim SizeKb As String
' To compute: size in Kb
Dim ms As New MemoryStream()
img.Save(ms, Imaging.ImageFormat.Jpeg)
SizeKb = (ms.Length \ 1024).ToString() & "Kb "
lblCurrentSize.Text = "Current Size: " & SizeKb & "(" & img.Width & "x" & img.Height & ") [" & img.Width / img.Height & "]"
End Sub
So that's how I got this thumbnail:
Link to affected JPEG thumbnail
Won't show in IE.
Shows in Windows Explorer and FrontPage editing browser.
Shows in Picture Viewer.
Half of it shows in Firefox.
GIMP was the only app that gave a clue - it says:
"JPEG image message / Premature end of JPEG file / EXIF data will be ignored."
Then GIMP shows it just fine.
When I run a batch, about 90% of the thumbnails are affected this way; 10% work with no problems.
Example:
Link to few more examples
Have any idea why this "Premature end of JPEG file" happens? Or how it can be fixed?
Thanks!
Buffbuh
|
|
|
|
 |
|
 |
Did you try to do some modifications in the actual saving of file as described in the post titled "Size difference on web page"?
AV
|
|
|
|
 |
|
 |
Hi there,
Many thanks for a very useful tool. I've added two lines in your code that made this even more useful for me.
In your frmMain.vb file, below line
Fshort = Ffull.Substring(Ffull.LastIndexOf("\") + 1)
I added the following two lines
Dim Fshort2() As String = Fshort.Split(".")
Fshort = String.Concat(Fshort2(0), "_s.", Fshort2(1))
These two lines add two extra characters (_s) before the picture extension (e.g. jpg, gif ar any other).
Result: if the original picture name is "picture.jpg" the name of the small one is "picture_s.jpg"
That was useful for a project that I work so I thought to share this with you guys.
Thanks again for a useful idea.
PlouVou
|
|
|
|
 |
|
 |
Hi,
this is regarding a vb.net windows application for developing a picasa like image viewer, i have a created a user control with one checkbox, picturebox and a textbox grouped inside a panel. In another form i have placed a flowlayout panel. when the user select a folder from the browse menu, the program will find all the .jpeg images from that folder and to show it as thumbnail, the program will dynamically add the usercontrol to the flowlayout panel. i have done this much, but the problem what i am facing now is, if we scroll down the flowlayoutpanel to the bottom and try to select a usercontrol then automaticaly flowlayoutpanel's scrollbar will go to top. so i cannot select an item by scrolling the panel, i can select the item which is shown at the top 2-3 lines, for selecting rest of the pictures, i need to scroll down. but if i click any of the item other than the top 2-3 levels, then the scrollbar will reset to top.
can i anyone help me to resolve this problem???
Thanks
~Jay
|
|
|
|
 |
|
 |
I used the program to reduce the size of my files, but I used a factor of 1.0 to leave the file the same height and width. The new images show to be the exact same dimension when you right click and look at the properties of the image. When I placed the images on my website, the bottom portion of the image was cut off. Does anyone have any idea why two images that show to be identical except for file size show differently on a asp.net web page. If I look at it in a desktop viewer it looks correct.
Puzzled by results.
|
|
|
|
 |
|
 |
Maybe the issue is in writing down the resized picture: in fact, I noticed that actually an ending byte is cut in the output, and maybe your desktop viewer is smarter than your browser in displaying the final picture.
Try modifying this line of code in ToFile() subroutine:
fs.Write(imgData, 0, UBound(imgData))
with this one:
fs.Write(imgData, 0, ms.Length)
Regards, AV
|
|
|
|
 |
|
 |
Thanks - that solve the problem.
|
|
|
|
 |
|
 |
Very useful, thanks for posting this code, Jim
|
|
|
|
 |
|
 |
Thank you for using it!
AV
|
|
|
|
 |
|
 |
Thank you *so* much. It's really nice to find a simple resizing utility that DOESN'T use filtering.
I needed some sort of basis for a program to resize seamless textures for 3D applications. Because of the simplicity of this one, it resizes the textures without introducing seams into the image - something sorely lacking in every single utility out there.
Thank you *so* much!
|
|
|
|
 |
|
 |
I'm using the modified snippet to resize images to a fixed size, with desired size entered via a text box. So I have this. Private Sub btnResize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnResize.Click If img.Size.Width > txtboxNewWidth.Text Then img = New Bitmap(img, New Size(txtboxNewWidth.Text, img.Size.Height * txtboxNewWidth.Text / img.Size.Width)) End If If img.Size.Height > txtboxNewHeight.Text Then img = New Bitmap(img, New Size(img.Size.Width * txtboxNewHeight.Text / img.Size.Height, txtboxNewHeight.Text)) End If picEditWindow.Image = img End Sub With picEditWindow being the name of the image shown in the picturebox. When I run in debug, and click the button to resize, the program crashes, and spits out this line as the cause If img.Size.Width > txtboxNewWidth.Text Then With the error A first chance exception of type 'System.NullReferenceException' occurred And detailed it says, Object reference not set to an instance of an object What else is required for the resize snippet of code to work?
|
|
|
|
 |
|
 |
Hi.
As far as I can see, what you did is to put the "heart" of the computation done by the Reduce() subroutine inside a stand-alone Sub, that actually handles a Button.Click event.
Doing so, the code snippet you extracted (designed to work inside the iteration on the pictures detected in the input folder) looses the initialization of the img variable.
So, when you try to access to properties like Size, a NullReferenceException is thrown, just because img equals Nothing.
Try to add this line of code at the very beginning of your btnResize_Click routine:
img = picEditWindow.Image
In this way, you put in img a reference to the actual image you want to work with.
Regards, AV
|
|
|
|
 |
|
 |
Thank you Alberto that worked great! I see now that putting that code snippet into a click routine isn't a good idea. It should be in main so it can use and be used by other functions. Right? Is it even possible to place the function in main, and then access it through a click event? I've been reading through your code and most of it is over my head. (I'm a beginner) I'm also using VB2005 which is a bit different.
|
|
|
|
 |
|
 |
The way a function can be called by other parts of code is a matter of "accessibility" and "scope" of the function. Also, the issue you had on your first trial was also a scope-related issue, applied to variables.
I strongly recommend to you (as a "beginner", as you stated) to read something like this:
http://media.techtarget.com/digitalguide/images/Misc/petrusha_ch02.pdf[^]
Regards, AV
|
|
|
|
 |
|
 |
You saved me a lot of work.
I had been thinking of doing something like this, but I am glad I checked on Codeproject first!
well done.
With Regards
Shailen Sukul
BSc Mcsd.Net Mcsd Mcad
.Net Architect/Developer
Ashlen Consulting Services P/L
|
|
|
|
 |
|
 |
After I convert some images by using Batch Image Resizer.
The buttom of every image is cut out as black space.
I try by adjusting factor. But it is not disappered.
And I open converted picture with ACDSee 7.0 application.
It show picture and at status bar "Source DataStream is corrupt" message is appear.
Lucky
|
|
|
|
 |
|
 |
Hi. I never had this problem. Did it appear on "all" of your images, or only on some of them? Getting some of those images wrongly resized could be useful to investigate on this issue. If you want, send them to my email address.
I'll test and if a reason is there, I'll try to fix the problem and post again a reply on this forum.
AV
|
|
|
|
 |
|
 |
I wanted to do a little software like this but someone made it after me.
My idea was to make a software that emulate behavior of MS Paint
File --> Open --> Save
because this "routine" reduce largerness of file jpg
I wanna say that this program made this "my discovery" better than MS PAINT because if we set factor to 1 it reduces better the pictures.
Claudio
http://spaces.msn.com/tebbyblog
|
|
|
|
 |
|
 |
If you resample the image when you resize it, you get a far better quality image. (I think this is similar to antialiasing with fonts).
(What is *looks* like when you resample something is that you get a "softer" less "jagged" looking image. This is most noticeable if you resize by a large factor (.1 or 10x, etc.)
I am looking for a way to resize with resampling.
Clay
|
|
|
|
 |
|
|
 |
|
 |
Would it be possible to change your code so that it will resize pdf files?
Thanks!
Triskal
|
|
|
|
 |
|
 |
Well...
This utility is designed to resize images and makes use of the native .NET framework API to manage graphics. PDF files are not image files, but document files, and:
1) for sure the task of resizing a document is deeply different from the task of resizing images;
2) .NET Framework doesn't seem to contain native API to manage PDF files; lots of third parts products and sofware components exist to manipulate PDF files, so this is not an impassable obstacle.
But, first of all, it would be nice to define better what you mean by "resizing PDF files": do you mean "reduce each file size"? or "cut a PDF file in smaller documents, composed by a lower number of pages"? or something else?
|
|
|
|
 |