Guide for C#
Core Document Formats
Additional Features

C# Imaging - Create Windows Image Viewer in C#

100% C# Sample Code to Create Windows Image Viewer

Visual C#
Home > .NET Imaging SDK > C# > Create Windows Viewer
If this is your first time to use our DocImageSDK, we strongly suggest you reading How to Start first!

C# Windows Image Viewer SDK Overview

Like C#.NET Web Image Viewer, this professional and mature Windows Image Viewer from Rasteredge DocImage SDK for .NET, C#.NET can be also used to view, process and annotate image and document on your C#.NET Windows application. Written in 100% managed C# code and developed in .NET Framework 2.0, this standalone and clean .NET doc image library can help C# developers create a Windows image (picture / photo) viewer without using other external document or image viewing SDKs.
In this online tutorial page for how to create a Windows document image viewer application, you will find information on following aspects.
  • Key feature list of C#.NET Windows image viewer control SDK
  • How to use and activate this Visual C# .NET Windows document image viewer library add-on
  • C#.NET programming example to create a Windows document image viewer application
  • C#.NET Windows image viewer SDK FAQs
If you want to create a Windows document image viewing application for specific document or image type, please try this C#.NET Windows PDF document viewer SDK or Visual C# .NET Windows TIFF image viewer add-on and Windows Word (.doc /. docx) file viewer plugin.
C# Windows Document Image Viewer Features
  • No client downloads & installation, no flash plugin
  • Easily integrated into Visual C# .NET Windows application
  • Supports creating Windows image viewer project in Visual Studio 2005 or greater versions
  • Programmed in full C# code and compatible with .NET-compliant programming language C#
  • Support displaying and viewing multiple document image formats in C#.NET Windows class application
  • Users are allows to add their own command to customize this C#.NET Window image viewer
  • Allow developers to add, delete and reorder target image and document using simple C# code
  • Provide flexible document image processing functions, like cropping, image sharpening and vintage effect adding
  • Simple to rotate the viewing image & document files by 90 degrees, 180 degrees and 270 degrees
  • Easy to redact image and document by burning various text or graphic annotations
Run C#.NET Windows Image Viewer DLL
For Visual C#.NET developers, it is easy to create a high-quality Windows image viewer using this C#.NET Windows document image viewer SDK. In this section, we will guide you on how to activate and integrate this Windows document image viewer control SDK into your C#.NET class application. (For VB.NET developers, please go to Create Windows Image Viewer using VB.NET Programming Code.)
  1. Run Microsoft Visual Studio (2005 or later versions);
  2. Create a Windows class project that is compatible with Visual C# programming code;
  3. Download and unzip the trial version of RasterEdge DocImage SDK for .NET;
  4. Add all the dlls from above mentioned .NET imaging SDK to your Visual C# .NET application by adding reference directly;
  5. Call the namespace of this C#.NET Windows document image viewer SDK;
  6. Now you can create a Windows document image viewer application using following sample C# code.
C#.NET Windows Image Viewer Example
In this section, we provide you a Visual C# code snippet which you can use to create a Windows viewer application to display, annotate and process document files and image formats in .NET class application.
using System.IO;
using System.Drawing.Printing;
using RasterEdge.Imaging;
using System;
using System.Windows;
using RasterEdge.Imaging.WindowsControl;

