为什么我用picturebox显示裁剪出来的图片时,系统说内存不足呢?
vb.net吧
全部回复
仅看楼主
level 6
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim img As New Bitmap("E:\kenan.jpg")
Dim a As String = img.Width / 3
Dim b As String = img.Height / 3
PictureBox1.Image = System.Drawing.Image.FromFile("E:\kenan.jpg")
PictureBox1.SizeMode = PictureBoxSizeMode.Zoom
PictureBox2.SizeMode = PictureBoxSizeMode.Zoom
PictureBox3.SizeMode = PictureBoxSizeMode.Zoom
PictureBox4.SizeMode = PictureBoxSizeMode.Zoom
Dim rc1 As Rectangle = New Rectangle(0, 0, a, b)
Dim newImg1 As Image = img.Clone(rc1, Imaging.PixelFormat.Format32
bp
pArgb)
PictureBox2.Image = newImg1
Dim rc2 As Rectangle = New Rectangle(a, 0, (2 * a), b)
Dim newImg2 As Image = img.Clone(rc2, Imaging.PixelFormat.Format32bppArgb)
PictureBox3.Image = newImg2
Dim rc3 As Rectangle = New Rectangle((2 * a), 0, (3 * a), b)
Dim newImg3 As Image = img.Clone(rc3, Imaging.PixelFormat.Format32bppArgb)
PictureBox4.Image = newImg3
End Sub
2015年08月28日 08点08分 1
level 6
请教大神,是不是哪里出现了问题,谢谢。
2015年08月28日 08点08分 2
level 6
错误出在倒数第3行
2015年08月28日 08点08分 3
level 6
[疑问][疑问][疑问]
2015年08月28日 08点08分 4
level 12
你的rect的范围已经超出了bitmap的范围了,也就是说rect有一部分在bitmao里面是不存在的
2015年08月28日 08点08分 5
还有有必要夸吧问问题吗
2015年08月28日 08点08分
回复
�漣�����˹���
:那我要怎么改呢?
2015年08月28日 08点08分
回复 杰克冻人之怒 :那要怎么改呢?
2015年08月28日 09点08分
回复
�漣�����˹���
:你想要达到什么效果
2015年08月28日 09点08分
level 6
有大神在吗?
2015年08月28日 08点08分 6
level 12
Function ClipImg(input As Bitmap) As Bitmap(,)
Dim w As Integer = input.Width / 3, h As Integer = input.Height / 3
Dim ret(2, 2) As Bitmap
For i As Integer = 0 To 2
For j As Integer = 0 To 2
ret(i, j) = input.Clone(New Rectangle(w * i, h * j, w,h), Imaging.PixelFormat.DontCare)
Next
Next
Return ret
End Function
传入一个bitmap,输出一个二维数组。
2015年08月28日 09点08分 8
请问输出的二维数组就是9个图像吗?
2015年08月28日 09点08分
回复
�漣�����˹���
:对
2015年08月28日 11点08分
level 6
2015年08月28日 15点08分 9
你是不是用一个image储存了那个function的返回值?应该用二维数组。。
2015年08月28日 16点08分
回复
�ܿ˶���֮ŭ
:。把你的调用代码些上来
2015年08月28日 18点08分
回复
�ܿ˶���֮ŭ
: Dim img As New Bitmap("E:\kenan.jpg") PictureBox1.Image = img Dim a(2, 2) As Bitmap a(2, 2) = ClipImg(img) 是不是这样?
2015年08月29日 09点08分
level 12
还有你确定你那个bmp不是特别小的那种。。
2015年08月28日 16点08分 10
能不能麻烦您说详细一点
2015年08月29日 09点08分
level 13
内存泄漏,很明显。点击多次后内存就满了。img没释放。
2015年08月29日 04点08分 11
如何释放上面已经没用的绘制的Rectangle[呵呵]
2015年08月29日 09点08分
level 12
Dim img As New Bitmap("E:\kenan.jpg")
PictureBox1.Image = img
Dim a(,) As Bitmap
a = ClipImg(img)
2015年08月29日 09点08分 12
我完全按照您说的写,是不是像楼下写的那样
2015年08月29日 09点08分
level 6
Public Class Form1
Function ClipImg(input As Bitmap) As Bitmap(,)
Dim w As Integer = input.Width / 3, h As Integer = input.Height / 3
Dim ret(2, 2) As Bitmap
For i As Integer = 0 To 2
For j As Integer = 0 To 2
ret(i, j) = input.Clone(New Rectangle(w * i, h * j, w, h), Imaging.PixelFormat.DontCare)
Next
Next
Return ret
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim img As New Bitmap("E:\kenan.jpg")
PictureBox1.Image = img
Dim a(,) As Bitmap
a = ClipImg(img)
PictureBox1.SizeMode = PictureBoxSizeMode.Zoom
PictureBox2.SizeMode = PictureBoxSizeMode.Zoom
PictureBox2.Image = a(0, 0)
2015年08月29日 09点08分 13
level 6
2015年08月29日 09点08分 14
这个异常应该是第4行导致的。前面你的Dim Img....后面添加 img.Dispose应该就好了。
2015年09月12日 13点09分
level 12
那就是用完图片你没有释放内存。。记得用完了写dispose。。
2015年08月29日 12点08分 15
实在抱歉,不知道为什么我写了picturebox1.dispose()后,系统还是说“内存不足”,您知道为什么吗?
2015年08月29日 15点08分
回复
�漣�����˹���
:是释放图片不是释放图片框。。。
2015年08月29日 20点08分
回复
�ܿ˶���֮ŭ
:是不是直接在用完后就dispose()
2015年08月30日 03点08分
回复
�漣�����˹���
:不是。。img.dispose 你是电脑内存不足或者分配了太多动态内存。。
2015年08月30日 08点08分
level 13
Using img As New Bitmap .........
......
End Using
这样写不会漏掉Dispose,因为End Using是IDE自动添加的。
2015年08月29日 12点08分 16
小吧主,我用了以后系统还是提示“内存不足”,是我程序有问题,还是电脑或软件有问题?
2015年08月29日 15点08分
回复 奇迹我来了哈哈 :建议用小图片和大内存电脑进一步确定问题
2015年08月30日 01点08分
回复 Nukepayload2 :好的
2015年08月30日 17点08分
level 6
2015年08月29日 15点08分 17
应该是a.Dispose
2015年08月31日 00点08分
回复
�ܿ˶���֮ŭ
:成功了,谢谢您。[呵呵]能不能再问您一个问题:您知不知道如何把button长方形的形状变成一节竹子的形状,就是改变button的形状。
2015年08月31日 13点08分
回复 奇迹我来了哈哈 :可以用picturebox模拟
2015年08月31日 22点08分
回复
������111
:正解。还可以弄用户控件或者直接gdi+
2015年08月31日 23点08分
level 12
换种方法试试,用graphics+drawimage裁剪,记得用using。
2015年08月30日 01点08分 18
OK
2015年08月31日 13点08分
level 3
楼主也是牛人啊![大拇指]
2015年09月01日 14点09分 19
level 6
程序如何写如何才能像QQ那样截图
2015年09月03日 16点09分 20
1