|
|
Comments and Discussions
|
|
 |
|

|
as in the form load cause i am not able to remove the image after loading it.
thanks in advance
|
|
|
|
|

|
Thanks for the 5
|
|
|
|

|
Love this VB stuff. Have no understanding of c# so those projects are guaranteed to be a mysteriously useful when they do compile for me. VB, because of BASIC, naturally. Wouldn't forget it by choice but c# is forcing the issue.
|
|
|
|
|

|
My picture has a lot of horizontal and vertical lines (every x pixels). Now I have the problem that not all lines are visible.
If I zoom into the picture, all lines are slowly becoming visible.
Is that the problem of "StretchBlt"?
Has anyone a solution for this problem?
|
|
|
|

|
how can i display the selected portion of image in center of the rectangle while zooming...
|
|
|
|

|
I'm discovering that subsequent image loads seem to increase memory consumption until an exception is thrown. Something isn't being disposed of fully.
For instance, with the WindowsApplication9.exe in the /bin folder... If I keep loading images (jpgs from a digital camera at 10MP @ 3872 x 2592 pixels) into the app using the "Open Image" button, the memory runs away.
Any ideas? Otherwise, I really like the code. I'd love to be able to use it! Thanks.
|
|
|
|

|
thank you,
originally the program had a memory leak, but I fixed it,
try compiling the program instead of running the already compiled .exe
I wish I had more time to help but I'm very busy these days
tell me if it's urgent and I'll make time to recheck the code.
bye
|
|
|
|

|
Yes, there is a memory leak...
The following should correct it.
Public Function srcDispose() As Object
If Not IsNothing(srcBitmap) Then
DeleteObject(HBitmapSrc)
srcBitmap = Nothing
HBitmapSrc = Nothing
End If
|
|
|
|

|
How can I get the width and height of the drawn picture? (after zoom in/out)
|
|
|
|

|
If I understood you correctly, then there is nothing called the width,height of a photo after zoom in or zoom out, because a photo have a certain width/height originally, but after the zoom in or out the dimensions of the photo depends on the container the photo resides in.
So what you really want to know is the dimenstions of the container not the photo.
|
|
|
|

|
Assalamu'alaikum,
I'm Rezal, from Indonesia, Would u kind help me to break out my problems?
Suppose that i want to draw running signal, just like if we press ctrl+alt+del in windows then we'll see performance graph. And it should be there too the axis and ordinat label that able to automatically changing based on the data. for data, i have previously floating point number data in text (89.348,94.883,...).
I use vb.net 3.5 for programming.
Please. Thank u for ur help.
|
|
|
|

|
Your work is Excellent.
Can you please share to me following
How to draw next image at end of the first image while scrolling.
I mean when we reached end of the first image, i need to draw next image or same image again with out any time delay.That is it must view as Continues action.
Please help me
Titto Sebastian
modified on Thursday, February 21, 2008 4:41 AM
|
|
|
|

|
Hi titto,
Thank you for your comment and,
It is possible to draw another image at the end of the first image.
BUT there are important factors:
1-Are the next image (or images) already loaded into memory ?
2-How big the next images (or images) are ?
If the all images are loaded into memory there will be no time delay at all,
but they will take alot of memory according to how big these images are.
for further discussion plz reply.
|
|
|
|

|
Thanks for your great replay.
My aim is to stitch images.For example we taken different pictures in a mounten,
We need to stitch the images as into one panoramic image.
with regards
Titto Sebastian.
|
|
|
|

|
Thanks for you excellent article.
Worked first time in VB.net 2005
|
|
|
|

