MouseWheel事件,鼠标向后滚图像消失
我使用Form的MouseWheel()事件缩放Image1中的图像,鼠标前滚缩小,后滚放大。但是前滚没问题,后滚一下图像就消失了,这是什么bug?
else { Graphics::TBitmap *bitmap1 = new Graphics::TBitmap(); Graphics::TBitmap *bitmap2 = new Graphics::TBitmap(); bitmap1 -> Assign(Image1 -> Picture -> Bitmap); Image1 -> ShowHint = true; Image1 -> Hint = "鼠标滚轮向前滚动缩小Image1中图像, 鼠标滚轮向后滚动放大Image1中图像"; Image1 -> Proportional = true; //锁定缩放图像时的纵横比 if(WheelDelta > 0) //滚轮上滚图像缩小 { bitmap2 -> Width = (int)(0.99 * bitmap1 -> Width); bitmap2 -> Height = (int)(0.99 * bitmap1 -> Height); SetStretchBltMode(bitmap2 -> Canvas -> Handle, HALFTONE); StretchBlt(bitmap2 -> Canvas -> Handle, 0, 0, bitmap2 -> Width, bitmap2 -> Height, bitmap1 -> Canvas -> Handle, 0, 0, bitmap1 -> Width, bitmap1 -> Height, SRCCOPY); } else //放大 { bitmap2 -> Width = 1.01 * bitmap1 -> Width; bitmap2 -> Width = 1.01 * bitmap1 -> Height; SetStretchBltMode(bitmap2 -> Canvas -> Handle, HALFTONE); StretchBlt(bitmap2 -> Canvas -> Handle, 0, 0, bitmap2 -> Width, bitmap2 -> Height, bitmap1 -> Canvas -> Handle, 0, 0, bitmap1 -> Width, bitmap1 -> Height, SRCCOPY); } Image1 -> Picture -> Bitmap = bitmap2; Image1 -> Refresh(); w = Image1 -> Width; h = Image1 -> Height; StatusBar1 -> Panels -> Items[2] -> Text = "图像尺寸:" + h + "x" + w + " pixel"; //状态栏更改缩放后的尺寸 delete bitmap1; delete bitmap2; }