namespace Picture_Labs
{
public partial class Form1 : Form
{
RasterImaging WindowsViewer = new RasterImaging();

//Open And Save Dialog
OpenFileDialog ofd = new OpenFileDialog();
SaveFileDialog sfd = new SaveFileDialog();

//Zoom Level
double zoomFactor = 1.0;

//Image Processing Handler
RasterImaging.ImageHandler imageHandler = new RasterImaging.ImageHandler();

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
imageHandler = new RasterImaging.ImageHandler();
}

private void cOpen_Click(object sender, EventArgs e)
{
ofd = new OpenFileDialog();
ofd.Title = "Open Picture";
ofd.Filter = "Picture File |*.bmp;*.jpg;*.png;*.gif";
ofd.ShowDialog();
if (ofd.FileName.ToString() != "")
{
//Send Image To Handle
imageHandler.CurrentBitmap = (Bitmap)Bitmap.FromFile(ofd.FileName);
imageHandler.BitmapPath = ofd.FileName;

this.AutoScroll = true;
this.AutoScrollMinSize = new Size(Convert.ToInt32(imageHandler.CurrentBitmap.Width * zoomFactor),
Convert.ToInt32(imageHandler.CurrentBitmap.Height * zoomFactor));
this.Invalidate();

ofd.Dispose();
}

}

// Detect any Change From Handle and Then Display It To Current Form
private void Form1_Paint(object sender, PaintEventArgs e)
{
// Scale Image To Center Screen
Graphics g = e.Graphics;
int FormSizeX = (this.Size.Width / 2) - ( imageHandler.CurrentBitmap.Width / 2);
int FormSizeY = (this.Size.Height / 2) - (imageHandler.CurrentBitmap.Height / 2);
g.DrawImage(imageHandler.CurrentBitmap, new Rectangle(FormSizeX, FormSizeY,
Convert.ToInt32(imageHandler.CurrentBitmap.Width * zoomFactor),
Convert.ToInt32(imageHandler.CurrentBitmap.Height * zoomFactor)));
}

// Save The File
private void cSave_Click(object sender, EventArgs e)
{
sfd = new SaveFileDialog();
sfd.Title = "Save Pictre";
sfd.Filter = "Windows Bitmap (*.bmp) |*.bmp";
sfd.ShowDialog();
if (sfd.FileName.ToString() != "")
{
imageHandler.SaveBitmap(sfd.FileName);
}
}

// Change Zoom Level
private void cbScale_Change(object sender, EventArgs e)
{
switch (cbScale.Text)
{
case "50%":
zoomFactor = 0.5;
this.AutoScrollMinSize = new Size(Convert.ToInt32(imageHandler.CurrentBitmap.Width * zoomFactor),
Convert.ToInt32(imageHandler.CurrentBitmap.Height * zoomFactor));
this.Invalidate();
break;
case "100%":
zoomFactor = 1.0;
this.AutoScrollMinSize = new Size(Convert.ToInt32(imageHandler.CurrentBitmap.Width * zoomFactor),
Convert.ToInt32(imageHandler.CurrentBitmap.Height * zoomFactor));
this.Invalidate();
break;
case "150%":
zoomFactor = 1.5;
this.AutoScrollMinSize = new Size(Convert.ToInt32(imageHandler.CurrentBitmap.Width * zoomFactor),
Convert.ToInt32(imageHandler.CurrentBitmap.Height * zoomFactor));
this.Invalidate();
break;
case "200%":
zoomFactor = 2.0;
this.AutoScrollMinSize = new Size(Convert.ToInt32(imageHandler.CurrentBitmap.Width * zoomFactor),
Convert.ToInt32(imageHandler.CurrentBitmap.Height * zoomFactor));
this.Invalidate();
break;
case "250%":
zoomFactor = 2.5;
this.AutoScrollMinSize = new Size(Convert.ToInt32(imageHandler.CurrentBitmap.Width * zoomFactor),
Convert.ToInt32(imageHandler.CurrentBitmap.Height * zoomFactor));
this.Invalidate();
break;
case "300%":
zoomFactor = 3.0;
this.AutoScrollMinSize = new Size(Convert.ToInt32(imageHandler.CurrentBitmap.Width * zoomFactor),
Convert.ToInt32(imageHandler.CurrentBitmap.Height * zoomFactor));
this.Invalidate();
break;
case "350%":
zoomFactor = 3.5;
this.AutoScrollMinSize = new Size(Convert.ToInt32(imageHandler.CurrentBitmap.Width * zoomFactor),
Convert.ToInt32(imageHandler.CurrentBitmap.Height * zoomFactor));
this.Invalidate();
break;
case "400%":
zoomFactor = 4.0;
this.AutoScrollMinSize = new Size(Convert.ToInt32(imageHandler.CurrentBitmap.Width * zoomFactor),
Convert.ToInt32(imageHandler.CurrentBitmap.Height * zoomFactor));
this.Invalidate();
break;
default:
break;
}
}

// Rotate And Flip Image
private void cbRotateFlip_Change(object sender, EventArgs e)
{
switch (cbRotateFlip.Text)
{
case "Rotate 90":
imageHandler.RotateFlip(RotateFlipType.Rotate90FlipNone);
this.AutoScroll = true;
this.AutoScrollMinSize = new Size(Convert.ToInt32(imageHandler.CurrentBitmap.Width * zoomFactor),
Convert.ToInt32(imageHandler.CurrentBitmap.Height * zoomFactor));
this.Invalidate();
break;
case "Rotate 180":
imageHandler.RotateFlip(RotateFlipType.Rotate180FlipNone);
this.AutoScroll = true;
this.AutoScrollMinSize = new Size(Convert.ToInt32(imageHandler.CurrentBitmap.Width * zoomFactor),
Convert.ToInt32(imageHandler.CurrentBitmap.Height * zoomFactor));
this.Invalidate();
break;
case "Rotate 270":
imageHandler.RotateFlip(RotateFlipType.Rotate270FlipNone);
this.AutoScroll = true;
this.AutoScrollMinSize = new Size(Convert.ToInt32(imageHandler.CurrentBitmap.Width * zoomFactor),
Convert.ToInt32(imageHandler.CurrentBitmap.Height * zoomFactor));
this.Invalidate();
break;
case "Flip Horizontal":
imageHandler.RotateFlip(RotateFlipType.RotateNoneFlipX);
this.AutoScroll = true;
this.AutoScrollMinSize = new Size(Convert.ToInt32(imageHandler.CurrentBitmap.Width * zoomFactor),
Convert.ToInt32(imageHandler.CurrentBitmap.Height * zoomFactor));
this.Invalidate();
break;
case "Flip Vertical":
imageHandler.RotateFlip(RotateFlipType.RotateNoneFlipY);
this.AutoScroll = true;
this.AutoScrollMinSize = new Size(Convert.ToInt32(imageHandler.CurrentBitmap.Width * zoomFactor),
Convert.ToInt32(imageHandler.CurrentBitmap.Height * zoomFactor));
this.Invalidate();
break;
default:
break;
}
}

private void cbMask_Change(object sender, EventArgs e)
{
switch (cbMask.Text)
{
case "Red":
this.Cursor = Cursors.WaitCursor;
imageHandler.RestorePrevious();
imageHandler.SetColorFilter(RasterImaging.ImageHandler.ColorFilterTypes.Red);
this.Invalidate();
this.Cursor = Cursors.Default;
break;
case "Green":
this.Cursor = Cursors.WaitCursor;
imageHandler.RestorePrevious();
imageHandler.SetColorFilter(RasterImaging.ImageHandler.ColorFilterTypes.Green);
this.Invalidate();
this.Cursor = Cursors.Default;
break;
case "Blue":
this.Cursor = Cursors.WaitCursor;
imageHandler.RestorePrevious();
imageHandler.SetColorFilter(RasterImaging.ImageHandler.ColorFilterTypes.Blue);
this.Invalidate();
this.Cursor = Cursors.Default;
break;
default:
break;
}
}

private void cbFilter_Change(object sender, EventArgs e)
{
switch (cbFilter.Text)
{
//"Gamma",
//"Contrast",
//"Brightness"});
case "Grayscake":
this.Cursor = Cursors.WaitCursor;
imageHandler.RestorePrevious();
imageHandler.SetGrayscale();
this.Invalidate();
this.Cursor = Cursors.Default;
break;
case "Invert":
this.Cursor = Cursors.WaitCursor;
imageHandler.RestorePrevious();
imageHandler.SetInvert();
this.Invalidate();
this.Cursor = Cursors.Default;
break;
case "Gamma":
this.Cursor = Cursors.WaitCursor;
imageHandler.RestorePrevious();
//You Can Change This Value
imageHandler.SetGamma( 2.1, 2.1, 2.0); //Is Enough?
this.Invalidate();
this.Cursor = Cursors.Default;
break;
case "Contrast":
this.Cursor = Cursors.WaitCursor;
imageHandler.RestorePrevious();
//You Can Change This Value
imageHandler.SetContrast(2.5); //Is Enough?
this.Invalidate();
this.Cursor = Cursors.Default;
break;
case "Brightness":
this.Cursor = Cursors.WaitCursor;
imageHandler.RestorePrevious();
//You Can Change This Value
imageHandler.SetBrightness(15); //Is Enough?
this.Invalidate();
this.Cursor = Cursors.Default;
break;
default:
break;
}
}

}
}
C#.NET Windows Image Viewer FAQs
Q 1: Does this C#.NET Windows Image Viewer SDK allow developers to edit the content of target image or document file?
A 1: This C#.NET Windows Image Viewers SDK does not support editing & redacting the original content of source document image file. But developers can add some comment or hide certain content by burning annotations.

Q 2: What document image types are supported by this C#.NET Windows Image Viewer SDK?
A 2: Using this C#.NET Windows document image viewer SDK, developers can easily view and display the document types (like Word, PDF and TIFF) and the image formats (like PNG, JPEG, GIF and BMP).
See more Image Viewer Creation Tutorial!
More Tutorials!
Find more user guides with RasteEdge .NET Image SDK using Visual C# sample codings!


Recommend this to Google+