|
I am trying to experiment with modifying your code to zoom images with the mousewheel.
I have set the mousewheel event on the main form.
I passed the main form control to the NetPicView class
The following even was added.
AddHandler focusControl.MouseWheel, AddressOf form_MouseWheel
focuscontrol is the form control.
Here is the event code:
Private Sub Form_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If IsNothing(srcBitmap) Then Exit Sub
Host.Cursor = Cursors.Arrow
If e.Delta >= 0 Then
If Zfactor > MaxZ Then Exit Sub
oldZfactor = Zfactor
Zfactor = Zfactor * 1.3
DrawPic(e.X, e.Y)
ElseIf e.Delta < 0 Then
If Zfactor < MinZ Then Exit Sub
oldZfactor = Zfactor
Zfactor = Zfactor / 1.3
DrawPic(e.X, e.Y)
End If
RaiseEvent ZoomChanged(Zfactor)
End Sub
The experiment worked...almost.
When I zoom with the mouse wheel it does not always stay on the same pixel on the image. It seems to have an offset in the
x axis only. This does not happen if you zoom with the mouse click. I wonder if there is a way to fix this.
Thanks for the work. It is awesome.
|
|
|
|

|
Thankyou for a brilliant control
|
|
|
|

|
I've been looking for an example on doing this for a while, very helpful. Thank you.
|
|
|
|

