Click here to Skip to main content
15,922,696 members
Home / Discussions / C#
   

C#

 
GeneralRe: GC in Services Pin
Daniel Turini23-May-03 2:40
Daniel Turini23-May-03 2:40 
GeneralRe: GC in Services Pin
solidstore22-May-03 4:02
solidstore22-May-03 4:02 
GeneralRe: GC in Services Pin
Daniel Turini22-May-03 2:56
Daniel Turini22-May-03 2:56 
GeneralRe: GC in Services Pin
solidstore22-May-03 3:24
solidstore22-May-03 3:24 
GeneralRe: GC in Services Pin
solidstore22-May-03 3:16
solidstore22-May-03 3:16 
Questionis there a simple grid for windows forms? Pin
IsaacB21-May-03 6:04
IsaacB21-May-03 6:04 
AnswerRe: is there a simple grid for windows forms? Pin
Anonymous21-May-03 6:44
Anonymous21-May-03 6:44 
Generalsaving and changing a .tiff file's properties Pin
Chris Eatough21-May-03 5:51
Chris Eatough21-May-03 5:51 
Hey,

Ive been writing a simple image viewer program in C# and wanted to add the option to save a loaded image to another format. In the tiff format though its been a pain, i want to read in the tiff image's format, and give the option of changing that format. So far i do not know how to read an images properties, can anyone help?Confused | :confused:

Heres the proto source code ive done (bulit up mostly from CodeProject articles Smile | :) )

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace ImageViewer
{
public class MyForm : System.Windows.Forms.Form
{
private System.ComponentModel.Container components = null;
protected MenuItem _itemNativeSize;
protected MenuItem _itemWindowSize;
protected int _filterIndex = -1;
protected Bitmap _myBitmap;
protected bool _nativeSize = true;

public MyForm()
{
InitializeComponent();

// set the initial text and size of the window
this.Text = "Image Viewer 0.0";
this.ClientSize = new Size(640, 480);
....
}

private void OnOpenImage(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();


if(_filterIndex != -1)
ofd.FilterIndex = _filterIndex;

if(ofd.ShowDialog() == DialogResult.OK)
{
String filename = ofd.FileName;
if(filename.Length != 0)
{
_filterIndex = ofd.FilterIndex;
try
{
_myBitmap = new Bitmap(filename);
this.Text = "Image Viewer - " + filename;
this.AutoScroll = true;
this.AutoScrollMinSize = _myBitmap.Size;
this.Invalidate();
}
catch
{
MessageBox.Show(String.Format ("{0} is not " +
"a valid image file", filename), "Error");
}
}
}
}

private void OnSaveImage(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();

sfd.Title = "Save Image As";

if(sfd.ShowDialog() == DialogResult.OK)
{
sfd.AddExtension = true;
String filename = sfd.FileName;
if(filename.EndsWith(".png"))
_myBitmap.Save(filename, ImageFormat.Png);
else if(filename.EndsWith(".tiff") || filename.EndsWith(".tif"))
_myBitmap.Save(filename, ImageFormat.Tiff);
else if(filename.EndsWith(".bmp"))
_myBitmap.Save(filename, ImageFormat.Tiff);
else if(filename.EndsWith(".jpeg") || filename.EndsWith(".jpg"))
_myBitmap.Save(filename, ImageFormat.Jpeg);
else if(filename.EndsWith(".gif"))
_myBitmap.Save(filename, ImageFormat.Gif);
else
MessageBox.Show("Unknown file type");
}
}

private void OnExit(object sender, EventArgs e)
{
this.Close();
}


protected override void OnPaint(PaintEventArgs e)
{
if(_myBitmap != null)
{
Graphics g = e.Graphics;
if(_nativeSize)
{
g.DrawImage(_myBitmap,
this.AutoScrollPosition.X,
this.AutoScrollPosition.Y,
_myBitmap.Width, _myBitmap.Height);
}
else
{
g.DrawImage(_myBitmap, this.ClientRectangle);
}
}
}

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion

[STAThread]
static void Main()
{
Application.Run(new MyForm());
}
}
}
Generalprinting issues Pin
RB@Emphasys21-May-03 5:14
RB@Emphasys21-May-03 5:14 
QuestionPost Visual Inheritance? Pin
Rocky Moore21-May-03 2:54
Rocky Moore21-May-03 2:54 
AnswerRe: Post Visual Inheritance? Pin
Arjan Einbu21-May-03 3:07
Arjan Einbu21-May-03 3:07 
GeneralRe: Post Visual Inheritance? Pin
Rocky Moore21-May-03 3:53
Rocky Moore21-May-03 3:53 
GeneralRe: Post Visual Inheritance? Pin
Rocky Moore21-May-03 22:58
Rocky Moore21-May-03 22:58 
QuestionHow To Open Browserlink in Winforms Pin
rund1me21-May-03 1:26
rund1me21-May-03 1:26 
AnswerRe: How To Open Browserlink in Winforms Pin
Arjan Einbu21-May-03 2:56
Arjan Einbu21-May-03 2:56 
GeneralRe: How To Open Browserlink in Winforms Pin
rund1me21-May-03 3:10
rund1me21-May-03 3:10 
GeneralSharing values with multiple forms Pin
totig21-May-03 0:30
totig21-May-03 0:30 
GeneralRe: Sharing values with multiple forms Pin
Rocky Moore21-May-03 2:47
Rocky Moore21-May-03 2:47 
GeneralRe: Sharing values with multiple forms Pin
totig21-May-03 4:46
totig21-May-03 4:46 
GeneralRe: Sharing values with multiple forms Pin
Rocky Moore21-May-03 21:34
Rocky Moore21-May-03 21:34 
Questionhow to receive html element events Pin
benzite21-May-03 0:14
benzite21-May-03 0:14 
AnswerRe: how to receive html element events Pin
Jose Fco Bonnin22-May-03 3:54
Jose Fco Bonnin22-May-03 3:54 
GeneralRe: how to receive html element events Pin
benzite22-May-03 18:56
benzite22-May-03 18:56 
GeneralOffice XP and 2000 Automation Compatibility Pin
Braulio Dez20-May-03 23:33
Braulio Dez20-May-03 23:33 
GeneralRe: Office XP and 2000 Automation Compatibility Pin
shaunAustin21-May-03 4:03
shaunAustin21-May-03 4:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.