Load/Save Bitmaps

  • Thread starter Thread starter cdvolko
  • Start date Start date
C

cdvolko

Hi,

I'm looking for code to load and save bitmap files (24 bit per pixel).

TIA
Claus
 
Hi,

I'm looking for code to load and save bitmap files (24 bit per pixel).

TIA
Claus


Explore the options in System.Drawing.Bitmap Using those in combination with
System.IO will get you where you need to be.
 
Bitmap image1;

image1 = new Bitmap(@"C:\Documents and Settings\All Users\"
+ @"Documents\My Music\music.bmp", true);
 
Have a look at System.Drawing.Bitmap and System.Drawing.Image.

I've done that. And I've written my program. But when trying to
compile it, I get the error CS0234: The type or namespace name Drawing
does not exist in the namespace system (Is an assembly reference
missing?). What's wrong? Here's my code:


using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.IO;

namespace Border
{
class Program
{
static void Main(string[] args)
{
String filename;
Bitmap myBitmap;

Console.WriteLine("Source file name:");
filename = Console.ReadLine();

myBitmap = new Bitmap(filename);
if (myBitmap == null)
{
Console.WriteLine("Error: File not found!");
return;
}

for (int i = 0; i < 3; i++)
{
for (int j = 0; j < myBitmap.Width; j++)
{
myBitmap.SetPixel(j, i, Color.Black);
myBitmap.SetPixel(j, myBitmap.Height - i,
Color.Black);
}
for (int j = 0; j < myBitmap.Height; j++)
{
myBitmap.SetPixel(i, j, Color.Black);
myBitmap.SetPixel(myBitmap.Width - i, j,
Color.Black);
}
}

myBitmap.Save(filename);
}
}
}
 
I've done that. And I've written my program. But when trying to
compile it, I get the error CS0234: The type or namespace name Drawing
does not exist in the namespace system (Is an assembly reference
missing?). What's wrong? Here's my code:

Yes, we should have mentioned this as well, all apologizes. Just because
your 'using' something doesn't mean your "including" (referencing) it, you
will need to manually add a reference to use the System.Drawing features as
well (at least the Bitmap namespace). If you are developing on a product in
the Microsoft Visual Studio family, you can right click your project in the
Solution Explorer, choose Add Reference... and select System.Drawing in the
..NET Tab.

If your IDE is some other brand, basically you need to reference
System.Drawing.dll

Most of the time you don't need to do this because the most common
Namespaces are included in mscorlib.dll and it is automatically referenced
in any new project you create. I guess System.Drawing.Bitmap isn't
considered "common."


Enjoy!
 
You need to include a reference to the system.drawing assembly. Right click
the references section in Solution Explorer and add System.Drawing.

Have a look at System.Drawing.Bitmap and System.Drawing.Image.

I've done that. And I've written my program. But when trying to
compile it, I get the error CS0234: The type or namespace name Drawing
does not exist in the namespace system (Is an assembly reference
missing?). What's wrong? Here's my code:


using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.IO;

namespace Border
{
class Program
{
static void Main(string[] args)
{
String filename;
Bitmap myBitmap;

Console.WriteLine("Source file name:");
filename = Console.ReadLine();

myBitmap = new Bitmap(filename);
if (myBitmap == null)
{
Console.WriteLine("Error: File not found!");
return;
}

for (int i = 0; i < 3; i++)
{
for (int j = 0; j < myBitmap.Width; j++)
{
myBitmap.SetPixel(j, i, Color.Black);
myBitmap.SetPixel(j, myBitmap.Height - i,
Color.Black);
}
for (int j = 0; j < myBitmap.Height; j++)
{
myBitmap.SetPixel(i, j, Color.Black);
myBitmap.SetPixel(myBitmap.Width - i, j,
Color.Black);
}
}

myBitmap.Save(filename);
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top