|
Hi! Thank you for your source. Helped me a lot. But there is one picularity in all this. If the image is changed (for example, rotated or changed in any other way) the viewer works improperly. I rewrote your class using only managed code (it solves the problem and does not hurt performance):
internal sealed class Viewer : IDisposable
{
public float CurrentZoom
{
get
{
return _zoomFactor;
}
set
{
_zoomFactor = value;
this.DrawImage(_host.Width / 2, _host.Height / 2);
}
}
public Image Image
{
get
{
return _image;
}
set
{
if (_image != value)
{
_image = value;
_host.Invalidate();
}
}
}
public float MaxZoom
{
get
{
return _maxZ;
}
set
{
_maxZ = value;
}
}
public float MinZoom
{
get
{
return _minZ;
}
set
{
_minZ = value;
}
}
private void DrawImage(float zoomX, float zoomY)
{
if (_image == null)
{
return;
}
_xOut = false;
_yOut = false;
if (_host.Width > _image.Width * _zoomFactor)
{
_mrec.X = 0;
_mrec.Width = _image.Width;
_brec.X = (_host.Width - _image.Width * _zoomFactor) / 2;
_brec.Width = _image.Width * _zoomFactor;
}
else
{
_mrec.X = _mrec.X + ((_host.Width / _oldZFactor - _host.Width / _zoomFactor) / ((_host.Width + 0.001f) / zoomX));
_mrec.Width = _host.Width / _zoomFactor;
_brec.X = 0;
_brec.Width = _host.Width;
}
if (_host.Height > _image.Height * _zoomFactor)
{
_mrec.Y = 0;
_mrec.Height = _image.Height;
_brec.Y = (_host.Height - _image.Height * _zoomFactor) / 2;
_brec.Height = _image.Height * _zoomFactor;
}
else
{
_mrec.Y = _mrec.Y + ((_host.Height / _oldZFactor - _host.Height / _zoomFactor) / ((_host.Height + 0.001f) / zoomY));
_mrec.Height = _host.Height / _zoomFactor;
_brec.Y = 0;
_brec.Height = _host.Height;
}
_oldZFactor = _zoomFactor;
if (_mrec.Right > _image.Width)
{
_xOut = true;
_mrec.X = _image.Width - _mrec.Width;
}
if (_mrec.X < 0)
{
_xOut = true;
_mrec.X = 0;
}
if (_mrec.Bottom > _image.Height)
{
_yOut = true;
_mrec.Y = _image.Height - _mrec.Height;
}
if (_mrec.Y < 0)
{
_yOut = true;
_mrec.Y = 0;
}
using (Graphics g = _host.CreateGraphics())
{
int brecX = (int)_brec.X;
int brecY = (int)_brec.Y;
int brecWidth = (int)_brec.Width;
int brecHeight = (int)_brec.Height;
int mrecX = (int)_mrec.X;
int mrecY = (int)_mrec.Y;
int mrecWidth = (int)_mrec.Width;
int mrecHeight = (int)_mrec.Height;
g.DrawImage(
_image
, new Rectangle(brecX, brecY, brecWidth, brecHeight)
, new Rectangle(mrecX, mrecY, mrecWidth, mrecHeight)
, GraphicsUnit.Pixel
);
int leftRectWidth = brecX - _host.Left;
int topRectHeight = brecY - _host.Top;
int topRectWidth = _host.Width - leftRectWidth;
int rightRectLeft = _host.Left + leftRectWidth + brecWidth;
g.FillRectangle(Brushes.Black, new Rectangle(0, 0, leftRectWidth, _host.Height));
g.FillRectangle(Brushes.Black, new Rectangle(leftRectWidth, 0, topRectWidth, topRectHeight));
g.FillRectangle(Brushes.Black, Rectangle.FromLTRB(rightRectLeft, topRectHeight, _host.Right, _host.Bottom));
g.FillRectangle(Brushes.Black, Rectangle.FromLTRB(leftRectWidth, _host.Top + topRectHeight + brecHeight, rightRectLeft, _host.Bottom));
}
}
private void _host_MouseDown(object sender, MouseEventArgs e)
{
if (_image != null)
{
_p.X = e.X;
_p.Y = e.Y;
_cp.X = 0;
_cp.Y = 0;
_cs.X = e.X;
_cs.Y = e.Y;
_downPress = true;
}
}
private void _host_MouseMove(object sender, MouseEventArgs e)
{
if (_image != null)
{
if (_downPress)
{
_host.Cursor = Cursors.NoMove2D;
// Accelerated scrolling when right click drag.
if (e.Button == MouseButtons.Right)
{
_cp.X = (_p.X - e.X) * (_image.Width / 2000);
_cp.Y = (_p.Y - e.Y) * (_image.Height / 2000);
}
_mrec.X = ((_p.X - e.X) / _zoomFactor) + _mrec.X + _cp.X;
_mrec.Y = ((_p.Y - e.Y) / _zoomFactor) + _mrec.Y + _cp.Y;
this.DrawImage(0, 0);
if (!_xOut)
{
_p.X = e.X;
}
if (!_yOut)
{
_p.X = e.Y;
}
}
}
}
private void _host_MouseUp(object sender, MouseEventArgs e)
{
if (_image != null)
{
_downPress = false;
_host.Cursor = Cursors.Arrow;
if (_cs.X == e.X && _cs.Y == e.Y)
{
if (e.Button == MouseButtons.Left)
{
if (_zoomFactor > _maxZ)
{
return;
}
_oldZFactor = _zoomFactor;
_zoomFactor = _zoomFactor * 1.3f;
}
else if (e.Button == MouseButtons.Right)
{
if (_zoomFactor < _minZ)
{
return;
}
_oldZFactor = _zoomFactor;
_zoomFactor = _zoomFactor / 1.3f;
}
}
_host.Invalidate();
}
}
private void _host_Paint(object sender, PaintEventArgs e)
{
this.DrawImage(0, 0);
}
private void _host_Resize(object sender, EventArgs e)
{
if (_hostLoadComplete)
{
this.DrawImage(0, 0);
}
}
private Control _host;
private Image _image;
private PointF _p;
private PointF _cp;
private PointF _cs;
private RectangleF _mrec; // Main rectangle.
private RectangleF _brec; // Boundary rectangle.
private float _zoomFactor = 1; // Current zoom.
private float _minZ = 0.05f; // Minimum zoom.
private float _maxZ = 20.0f; // Maximum zoom.
private float _oldZFactor = 1; // Previous zoom (bigger means zoom in).
private bool _xOut;
private bool _yOut;
private bool _hostLoadComplete;
private bool _downPress;
///
/// Initializes a new instance of the class.
///
///
/// is .
///
public Viewer(Control hostControl)
{
if (hostControl == null)
{
throw new ArgumentNullException("hostControl");
}
_host = hostControl;
_host.MouseDown += _host_MouseDown;
_host.MouseMove += _host_MouseMove;
_host.MouseUp += _host_MouseUp;
_host.Paint += _host_Paint;
_host.Resize += _host_Resize;
_hostLoadComplete = true;
}
///
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
///
public void Dispose()
{
if (_host != null)
{
_host.MouseDown -= _host_MouseDown;
_host.MouseMove -= _host_MouseMove;
_host.MouseUp -= _host_MouseUp;
_host.Paint -= _host_Paint;
_host.Resize -= _host_Resize;
}
}
}
|
|
|
|

