Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Background of a saved image problem

Background of a saved image problem

Scheduled Pinned Locked Moved C#
graphicshelpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Eagle32
    wrote on last edited by
    #1

    Hi, I am having problems with the background of the image after it has been rotated and then saved. It saves the rotated image fine but it has a black background but i would like it to be transparent, similar to what occurs under Windows Operating System. I tried using MakeTransparent method before but doesnt seem to work. Here is the code:

    //cast the Image to Bitmap
    Bitmap temp = (Bitmap)ActualImage;
    Color c = temp.GetPixel(1,1);
    //temp.SetPixel(1, 1, Color.Transparent);
    temp.MakeTransparent(c);
    .......
    sfdlg.SaveImage(sfdlg.FileName,temp,80);

    Could anybody assist me with this please? Thanks

    S 1 Reply Last reply
    0
    • E Eagle32

      Hi, I am having problems with the background of the image after it has been rotated and then saved. It saves the rotated image fine but it has a black background but i would like it to be transparent, similar to what occurs under Windows Operating System. I tried using MakeTransparent method before but doesnt seem to work. Here is the code:

      //cast the Image to Bitmap
      Bitmap temp = (Bitmap)ActualImage;
      Color c = temp.GetPixel(1,1);
      //temp.SetPixel(1, 1, Color.Transparent);
      temp.MakeTransparent(c);
      .......
      sfdlg.SaveImage(sfdlg.FileName,temp,80);

      Could anybody assist me with this please? Thanks

      S Offline
      S Offline
      Stanciu Vlad
      wrote on last edited by
      #2

      I don't know what method you use there to save your file, but my guess is you save it as a bitmap (bmp). If so, then I must inform you that bitmaps (bmp files) do not support transparency... the gif and png file format on the other hand supports transparency.

      I have no smart signature yet...

      E 1 Reply Last reply
      0
      • S Stanciu Vlad

        I don't know what method you use there to save your file, but my guess is you save it as a bitmap (bmp). If so, then I must inform you that bitmaps (bmp files) do not support transparency... the gif and png file format on the other hand supports transparency.

        I have no smart signature yet...

        E Offline
        E Offline
        Eagle32
        wrote on last edited by
        #3

        Hi, I am saving the images as JPEGs and i am using the following code: credit goes to microsoft

        private static ImageCodecInfo GetEncoderInfo(String mimeType)
        {
        int j;
        ImageCodecInfo[] encoders;
        encoders = ImageCodecInfo.GetImageEncoders();
        for(j = 0; j < encoders.Length; ++j)
        {
        if(encoders[j].MimeType == mimeType)
        return encoders[j];
        }
        return null;
        }
        private void SaveJPGWithCompressionSetting( Image image, string szFileName, long lCompression )
        {
        EncoderParameters eps = new EncoderParameters(1);
        eps.Param[0] = new EncoderParameter( Encoder.Quality, lCompression );
        ImageCodecInfo ici = GetEncoderInfo("image/jpeg");
        image.Save( szFileName, ici, eps );
        }

        S 1 Reply Last reply
        0
        • E Eagle32

          Hi, I am saving the images as JPEGs and i am using the following code: credit goes to microsoft

          private static ImageCodecInfo GetEncoderInfo(String mimeType)
          {
          int j;
          ImageCodecInfo[] encoders;
          encoders = ImageCodecInfo.GetImageEncoders();
          for(j = 0; j < encoders.Length; ++j)
          {
          if(encoders[j].MimeType == mimeType)
          return encoders[j];
          }
          return null;
          }
          private void SaveJPGWithCompressionSetting( Image image, string szFileName, long lCompression )
          {
          EncoderParameters eps = new EncoderParameters(1);
          eps.Param[0] = new EncoderParameter( Encoder.Quality, lCompression );
          ImageCodecInfo ici = GetEncoderInfo("image/jpeg");
          image.Save( szFileName, ici, eps );
          }

          S Offline
          S Offline
          Stanciu Vlad
          wrote on last edited by
          #4

          As far as I know, jpeg formats do NOT support transparency. Here you have some info about transparency in jpeg (and some other approaches to your problem) http://graphicssoft.about.com/b/2006/08/21/qa-transparent-jpeg.htm[^]. And here you have a list with transparency compatible image types http://en.wikipedia.org/wiki/Transparency_(graphic)[^]. Best of luck!

          I have no smart signature yet...

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups