When sub runs for the second time, the program freezes - vb.net

I've been doing a skin stealer, but for some reason, when I re-click button 3, it just freezes. Note that I've added the MsgBoxes to know where it freezes (As far as I know, it freezes at AssembleSkin()). I have no idea why it would do that, so if you have an idea why, go ahead and post a suggestion! Thanks
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If TextBox1.Text = "" Then
Else
MsgBox("1")
Dim request = DirectCast(WebRequest.Create _
("http://www.minecraft.net/skin/" + TextBox1.Text + ".png"), WebRequest)
MsgBox("2")
Try
Dim response As WebResponse = DirectCast(request.GetResponse(), WebResponse)
MsgBox("3")
AssembleSkin(FindImage(TextBox1.Text), PictureBox1, PictureBox2, PictureBox5, PictureBox6, PictureBox3, PictureBox4)
MsgBox("4")
Dim Skin As Image = FindImage(TextBox1.Text)
MsgBox("5")
PictureBox7.Image = SizeImage(Skin, 300, 150)
Catch ex As WebException
Dim response As WebResponse = DirectCast(ex.Response, WebResponse)
MsgBox("Skin does not exist", MsgBoxStyle.OkOnly, "Mynecraft V2")
End Try
End If
End Sub
Private Function FindImage(ByVal Username As String) As Image
Dim tClient As WebClient = New WebClient
Dim tImage As Bitmap = Bitmap.FromStream(New MemoryStream(tClient.DownloadData("http://www.minecraft.net/skin/" + Username + ".png")))
Return tImage
End Function
Public Function GetPicturePart(ByVal SourceImage As Bitmap, ByVal Region As Rectangle) As Bitmap
Dim ImagePart As Bitmap = New Bitmap(Region.Width, Region.Height)
Using G As Graphics = Graphics.FromImage(ImagePart)
Dim TargetRect As Rectangle = New Rectangle(0, 0, Region.Width, Region.Height)
Dim SourceRect As Rectangle = Region
G.DrawImage(SourceImage, TargetRect, SourceRect, GraphicsUnit.Pixel)
End Using
Return ImagePart
End Function
Private Function SizeImage(ByVal img As Bitmap, ByVal width As Integer, ByVal height As Integer) As Bitmap
Dim newBit As New Bitmap(width, height)
Dim g As Graphics = Graphics.FromImage(newBit)
g.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor
g.PixelOffsetMode = Drawing2D.PixelOffsetMode.Half
g.DrawImage(img, 0, 0, width, height)
Return newBit
End Function
Private Sub AssembleSkin(ByVal Image As Image, ByVal Head As PictureBox, ByVal Body As PictureBox, ByVal LeftArm As PictureBox, ByVal RightArm As PictureBox, ByVal RightLeg As PictureBox, ByVal LeftLeg As PictureBox)
Head.Image = SizeImage(GetPicturePart(Image, New Rectangle(New Point(8, 8), New Size(8, 8))), 64, 64)
Body.Image = SizeImage(GetPicturePart(Image, New Rectangle(New Point(20, 20), New Size(8, 12))), 64, 96)
LeftArm.Image = SizeImage(GetPicturePart(Image, New Rectangle(New Point(44, 20), New Size(4, 12))), 32, 96)
RightArm.Image = SizeImage(GetPicturePart(Image, New Rectangle(New Point(44, 20), New Size(4, 12))), 32, 96)
LeftLeg.Image = SizeImage(GetPicturePart(Image, New Rectangle(New Point(4, 20), New Size(4, 12))), 32, 96)
RightLeg.Image = SizeImage(GetPicturePart(Image, New Rectangle(New Point(4, 20), New Size(4, 12))), 32, 96)
End Sub

ByVal Image As Image
;o first time i've seen this notation.
also, in your catch statement check the ex.tostring stack trace. (or using system.diagnostics.stacktrace)/
also, what happens when the findimage method returns null, and that is passed to the assembleskin method. that also has a high probability of being the issue.
in any case, check the exception code/trace.

Related

Type Text Directly On A Bitmap Image at Mouse Position

