I got one too hard for me to fix problem. I know the cause and i know why
but i cant fix it.
I am using a "Rubber band" like function, drawing a rectangle on an image
in a picturebox that i loaded. Now i want to Cut out the part i marked with
the "Rubber band" and load that image in the picturebox. This works great
and i can save that image as i want to. The problem is that the image loaded
is smaller cause when i load the image i use drawimage from the original image
and redraw it to fit the picturebox. And when i now cut out everything except
the "Rubber band" part it gets smaller cause i use the picturebox verision of
the image and not the original image.Any ideas on how this can be done easily
so i cut from the original image and not the picturebox image wich is smaller.
and if i cut from the original image the rectangle will be too small aswell.
hard to explain, hope you will understand.
iam using Microsoft visual basic.net 2003
but i cant fix it.
I am using a "Rubber band" like function, drawing a rectangle on an image
in a picturebox that i loaded. Now i want to Cut out the part i marked with
the "Rubber band" and load that image in the picturebox. This works great
and i can save that image as i want to. The problem is that the image loaded
is smaller cause when i load the image i use drawimage from the original image
and redraw it to fit the picturebox. And when i now cut out everything except
the "Rubber band" part it gets smaller cause i use the picturebox verision of
the image and not the original image.Any ideas on how this can be done easily
so i cut from the original image and not the picturebox image wich is smaller.
and if i cut from the original image the rectangle will be too small aswell.
hard to explain, hope you will understand.
iam using Microsoft visual basic.net 2003
Code:
'Part of the load image code
tempx = PictureBox1.Width
tempy = PictureBox1.Height
Dim tempbmp As New Bitmap(tempx, tempy)
Dim g As Graphics = graphics.FromImage(tempbmp)
g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(tempbitmap, New Rectangle(0, 0, tempx, tempy), New Rectangle(0, 0, tempbitmap.Width, tempbitmap.Height), GraphicsUnit.Pixel)
g.Dispose()
PictureBox1.Image = tempbmp
imageloaded = True
loadedbitmap = tempbmp
'Button to cut out the Marked image
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If marked = True Then
marked = False
Dim tempbmp As New Bitmap(DrawREC.Width, DrawREC.Height)
Dim g As Graphics = graphics.FromImage(tempbmp)
g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(loadedbitmap, New Rectangle(0, 0, DrawREC.Width, DrawREC.Height), New Rectangle(DrawREC.X, DrawREC.Y, DrawREC.Width, DrawREC.Height), GraphicsUnit.Pixel)
g.Dispose()
loadedbitmap = tempbmp
PictureBox1.Image = tempbmp
imageloaded = True
End If
End Sub
'Save the new image sub
Private Sub SaveNewImage()
Dim filename As String = GetFileNameWithoutExtension(path)
Dim newbm As New Bitmap(loadedbitmap)
newbm.Save(filename, ImageFormat.Jpeg)
End Sub