|
thnx eisernwolf , i orginally wrote this class in managed code ,
but i wanted more scroll speed especially for large images.
but u r right , rotating the image doesn't update the sourcehdc which leads to
incorrect results.
|
|
|
|

|
Thanks for your article and code. They saved me a lot of time. I want to send back to you a version that has the following improvements:
1. Changed your control to inherit UserControl so we get all the bells and whistles that go along with that - such as:
a. Dispose using an overloads
b. Capability to drop it into a Form from the VS ToolBox.
c. Use of UserControl's OnPaint, OnMouseWheel, etc
2. Rotation using the Image.RotateFlip method and resetting SourceHDC.
3. MouseWheel for Zoom. I needed right/left click for other reasons so the MouseWheel zoom was necessary. I think it is a superior UI for zooming.
4. I didn't see any memory leaks, but I would like to hear from anyone who finds any.
5. I tested eisernwolf's version of managed code for Drawing (ported his C# version to VB) - it is in the code below as the DrawImageWithoutAPI method). It is not as fast/smooth as your original version, so I won't use it unless someone can figure out how to make it as fast.
Again, Mohammed, many thanks for your code!
Tom
-------------------------------------------------
Imports System.Drawing
Public Class ImageViewer
Inherits UserControl
#Region " Properties & Declarations "
Private Gr As Graphics
Public Property Image() As Bitmap
Get
Return _Image
End Get
Set(ByVal Value As Bitmap)
If _Image IsNot Value Then
_Image = Value
_ZoomFactor = 1
_OldZoomFactor = 1
Me.Invalidate()
End If
End Set
End Property
Private _Image As Bitmap
' Current, minimum, maximum, previous zoom (bigger means zoom in)
Public Property CurrentZoom() As Single
Get
Return _ZoomFactor
End Get
Set(ByVal Value As Single)
_ZoomFactor = Value
DrawImage(Me.Width / 2, Me.Height / 2)
End Set
End Property
Private _ZoomFactor As Single = 1
Private _OldZoomFactor As Single = 1
Public Property MinZoom() As Single
Get
Return _MinZoom
End Get
Set(ByVal Value As Single)
_MinZoom = Value
End Set
End Property
Private _MinZoom As Single = 0.05
Public Property MaxZoom() As Single
Get
Return _MaxZoom
End Get
Set(ByVal Value As Single)
_MaxZoom = Value
End Set
End Property
Private _MaxZoom As Single = 20
' Handles
Private _SourceHDC As IntPtr = Nothing
Private _DestinationHDC As IntPtr = Nothing
' Saved Points
Private _MouseDown As PointF
Private _SavedMouseDown As PointF
' Main rectangle , Boundary rectangle
Private _MainRectF As RectangleF
Private _BoundaryRectF As RectangleF
' Boolean
Private _XOut As Boolean = False
Private _YOut As Boolean = False
Private _DownPress As Boolean = False
#End Region
#Region " Dispose Overloads "
Public Overloads Sub Dispose()
If Not IsNothing(_Image) Then
_Image.Dispose()
_Image = Nothing
End If
If Not _SourceHDC.Equals(IntPtr.Zero) Then
DeleteDC(_SourceHDC)
_SourceHDC = Nothing
End If
If Not IsNothing(Gr) Then
Gr.Dispose()
Gr = Nothing
End If
GC.Collect()
End Sub
#End Region
#Region " Overriden Events "
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
DrawImage(0, 0)
End Sub
Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
MyBase.OnResize(e)
If _Image Is Nothing Then Exit Sub
DrawImage(0, 0)
End Sub
Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
MyBase.OnMouseUp(e)
If _Image Is Nothing Then Exit Sub
_DownPress = False
Me.Cursor = Cursors.Arrow
If _SavedMouseDown.X = e.X And _SavedMouseDown.Y = e.Y Then
If e.Button = MouseButtons.Left Then
If _ZoomFactor > _MaxZoom Then Exit Sub
_OldZoomFactor = _ZoomFactor
_ZoomFactor = _ZoomFactor * 1.3
ElseIf e.Button = MouseButtons.Right Then
If _ZoomFactor < _MinZoom Then Exit Sub
_OldZoomFactor = _ZoomFactor
_ZoomFactor = _ZoomFactor / 1.3
End If
DrawImage(e.X, e.Y)
RaiseEvent ZoomChanged(_ZoomFactor)
End If
End Sub
Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
MyBase.OnMouseDown(e)
If _Image Is Nothing Then Exit Sub
_MouseDown.X = e.X
_MouseDown.Y = e.Y
_SavedMouseDown.X = e.X
_SavedMouseDown.Y = e.Y
_DownPress = True
End Sub
Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)
MyBase.OnMouseMove(e)
If _Image Is Nothing Then Exit Sub
If _DownPress = True Then
Me.Cursor = Cursors.NoMove2D
' Accelerated scrolling when right click drag
Dim cp As New PointF(0, 0)
If e.Button = MouseButtons.Right Then
cp.X = (_MouseDown.X - e.X) * (_Image.Width / 2000)
cp.Y = (_MouseDown.Y - e.Y) * (_Image.Height / 2000)
End If
_MainRectF.X = ((_MouseDown.X - e.X) / _ZoomFactor) + _MainRectF.X + cp.X
_MainRectF.Y = ((_MouseDown.Y - e.Y) / _ZoomFactor) + _MainRectF.Y + cp.Y
DrawImage(0, 0)
If _XOut = False Then _MouseDown.X = e.X
If _YOut = False Then _MouseDown.Y = e.Y
End If
RaiseEvent MoveOver((e.X - _BoundaryRectF.X) / _ZoomFactor + _MainRectF.X, (e.Y - _BoundaryRectF.Y) / _ZoomFactor + _MainRectF.Y)
End Sub
Protected Overrides Sub OnMouseWheel(ByVal e As System.Windows.Forms.MouseEventArgs)
MyBase.OnMouseWheel(e)
If _Image Is Nothing Then Exit Sub
Me.Cursor = Cursors.Arrow
If e.Delta >= 0 Then
If _ZoomFactor > _MaxZoom Then Exit Sub
_OldZoomFactor = _ZoomFactor
_ZoomFactor = _ZoomFactor * 1.3
ElseIf e.Delta < 0 Then
If _ZoomFactor < _MinZoom Then Exit Sub
_OldZoomFactor = _ZoomFactor
_ZoomFactor = _ZoomFactor / 1.3
End If
DrawImage(e.X, e.Y)
RaiseEvent ZoomChanged(_ZoomFactor)
End Sub
#End Region
#Region " Draw Image "
Private Sub DrawImage(ByVal zoomX As Single, ByVal zoomY As Single)
If _Image Is Nothing Then Exit Sub
If _SourceHDC.Equals(IntPtr.Zero) Then
_SourceHDC = CreateCompatibleDC(IntPtr.Zero)
SelectObject(_SourceHDC, _Image.GetHbitmap())
End If
If _DestinationHDC.Equals(IntPtr.Zero) Then
If IsNothing(Gr) Then
Gr = Me.CreateGraphics
End If
_DestinationHDC = Gr.GetHdc()
SetStretchBltMode(_DestinationHDC, 3)
End If
_XOut = False
_YOut = False
If Me.Width > _Image.Width * _ZoomFactor Then
_MainRectF.X = 0
_MainRectF.Width = _Image.Width
_BoundaryRectF.X = (Me.Width - _Image.Width * _ZoomFactor) / 2
_BoundaryRectF.Width = _Image.Width * _ZoomFactor
BitBlt(_DestinationHDC, 0, 0, _BoundaryRectF.X, Me.Height, _SourceHDC, 0, 0, TernaryRasterOperations.BLACKNESS)
BitBlt(_DestinationHDC, _BoundaryRectF.Right, 0, _BoundaryRectF.X, Me.Height, _SourceHDC, 0, 0, TernaryRasterOperations.BLACKNESS)
Else
_MainRectF.X = _MainRectF.X + ((Me.Width / _OldZoomFactor - Me.Width / _ZoomFactor) / ((Me.Width + 0.001) / zoomX))
_MainRectF.Width = Me.Width / _ZoomFactor
_BoundaryRectF.X = 0
_BoundaryRectF.Width = Me.Width
End If
If Me.Height > _Image.Height * _ZoomFactor Then
_MainRectF.Y = 0
_MainRectF.Height = _Image.Height
_BoundaryRectF.Y = (Me.Height - _Image.Height * _ZoomFactor) / 2
_BoundaryRectF.Height = _Image.Height * _ZoomFactor
BitBlt(_DestinationHDC, 0, 0, Me.Width, _BoundaryRectF.Y, _SourceHDC, 0, 0, TernaryRasterOperations.BLACKNESS)
BitBlt(_DestinationHDC, 0, _BoundaryRectF.Bottom, Me.Width, _BoundaryRectF.Y, _SourceHDC, 0, 0, TernaryRasterOperations.BLACKNESS)
Else
_MainRectF.Y = _MainRectF.Y + ((Me.Height / _OldZoomFactor - Me.Height / _ZoomFactor) / ((Me.Height + 0.001) / zoomY))
_MainRectF.Height = Me.Height / _ZoomFactor
_BoundaryRectF.Y = 0
_BoundaryRectF.Height = Me.Height
End If
_OldZoomFactor = _ZoomFactor
If _MainRectF.Right > _Image.Width Then
_XOut = True
_MainRectF.X = (_Image.Width - _MainRectF.Width)
End If
If _MainRectF.X < 0 Then
_XOut = True
_MainRectF.X = 0
End If
If _MainRectF.Bottom > _Image.Height Then
_YOut = True
_MainRectF.Y = (_Image.Height - _MainRectF.Height)
End If
If _MainRectF.Y < 0 Then
_YOut = True
_MainRectF.Y = 0
End If
StretchBlt(_DestinationHDC, _BoundaryRectF.X, _BoundaryRectF.Y, _BoundaryRectF.Width, _BoundaryRectF.Height, _
_SourceHDC, _MainRectF.X, _MainRectF.Y, _MainRectF.Width, _MainRectF.Height, _
TernaryRasterOperations.SRCCOPY)
Gr.ReleaseHdc(_DestinationHDC)
_DestinationHDC = Nothing
End Sub
' Without the API: Noticeably less smooth
Private Sub DrawImageWithoutAPI(ByVal zoomX As Single, ByVal zoomY As Single)
If _Image Is Nothing Then Exit Sub
_XOut = False
_YOut = False
If Me.Width > (_Image.Width * _ZoomFactor) Then
_MainRectF.X = 0
_MainRectF.Width = _Image.Width
_BoundaryRectF.X = (Me.Width - _Image.Width * _ZoomFactor) / 2
_BoundaryRectF.Width = _Image.Width * _ZoomFactor
Else
_MainRectF.X = _MainRectF.X + ((Me.Width / _OldZoomFactor - Me.Width / _ZoomFactor) / ((Me.Width + 0.001F) / zoomX))
_MainRectF.Width = Me.Width / _ZoomFactor
_BoundaryRectF.X = 0
_BoundaryRectF.Width = Me.Width
End If
If (Me.Height > _Image.Height * _ZoomFactor) Then
_MainRectF.Y = 0
_MainRectF.Height = _Image.Height
_BoundaryRectF.Y = (Me.Height - _Image.Height * _ZoomFactor) / 2
_BoundaryRectF.Height = _Image.Height * _ZoomFactor
Else
_MainRectF.Y = _MainRectF.Y + ((Me.Height / _OldZoomFactor - Me.Height / _ZoomFactor) / ((Me.Height + 0.001F) / zoomY))
_MainRectF.Height = Me.Height / _ZoomFactor
_BoundaryRectF.Y = 0
_BoundaryRectF.Height = Me.Height
End If
_OldZoomFactor = _ZoomFactor
If (_MainRectF.Right > _Image.Width) Then
_XOut = True
_MainRectF.X = _Image.Width - _MainRectF.Width
End If
If (_MainRectF.X < 0) Then
_XOut = True
_MainRectF.X = 0
End If
If (_MainRectF.Bottom > _Image.Height) Then
_YOut = True
_MainRectF.Y = _Image.Height - _MainRectF.Height
End If
If (_MainRectF.Y < 0) Then
_YOut = True
_MainRectF.Y = 0
End If
Using g As Graphics = Me.CreateGraphics()
Dim bRecX As Integer = CInt(_BoundaryRectF.X)
Dim bRecY As Integer = CInt(_BoundaryRectF.Y)
Dim bRecWidth As Integer = CInt(_BoundaryRectF.Width)
Dim bRecHeight As Integer = CInt(_BoundaryRectF.Height)
Dim mRecX As Integer = CInt(_MainRectF.X)
Dim mRecY As Integer = CInt(_MainRectF.Y)
Dim mRecWidth As Integer = CInt(_MainRectF.Width)
Dim mRecHeight As Integer = CInt(_MainRectF.Height)
g.DrawImage(_Image, New Rectangle(bRecX, bRecY, bRecWidth, bRecHeight), New Rectangle(mRecX, mRecY, mRecWidth, mRecHeight), GraphicsUnit.Pixel)
Dim leftRectWidth As Integer = bRecX - Me.Left
Dim topRectHeight As Integer = bRecY - Me.Top
Dim topRectWidth As Integer = Me.Width - leftRectWidth
Dim rightRectLeft As Integer = Me.Left + leftRectWidth + bRecWidth
g.FillRectangle(Brushes.Black, New Rectangle(0, 0, leftRectWidth, Me.Height))
g.FillRectangle(Brushes.Black, New Rectangle(leftRectWidth, 0, topRectWidth, topRectHeight))
g.FillRectangle(Brushes.Black, Rectangle.FromLTRB(rightRectLeft, topRectHeight, Me.Right, Me.Bottom))
g.FillRectangle(Brushes.Black, Rectangle.FromLTRB(leftRectWidth, Me.Top + topRectHeight + bRecHeight, rightRectLeft, Me.Bottom))
End Using
End Sub
#End Region
#Region " Rotate Image & Save Image "
' Parameter: Rotation can be 90°, 180° or 270°
Public Sub RotateImage(ByVal rotate As String)
If _Image Is Nothing Then Exit Sub
Dim rt As RotateFlipType
If rotate = "90°" Then
rt = RotateFlipType.Rotate90FlipXY
ElseIf rotate = "180°" Then
rt = RotateFlipType.Rotate180FlipXY
ElseIf rotate = "270°" Then
rt = RotateFlipType.Rotate270FlipXY
Else
Exit Sub
End If
_Image.RotateFlip(rt)
_SourceHDC = Nothing
_DestinationHDC = Nothing
Me.Invalidate()
End Sub
Public Sub SaveImage(ByVal img As Bitmap)
' Displays a SaveFileDialog so the user can save the Image
Dim saveFileDialog1 As New SaveFileDialog()
saveFileDialog1.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif"
saveFileDialog1.Title = "Save Image File"
saveFileDialog1.ShowDialog()
' If the file name is not an empty string open it for saving.
If saveFileDialog1.FileName <> "" Then
' Saves the Image via a FileStream created by the OpenFile method.
Dim fs As System.IO.FileStream = CType _
(saveFileDialog1.OpenFile(), System.IO.FileStream)
' Saves the Image in the appropriate ImageFormat based upon the file type selected in the dialog box.
' NOTE that the FilterIndex property is one-based.
Select Case saveFileDialog1.FilterIndex
Case 1
img.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg)
Case 2
img.Save(fs, System.Drawing.Imaging.ImageFormat.Bmp)
Case 3
img.Save(fs, System.Drawing.Imaging.ImageFormat.Gif)
End Select
fs.Close()
fs.Dispose()
End If
End Sub
#End Region
#Region " Raised Events "
Public Event MoveOver(ByVal Px As Single, ByVal Py As Single)
Public Event ZoomChanged(ByVal CurZoom As Single)
#End Region
End Class
|
|
|
|

|
Very well done, and many thanks for sharing.
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
This is a simple class that can view scroll and zoom pictures
| Type | Article |
| Licence | CPOL |
| First Posted | 6 Feb 2007 |
| Views | 55,926 |
| Downloads | 625 |
| Bookmarked | 45 times |
|
|