|
-
Sep 10th, 2006, 02:42 PM
#1
Thread Starter
Hyperactive Member
[2005] Resizing a bitmap in memory
I know how to open a picture file and load it into memory as a bitmap, I know how to save it as a jpeg, and I even know how to crop them first but there doesn't seem to be a way to resize them to a certain size except for the GetThumbnailImage method but I have no idea what a callback or intptr is. Instead of selectively screenshotting a size changing picture box, I figured I'd ask you guys.
I tried to end process on Visual Studio 2005
but PETA stopped me saying it's smart enough
to be a living creature 
-
Sep 10th, 2006, 03:06 PM
#2
Re: [2005] Resizing a bitmap in memory
The IntPtr is just like a Pointer (Memory Address) to something [AddressOf someMethod or Control.Handle]
The Callback is a method called after each fragment of the file is read (how many times? it depends on the size of the image, and the buffer located by the Framework). So, it's of no use in resizing
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Sep 10th, 2006, 03:21 PM
#3
Thread Starter
Hyperactive Member
Re: [2005] Resizing a bitmap in memory
Okay so for the intptr, they're looking for a place to store the data in memory so I assume there's a way to generate an intptr from a bitmap variable that was declared without the new keyword, right? Also, does it toss that location when it's done? And if callbacks don't have anything to do with resizing and it's a built in thing that windows does to generate thumbnails, why is it asking me to supply one and how would I do so?
I tried to end process on Visual Studio 2005
but PETA stopped me saying it's smart enough
to be a living creature 
-
Sep 10th, 2006, 03:31 PM
#4
Hyperactive Member
Re: [2005] Resizing a bitmap in memory
To resize an image just use the graphics object of the control your drawing on (from within it's paint event) and use the DrawImage method and pass the image and a rectangle of the required size.
-
Sep 10th, 2006, 03:41 PM
#5
Thread Starter
Hyperactive Member
Re: [2005] Resizing a bitmap in memory
hmm well I spose I could stick it in a picturebox if I really have to. I'll try that
I tried to end process on Visual Studio 2005
but PETA stopped me saying it's smart enough
to be a living creature 
-
Sep 10th, 2006, 04:45 PM
#6
Fanatic Member
Re: [2005] Resizing a bitmap in memory
No no no, you simply want to resize the bitmap. Create a new Bitmap object with the desired size. Then call Graphics.CreateFromBitmap(), or CreateFromImage I can't remember, and pass in your new blank bitmap object. Then on the returned Graphics object call DrawImage() to copy your bitmap to the resized bitmap. You can forget about the old Bitmap reference if desired and simply store away the new bitmap object with no ill effects.
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
-
Sep 10th, 2006, 04:53 PM
#7
Thread Starter
Hyperactive Member
Re: [2005] Resizing a bitmap in memory
never mind this whole post, read the next one
Last edited by Desolator144; Sep 10th, 2006 at 05:09 PM.
I tried to end process on Visual Studio 2005
but PETA stopped me saying it's smart enough
to be a living creature 
-
Sep 10th, 2006, 04:57 PM
#8
Fanatic Member
Re: [2005] Resizing a bitmap in memory
You can't create a Graphics object instance by using new. You have to use the static methods in the Graphics class or a Controls CreateGraphics instance method. In this case you want the static methods. I already said I can't remember the exact name but the method does return a Graphics object just as I said above.
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
-
Sep 10th, 2006, 05:10 PM
#9
Thread Starter
Hyperactive Member
Re: [2005] Resizing a bitmap in memory
OOOOOOOOOH Fixed it! Okay, now it actually scales. Here's the real, actual, full, working version:
VB Code:
Private Sub btnChoose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChoose.Click
Dim FolderChooser As New OpenFileDialog
FolderChooser.Title = "Choose all the pictures to be formatted"
FolderChooser.Multiselect = True
FolderChooser.InitialDirectory = "C:\"
FolderChooser.ShowDialog()
Dim strDirectory() As String = FolderChooser.FileNames
Dim intWidth As Integer = CInt(InputBox("How wide would you like each thumbnail to be?", "Width"))
Dim intHeight As Integer = CInt(InputBox("How tall would you like each thumbnail to be?", "Height"))
Dim x As Integer
For x = 0 To strDirectory.GetUpperBound(0)
Dim bit As New Bitmap(strDirectory(x))
pctBox.Image = bit
me.update()
Dim TheGraphics As Graphics
Dim newbit As New Bitmap(intWidth, intHeight)
TheGraphics = Graphics.FromImage(newbit)
TheGraphics.DrawImage(bit, 0, 0, intWidth, intHeight)
Dim strSavePath As String
Dim intIndex As Integer
intIndex = strDirectory(x).Length - 4
strSavePath = strDirectory(x).Insert(intIndex, "Thumb")
newbit.Save(strSavePath, System.Drawing.Imaging.ImageFormat.Jpeg)
Next
End Sub
Last edited by Desolator144; Sep 10th, 2006 at 05:24 PM.
I tried to end process on Visual Studio 2005
but PETA stopped me saying it's smart enough
to be a living creature 
-
Sep 10th, 2006, 05:27 PM
#10
Re: [2005] Resizing a bitmap in memory
Yep.. and its a common question, and theres a codebank submission over it as well...
http://www.vbforums.com/showthread.php?t=383136
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
|