I am trying to write (type) directly onto a bitmap. I need to be able to type at the mouse position, so where ever on the screen i click the mouse, I can start typing text with the keyboard.
Here is a working VS 2017 VB Win Form code that will print "Hello World" at the mousedown position. But it only works with predetermined text. I would like to be able to just type at that spot. I feel I am so close, just can't get it to work.
Imports System.IO
Imports System.Windows.Forms.DataVisualization.Charting
Public Class Form1
Dim WithEvents Chart1 As New Chart
Private Structure TextPoints
Dim MPos As Point
Dim Txt As String
End Structure
Private TextList As New List(Of TextPoints)
Private TempPoint As Point
Private FirstPoint As Point
Dim xcnt As Integer = -1
Dim ycnt As Integer = -1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Me.Size = New Size(1100, 700)
Me.Location = New Point(10, 10)
MakeBackImage()
With Chart1
.Name = "Chart1"
.Location = New System.Drawing.Point(40, 40)
.Size = New System.Drawing.Size(1010, 610)
.BackImage = "BackImg.jpg"
.Parent = Me
End With
End Sub
Private Sub Chart1_MouseDown(ByVal sender As Object,
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Chart1.MouseDown
FirstPoint = New Point(e.X, e.Y)
TempPoint = New Point(e.X, e.Y)
Me.Refresh()
End Sub
Private Sub Chart1_MouseUp(ByVal sender As Object,
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Chart1.MouseUp
Dim T As New TextPoints With {
.MPos = TempPoint,
.Txt = "Hello World"}
TextList.Add(T)
Me.Refresh()
End Sub
Private Sub MakeBackImage()
Dim x, y As Integer
Dim img As Image = New Bitmap(1020, 620)
Dim graphics As Graphics = Graphics.FromImage(img)
graphics.Clear(Drawing.Color.White)
For x = 0 To 1000 Step 20
graphics.DrawLine(Pens.Black, x, 0, x, 600)
xcnt += 1
Next
For y = 0 To 600 Step 20
ycnt += 1
graphics.DrawLine(Pens.Black, 0, y, 1000, y)
Next
img.Save("BackImg.jpg", Imaging.ImageFormat.Jpeg)
End Sub
Private Sub Chart1_Paint(ByVal sender As Object,
ByVal e As System.Windows.Forms.PaintEventArgs) _
Handles Chart1.Paint
Dim drawString As String = "Hello World"
Dim drawFont As New Font("Arial", 14)
Dim drawBrush As New SolidBrush(Color.Black)
For Each t As TextPoints In TextList
e.Graphics.DrawString(t.Txt, drawFont,
drawBrush, t.MPos.X, t.MPos.Y)
Next
End Sub
End Class
This is a simplified code. Actually, the background image is only created once, but I added code to dynamically create it here to make the demo better.

How to show rotating spectrum gradient in PictureBox?

I basically want a rectangle in my form that shows a rainbow gradient and animates it(moving right), preferably as a background so I can show a transparent picture on top.
I tried animating a rainbow gif as the background, but the gif will never be as light as a code generated spectrum.
I also managed to implement a random code of a moving gradient, but this moves the gradient back and forth.
'''
Private Sub picCanvas_Paint(ByVal sender As Object, ByVal e _
As PaintEventArgs) Handles _
WallpaperPreview.Paint
' Draw the background gradient.
Dim br As New LinearGradientBrush(New Point(0, 0), New _
Point(Me.ClientSize.Width, 0), Color.Red,
Color.Blue)
Dim color_blend As New ColorBlend
color_blend.Colors = New Color() {Color.Red,
Color.White, Color.Blue}
color_blend.Positions = New Single() {0, m_Middle, 1}
br.InterpolationColors = color_blend
e.Graphics.FillRectangle(br, Me.ClientRectangle)
br.Dispose()
' Change the gradient's midpoint.
m_Middle += m_Delta
If (m_Middle > 1) OrElse (m_Middle < 0) Then m_Delta =
-m_Delta
End Sub
'''
Is there a way I can convert this to an always right moving rainbow gradient?
Edit:
My solution is this
'''
Private posX As Single = 0
Private posXmover As Single = 10
Private Sub Timer_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer.Tick
WallpaperPreview.Invalidate()
End Sub
Private Sub WallpaperPreview_Paint(ByVal sender As Object, ByVal e _
As PaintEventArgs) Handles _
WallpaperPreview.Paint
Dim rect As New Rectangle(posX, 0,
WallpaperPreview.ClientSize.Width * 2,
WallpaperPreview.ClientSize.Height)
Dim br As New LinearGradientBrush(rect, Color.Red,
Color.Blue, 0)
Dim color_blend As New ColorBlend
color_blend.Colors = New Color() {
Color.Red,
Color.Magenta,
Color.Blue,
Color.Cyan,
Color.Green,
Color.Yellow,
Color.Red,
Color.Magenta,
Color.Blue,
Color.Cyan,
Color.Green,
Color.Yellow,
Color.Red}
color_blend.Positions = New Single() {0, 0.083F, 0.163F, 0.249F, 0.332F, 0.415F, 0.5F, 0.583F, 0.66F, 0.749F, 0.832F, 0.915F, 1}
br.InterpolationColors = color_blend
e.Graphics.Clear(WallpaperPreview.BackColor)
e.Graphics.FillRectangle(br, Me.ClientRectangle)
br.Dispose()
posX += posXmover
End Sub
'''

VB.NET resize and crop images

i have a VSTO for powerpoint and want to resize images so they are the same size as the slide. a sample image i have is 1000x300 and the slide is 960x540. so this is the code i have:
_W=960
_H=540
Dim img As Image = System.Drawing.Bitmap.FromFile(file1)
OldRect = New RectangleF(233, 0, 533, 300) ' calculated values to crop left and right
NewRect = New RectangleF(0, 0, _W, _H)
Dim bmp As Bitmap = New Bitmap(img, _W, _H)
Dim g As Graphics = Graphics.FromImage(bmp)
g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
g.PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality
g.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
g.DrawImage(img, NewRect, OldRect, GraphicsUnit.Pixel)
img.Save(file2, Imaging.ImageFormat.Png)
but when i look at file2 it's the same 1000x300 file as the original. what am i missing here?
#plutonix; you're spot on. i was under the wrong impression that DrawImage would replace the image it was offered. but saving the bitmap the graphics object was created with produced the intended image.
bmp.Save(file2, Imaging.ImageFormat.Png)
works perfect. thanks!
The answer posted here is good but there is one major problem of quality that need to be addressed. In most cased you have to Crop Image and Maintain the Quality so in that regard, I have improved the crop feature of a sample and posted below is the link. This demo is in VB.NET but you can easily understand the concept and make adjustments.
http://www.mediafire.com/file/70rmlpcdjyxo8gc/ImageCroppingDemo_-_Maintain_Image_Quality.zip/file
CODES For Cropping (VB.NET)
Dim cropX As Integer
Dim cropY As Integer
Dim cropWidth As Integer
Dim cropHeight As Integer
Dim oCropX As Integer
Dim oCropY As Integer
Dim cropBitmap As Bitmap
Dim Loadedimage As Image
Public cropPen As Pen
Public cropPenSize As Integer = 1 '2
Public cropDashStyle As Drawing2D.DashStyle = Drawing2D.DashStyle.Solid
Public cropPenColor As Color = Color.Yellow
Private Sub crobPictureBox_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles crobPictureBox.MouseDown
Try
If e.Button = Windows.Forms.MouseButtons.Left Then
cropX = e.X
cropY = e.Y
cropPen = New Pen(cropPenColor, cropPenSize)
cropPen.DashStyle = DashStyle.DashDotDot
Cursor = Cursors.Cross
End If
crobPictureBox.Refresh()
Catch exc As Exception
End Try
End Sub
Dim tmppoint As Point
Private Sub crobPictureBox_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles crobPictureBox.MouseMove
Try
If crobPictureBox.Image Is Nothing Then Exit Sub
If e.Button = Windows.Forms.MouseButtons.Left Then
crobPictureBox.Refresh()
cropWidth = e.X - cropX
cropHeight = e.Y - cropY
crobPictureBox.CreateGraphics.DrawRectangle(cropPen, cropX, cropY, cropWidth, cropHeight)
End If
' GC.Collect()
Catch exc As Exception
If Err.Number = 5 Then Exit Sub
End Try
End Sub
Private Sub crobPictureBox_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles crobPictureBox.MouseUp
Try
Cursor = Cursors.Default
Try
If cropWidth < 1 Then
Exit Sub
End If
Dim smallWidthPercentage As Single = (cropWidth / crobPictureBox.Width) * 100
Dim smallHeightPercentage As Single = (cropHeight / crobPictureBox.Height) * 100
Dim smallXPercentage As Single = (cropX / crobPictureBox.Width) * 100
Dim smallYPercentage As Single = (cropY / crobPictureBox.Height) * 100
smallHeightPercentage += 10
smallYPercentage -= 10
Dim Widthdifference As Integer = Loadedimage.Width - crobPictureBox.Width
Dim HeightDifference As Integer = Loadedimage.Height - crobPictureBox.Height
Dim rect As Rectangle
rect = New Rectangle((smallXPercentage / 100) * Loadedimage.Width, (smallYPercentage / 100) * Loadedimage.Height, (smallWidthPercentage / 100) * Loadedimage.Width, (smallHeightPercentage / 100) * Loadedimage.Height)
Dim bit As Bitmap = New Bitmap(Loadedimage, Loadedimage.Width, Loadedimage.Height)
cropBitmap = New Bitmap(Loadedimage, (smallWidthPercentage / 100) * Loadedimage.Width, (smallHeightPercentage / 100) * Loadedimage.Height)
Dim g As Graphics = Graphics.FromImage(cropBitmap)
g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
g.PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality
g.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
g.DrawImage(bit, 0, 0, rect, GraphicsUnit.Pixel)
PreviewPictureBox.Image = cropBitmap
Catch exc As Exception
End Try
Catch exc As Exception
End Try
End Sub

Flip text in Vb.net

I have a problem in flipping text in VB.NET
It is flipped but with no line brake
See the Link:
http://www.spider-news.net/Flip_Text_question.JPG
Imports System.Drawing.Drawing2D
Imports System.Drawing
Public Class Form1
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
' Draw the text and the surrounding rectangle START.
Dim text1 As String = RichTextBox1.Text
Dim font1 As New Font("Arial", 10, FontStyle.Bold, GraphicsUnit.Point)
Try
Dim rect1 As New Rectangle(10, 10, 1000, 140)
' Create a StringFormat object with the each line of text, and the block
' of text centered on the page.
Dim stringFormat As New StringFormat()
stringFormat.Alignment = StringAlignment.Center
stringFormat.LineAlignment = StringAlignment.Center
' Draw the text and the surrounding rectangle.
e.Graphics.DrawString(text1, font1, Brushes.Blue, rect1, stringFormat)
e.Graphics.DrawRectangle(Pens.Black, rect1)
Finally
font1.Dispose()
End Try
' Draw the text and the surrounding rectangle END.
'' FLIP TEXT ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Draw Flipped Text the text surrounding rectangle START.
Using the_font As New Font("Arial", 20, FontStyle.Bold, GraphicsUnit.Point)
DrawFlippedText(e.Graphics, the_font, Brushes.Black, 10, 10, RichTextBox1.Text, True, False)
Dim txt_size As SizeF
txt_size = e.Graphics.MeasureString(RichTextBox1.Text, the_font)
e.Graphics.DrawRectangle(Pens.Red, 10, 10, txt_size.Width, txt_size.Height)
End Using
' Draw Flipped Text the text surrounding rectangle END.
'' FLIP TEXT ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
End Sub
Public Sub DrawFlippedText(ByVal gr As Graphics, ByVal the_font As Font, ByVal the_brush As Brush, ByVal x As Integer, ByVal y As Integer, ByVal txt As String, ByVal flip_x As Boolean, ByVal flip_y As Boolean)
' Save the current graphics state.
Dim state As GraphicsState = gr.Save()
' Set up the transformation.
Dim scale_x As Integer = IIf(flip_x, -1, 1)
Dim scale_y As Integer = IIf(flip_y, -1, 1)
gr.ResetTransform()
gr.ScaleTransform(scale_x, scale_y)
' Figure out where to draw.
Dim txt_size As SizeF = gr.MeasureString(txt, the_font)
If flip_x Then x = -x - RichTextBox1.Size.Width
If flip_y Then y = -y - RichTextBox1.Size.Height
Dim rect1 As New Rectangle(10, 10, 1000, 140)
Dim stringFormat As New StringFormat()
stringFormat.Alignment = StringAlignment.Center
stringFormat.LineAlignment = StringAlignment.Center
' Draw.
gr.DrawString(txt, the_font, the_brush, x, y)
' Restore the original graphics state.
gr.Restore(state)
End Sub
End Class
Please HELP
My guess is that if the linebreaks are not there you have to split the string into single words.
Then concatenate the words one by one and measure the lenght. if it exceeds your line width draw this string and continue with the next words.
The next draw should be on y-coordinate + your line-height.
I did this in a pdf where i place a text to an absolute position which could be more than 1 line:
Dim splitted As String() = text.Split()
Dim tempchunk As Chunk = New Chunk("", pdfFont)
Dim count As Integer = 0
For Each s As String In splitted
Dim chunk2 As Chunk
chunk2 = New Chunk(tempchunk.Content, pdfFont)
chunk2.Append(" " & s)
If chunk2.GetWidthPoint() > 155 Then
cb.SaveState()
cb.BeginText()
cb.MoveText(x, y - (13 * count))
cb.SetFontAndSize(bfont, 11)
cb.ShowText(tempchunk.Content.Trim())
cb.EndText()
cb.RestoreState()
tempchunk = New Chunk(s, pdfFont)
count += 1
Else
tempchunk.Append(" " & s)
End If
Next
If tempchunk.Content <> "" Then
cb.SaveState()
cb.BeginText()
cb.MoveText(x, y - (13 * count))
cb.SetFontAndSize(bfont, 11)
cb.ShowText(tempchunk.Content.Trim())
cb.EndText()
cb.RestoreState()
End If
Its the code for the pdf but maybe it helps
Try this.
I created a bitmap, draw the string and rectangle there, flipped it, then draw the bitmap (with flipped text) on the Form.
Public Class Form1
Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
Dim b As New Bitmap(300, 100)
Dim g As Graphics = Graphics.FromImage(b)
Dim d As Graphics = Me.CreateGraphics
Dim r As New Rectangle(0, 0, b.Width - 1, b.Height - 1)
Dim f As New StringFormat
f.Alignment = StringAlignment.Center
f.LineAlignment = StringAlignment.Center
g.Clear(BackColor)
g.DrawRectangle(Pens.Red, r)
g.DrawString(RichTextBox1.Text, RichTextBox1.Font, Brushes.Blue, r, f)
b.RotateFlip(RotateFlipType.RotateNoneFlipX)
d.DrawImageUnscaled(b, 10, 10)
g.Dispose()
b.Dispose()
d.Dispose()
End Sub
End Class

How to crop an image in vb.net?

The image can be anything. It can be jpg, png, anything.
Load it.
Crop it. Say removing first 100 pixels from the left.
Save to the same file
Use Graphics.DrawImage Method (Image, RectangleF, RectangleF, GraphicsUnit) method.
Dim fileName = "C:\file.jpg"
Dim CropRect As New Rectangle(100, 0, 100, 100)
Dim OriginalImage = Image.FromFile(fileName)
Dim CropImage = New Bitmap(CropRect.Width, CropRect.Height)
Using grp = Graphics.FromImage(CropImage)
grp.DrawImage(OriginalImage, New Rectangle(0, 0, CropRect.Width, CropRect.Height), CropRect, GraphicsUnit.Pixel)
OriginalImage.Dispose()
CropImage.Save(fileName)
End Using
Ref: Graphics.DrawImage and Image Cropping with Image Resizing Using VB.NET
private void btnCropImage_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.ShowDialog();
//check your filename or set constraint on fileopen dialog
//to open image files
string str = dlg.FileName;
//Load Image File to Image Class Object to make crop operation
Image img = System.Drawing.Bitmap.FromFile(str);
// Create rectangle for source image, what ever it's size.
GraphicsUnit units = GraphicsUnit.Pixel;
RectangleF srcRect = img.GetBounds(ref units);
// Create rectangle for displaying image - leaving 100 pixels from left saving image size.
RectangleF destRect = new RectangleF(100.0F, 0.0F, srcRect.Width - 100, srcRect.Height);
// Bitmap class object to which saves croped image
Bitmap bmp = new Bitmap((int)srcRect.Width - 100, (int)srcRect.Height);
// Draw image to screen.
Graphics grp = Graphics.FromImage(bmp);
grp.DrawImage(img, destRect, srcRect, units);
//save image to disk
bmp.Save("e:\\img.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
//Clear memory for Unused Source Image
img.Dispose();
}
Hope this help you..
Region "Image Cropping"
Dim cropX As Integer
Dim cropY As Integer
Dim cropWidth As Integer
Dim cropHeight As Integer
Dim oCropX As Integer
Dim oCropY As Integer
Dim cropBitmap As Bitmap
Public cropPen As Pen
Public cropPenSize As Integer = 1 '2
Public cropDashStyle As Drawing2D.DashStyle = Drawing2D.DashStyle.Solid
Public cropPenColor As Color = Color.Yellow
Private Sub RotateBtn_Click(sender As System.Object, e As EventArgs) Handles RotateBtn.Click
' RotateImage(PreviewPictureBox.Image, offset:=, angle:=90)
crobPictureBox.Image.RotateFlip(RotateFlipType.Rotate270FlipNone)
'PreviewPictureBox.Image.RotateFlip(RotateFlipType.Rotate270FlipNone)
'(45, PreviewPictureBox.Image)
End Sub
Private Sub crobPictureBox_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles crobPictureBox.MouseDown
Try
If e.Button = Windows.Forms.MouseButtons.Left Then
cropX = e.X
cropY = e.Y
cropPen = New Pen(cropPenColor, cropPenSize)
cropPen.DashStyle = DashStyle.DashDotDot
Cursor = Cursors.Cross
End If
crobPictureBox.Refresh()
Catch exc As Exception
End Try
End Sub
Dim tmppoint As Point
Private Sub crobPictureBox_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles crobPictureBox.MouseMove
Try
If crobPictureBox.Image Is Nothing Then Exit Sub
If e.Button = Windows.Forms.MouseButtons.Left Then
crobPictureBox.Refresh()
cropWidth = e.X - cropX
cropHeight = e.Y - cropY
crobPictureBox.CreateGraphics.DrawRectangle(cropPen, cropX, cropY, cropWidth, cropHeight)
End If
' GC.Collect()
Catch exc As Exception
If Err.Number = 5 Then Exit Sub
End Try
End Sub
Private Sub crobPictureBox_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles crobPictureBox.MouseUp
Try
Cursor = Cursors.Default
Try
If cropWidth < 1 Then
Exit Sub
End If
Dim rect As Rectangle = New Rectangle(cropX, cropY, cropWidth, cropHeight)
Dim bit As Bitmap = New Bitmap(crobPictureBox.Image, crobPictureBox.Width, crobPictureBox.Height)
cropBitmap = New Bitmap(cropWidth, cropHeight)
Dim g As Graphics = Graphics.FromImage(cropBitmap)
g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
g.PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality
g.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
g.DrawImage(bit, 0, 0, rect, GraphicsUnit.Pixel)
' g.DrawImage(bit, 0, 0, rect,GraphicsUnit.Pixel)
PreviewPictureBox.Image = cropBitmap
Catch exc As Exception
End Try
Catch exc As Exception
End Try
End Sub