| Flash for .NET Task-Based Help > C1FlashCanvas Tasks > Rendering Images Using C1FlashCanvas |
To render images using the C1FlashCanvas class, complete the following tasks:
![]() |
Note: You can draw any image which is supported by the .NET framework onto the C1FlashCanvas, since the Flash only supports JPEG and BMP, C1Flash does the necessary conversion if not supported (specifically, JPEG, BMP, GIF, TIFF, PHG, ICON and WMF). |
Here is what the form will look like:

To write code in Visual Basic
| Visual Basic |
Copy Code
|
|---|---|
Private Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
Me.OpenFileDialog1.InitialDirectory = Application.StartupPath
Me.OpenFileDialog1.Filter = _
"All Image Files|*.png;*.emf;*wmf;*tif;*tiff;*.gif;_
*.jpg;*.jpe;*.jpeg;*.bmp;*.dib;*.rle" & _
"|BMP (*.bmp;*.dib;*.rle)|*.bmp;*.dib;*.rle" & _
"|JPEG (*.jpg;*.jpe;*.jpeg)|*.jpg;*.jpe;*.jpeg" & _
"|WMF(*.wmf;*.emf)|*.wmf;*.emf" & _
"|TIFF(*.tif;*tiff)|*.tif;*tiff" & _
"|GIF(*.gif)|*.gif" & _
"|PNG(*.png)|*.png" & _
"|ICON(*.ico)|*.ico"
If Me.OpenFileDialog1.ShowDialog() = DialogResult.OK Then '
Dim filename As String = Me.OpenFileDialog1.FileName.Trim()
If Not (filename Is Nothing) And filename.Length > 0 Then
Dim image As Image = Image.FromFile(filename)
Me.C1FlashCanvas1.Clear(Color.White)
Dim width As Single = image.Width
Dim height As Single = image.Height
If Me.rbBestFit.Checked Then
Dim ratio As Single = CSng(image.Width) / CSng(image.Height)
If image.Width > image.Height Then
width = Me.C1FlashCanvas1.Width
height = CInt(width / ratio)
If height > Me.C1FlashCanvas1.Height Then
height = Me.C1FlashCanvas1.Height
width = height * ratio
End If
Else
height = Me.C1FlashCanvas1.Height
width = CInt(height * ratio)
If width > Me.C1FlashCanvas1.Width Then
width = Me.C1FlashCanvas1.Width
height = width / ratio
End If
End If
End If
Dim x As Single = (Me.C1FlashCanvas1.Width - width) / 2
Dim y As Single = (Me.C1FlashCanvas1.Height - height) / 2
Me.C1FlashCanvas1.DrawImage(image, New RectangleF(x, y, width, height))
image.Dispose()
Me.C1FlashCanvas1.RenderToFile("c:\WindowsApplication1.swf")
LaunchViewer("c:\WindowsApplication1.swf")
End If
End If
End Sub
|
|
To write code in C#
| C# |
Copy Code
|
|---|---|
private void button1_Click(object sender, System.EventArgs e)
{
this.openFileDialog1.InitialDirectory = Application.StartupPath;
this.openFileDialog1.Filter = "All Image Files|*.png;*.emf;*wmf;*tif;*tiff;*.gif;*.jpg;*.jpe;*.jpeg;*.bmp;*.dib;
*.rle|BMP(*.bmp;*.dib;*.rle)|*.bmp;*.dib;*.rle|JPEG(*.jpg;*.jpe;*.jpeg)
|*.jpg;*.jpe;*.jpeg|WMF(*.wmf;*.emf)|*.wmf;*.emf|TIFF(*.tif;*tiff)|
*.tif;*tiff|GIF(*.gif)|*.gif|PNG(*.png)|*.png|ICON(*.ico)|*.ico";
if(this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
string filename = this.openFileDialog1.FileName.Trim();
if (filename != null && filename.Length > 0)
{
Image image = Image.FromFile(filename);
this.c1FlashCanvas1.Clear(Color.White);
float width = image.Width;
float height = image.Height;
if (this.rbBestFit.Checked)
{
float ratio = (float)image.Width/(float)image.Height;
if (image.Width > image.Height)
{
width = this.c1FlashCanvas1.Width;
height = (int)(width/ratio);
if (height > this.c1FlashCanvas1.Height)
{
height = this.c1FlashCanvas1.Height;
width = height * ratio;
}
}
else
{
height = this.c1FlashCanvas1.Height;
width = (int)(height * ratio);
if (width > this.c1FlashCanvas1.Width)
{
width = this.c1FlashCanvas1.Width;
height = width / ratio;
}
}
}
float x = (this.c1FlashCanvas1.Width - width)/2;
float y = (this.c1FlashCanvas1.Height - height)/2;
this.c1FlashCanvas1.DrawImage(image, new RectangleF(x, y, width, height));
image.Dispose();
this.c1FlashCanvas1.RenderToFile(@"c:\WindowsApplication1.swf");
LaunchViewer(@"c:\WindowsApplication1.swf");
}
|
|
Here is what your chosen image (Best Fit and Actual Size, respectively) will look like:

