views:

245

answers:

1

I'm working on a solution that enables our users to draw annotations over images.So far I'm using graphics object to draw an image(annotations) over another one. The problem is that we can't always get a Graphics object from an image(GDI+ throws an exception if we try to get a graphics object of an indexed formatted image)

So the question is :

what are my options to solve this problem? can I change the PixelFormat temporarily ,get a graphics object ,do my painting and retrieve it back to its original format or can I draw an image over another one without using Graphics object?

+1  A: 

I can't answer you regarding GDI however I would propose that your overlay method could always take the same format (RGB 24-bit) image, and prior to performing the overlay, remember the input image format and convert the result image to it for the users. So perhaps three methods as in this rough pseudocode:

  • ConvertImageFormat(TargetFormat, ImageObject)
  • OverlayText(ImageObject, Text)
  • GetImageFormat(ImageObject)
    UserFormat = GetImageFormat(SourceImage);
    TempImage = ConvertImageFormat(RGBFormat, SourceImage);
    ImageWithText = OverlayText(TempImage, Text);
    UserImage = ConvertImageFormat(UserFormat, ImageWithText);
JYelton