A Graphics object cannot be created from an image that has an indexed pixel format.

  • Thread starter Thread starter Jon Q Jacobs
  • Start date Start date
J

Jon Q Jacobs

Guest
I have used this Overlay function with tif files I create. However, when I download a "real" tif image from our repository, I get the subject line error.

1. What is an indexed pixel format?

2. Can I convert it in my code to an acceptible format? or use a different object to accomplish the text overlay header?

public void Overlay(string fn, string accn)
{
string dir = Path.GetDirectoryName(fn);
string temp = Path.Combine(dir, "temp.tif");
File.Delete(temp);
File.Move(fn, temp);
string msg = "Accn:" + accn;
FileStream fs = File.Open(temp, FileMode.Open, FileAccess.Read);
Bitmap bm = (Bitmap)Bitmap.FromStream(fs);
Graphics graphics = Graphics.FromImage(bm);
SolidBrush brush = new SolidBrush(Color.Black);
Font font = new Font("Courier New", 20, FontStyle.Bold);
Rectangle rect = new Rectangle(8, 8, 300, 80);
graphics.DrawString(msg, font, brush, rect);
fs.Close();
bm.Save(fn);
}
Thanks,

Jon Jacobs
Not sent from my iphone, because I don't have one.

Continue reading...
 
Back
Top