Click here to Skip to main content
15,887,477 members
Home / Discussions / C#
   

C#

 
GeneralRe: String Formatting / Interpolation --- Opinions Pin
jschell22-Jan-16 13:55
jschell22-Jan-16 13:55 
AnswerRe: String Formatting / Interpolation --- Opinions Pin
jschell22-Jan-16 14:01
jschell22-Jan-16 14:01 
GeneralRe: String Formatting / Interpolation --- Opinions Pin
Sascha Lefèvre22-Jan-16 23:06
professionalSascha Lefèvre22-Jan-16 23:06 
GeneralRe: String Formatting / Interpolation --- Opinions Pin
jschell28-Jan-16 12:48
jschell28-Jan-16 12:48 
GeneralI want to understand namespace System.Security Pin
BasmaSH19-Jan-16 20:01
BasmaSH19-Jan-16 20:01 
GeneralRe: I want to understand namespace System.Security Pin
dan!sh 19-Jan-16 20:53
professional dan!sh 19-Jan-16 20:53 
GeneralRe: I want to understand namespace System.Security PinPopular
CHill6020-Jan-16 0:38
mveCHill6020-Jan-16 0:38 
QuestionRemoving EXIF Does not work when using Different Encoders to Choose Format Pin
Member 1227351319-Jan-16 2:30
Member 1227351319-Jan-16 2:30 
C#
Im using the following code to fix the orientation of image taking into account the EXIF Orientation Tag 

     static void FixImageOrientation(Image srce)
            {
                const int ExifOrientationId = 0x112;
                // Read orientation tag
                if (!srce.PropertyIdList.Contains(ExifOrientationId)) return;
                var prop = srce.GetPropertyItem(ExifOrientationId);
                var orient = BitConverter.ToInt16(prop.Value, 0);
                // Force value to 1
                prop.Value = BitConverter.GetBytes((short)1);
                srce.SetPropertyItem(prop);
    
                // Rotate/flip image according to <orient>
                switch (orient)
                {
                    case 1:
                     srce.RotateFlip(RotateFlipType.RotateNoneFlipNone);
                     break;
    
                    case 2:
                        srce.RotateFlip(RotateFlipType.RotateNoneFlipX);
                        break;
    
                    case 3:
                         srce.RotateFlip(RotateFlipType.Rotate180FlipNone);
                         break;
    
                    case 4:
                        srce.RotateFlip( RotateFlipType.Rotate180FlipX);
                        break;
    
                    case 5:
                         srce.RotateFlip(RotateFlipType.Rotate90FlipX);
                         break;
    
                    case 6:
                        srce.RotateFlip(RotateFlipType.Rotate90FlipNone);
                        break;
    
                    case 7:
                        srce.RotateFlip(RotateFlipType.Rotate270FlipX);
                        break;
    
                    case 8:
                         srce.RotateFlip(RotateFlipType.Rotate270FlipNone);
                         break;
    
                    default:
                        srce.RotateFlip(RotateFlipType.RotateNoneFlipNone);
                        break;
                }
            }

This code removes the EXIF Orientation Tag properly.
And saving the image works is i simply use **`img.save`**

But the app provides user the ability to select the format of the image.For that i use the following code

  

     private void saveJpeg(string path, Bitmap img, long quality)
            {
    
    
                EncoderParameter qualityParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
    
    
                ImageCodecInfo Codec = this.getEncoderInfo(imgformat);
    
                if (Codec == null)
                    return;
    
                EncoderParameters encoderParams = new EncoderParameters(1);
                encoderParams.Param[0] = qualityParam;
    
                img.Save(path + ext, Codec, encoderParams);
            }
            public string getimgext(string ccodec)
            {
                if (ccodec.Equals("image/png"))
                {
                    return ".png";
                }
                else if (ccodec.Equals("image/jpeg"))
                {
                    return ".jpg";
                }
                else if (ccodec.Equals("image/tiff"))
                {
                    return ".tif";
                }
                else if (ccodec.Equals("image/bmp"))
                {
                    return ".bmp";
                }
    
                else if (ccodec.Equals("image/gif"))
                {
                    return ".gif";
                }
                else
                {
                    return null;
                }
    
            }
            private ImageCodecInfo getEncoderInfo(string mimeType)
            {
                // Get image codecs for all image formats
                ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
    
                // Find the correct image codec
                for (int i = 0; i < codecs.Length; i++)
                    if (codecs[i].MimeType == mimeType)
                        return codecs[i];
                return null;
            }

When i save the image with `SaveJpeg` the image gets saved with wrong orientation.What im i doing wrong? Please help.

QuestionProblem solved: problem de-serializing using GZip: file left "open" Pin
BillWoodruff17-Jan-16 1:45
professionalBillWoodruff17-Jan-16 1:45 
AnswerRe: problem de-serializing using GZip: file left "open" Pin
OriginalGriff17-Jan-16 2:32
mveOriginalGriff17-Jan-16 2:32 
SuggestionRe: problem de-serializing using GZip: file left "open" Pin
Sascha Lefèvre17-Jan-16 3:24
professionalSascha Lefèvre17-Jan-16 3:24 
GeneralRe: problem de-serializing using GZip: file left "open" Pin
BillWoodruff17-Jan-16 4:11
professionalBillWoodruff17-Jan-16 4:11 
GeneralRe: problem de-serializing using GZip: file left "open" Pin
Sascha Lefèvre17-Jan-16 5:41
professionalSascha Lefèvre17-Jan-16 5:41 
GeneralRe: problem de-serializing using GZip: file left "open" Pin
BillWoodruff17-Jan-16 4:06
professionalBillWoodruff17-Jan-16 4:06 
GeneralRe: problem de-serializing using GZip: file left "open" Pin
OriginalGriff17-Jan-16 4:21
mveOriginalGriff17-Jan-16 4:21 
GeneralRe: problem de-serializing using GZip: file left "open" Pin
BillWoodruff17-Jan-16 6:49
professionalBillWoodruff17-Jan-16 6:49 
QuestionHow to disable show again the same form ? Pin
Member 1224802814-Jan-16 0:16
Member 1224802814-Jan-16 0:16 
AnswerRe: How to disable show again the same form ? Pin
John Torjo14-Jan-16 4:02
professionalJohn Torjo14-Jan-16 4:02 
GeneralRe: How to disable show again the same form ? Pin
Member 1224802814-Jan-16 11:18
Member 1224802814-Jan-16 11:18 
GeneralRe: How to disable show again the same form ? Pin
Mycroft Holmes14-Jan-16 11:46
professionalMycroft Holmes14-Jan-16 11:46 
GeneralRe: How to disable show again the same form ? Pin
Member 1224802814-Jan-16 11:59
Member 1224802814-Jan-16 11:59 
GeneralRe: How to disable show again the same form ? Pin
Sascha Lefèvre14-Jan-16 12:14
professionalSascha Lefèvre14-Jan-16 12:14 
AnswerRe: How to disable show again the same form ? Pin
BillWoodruff14-Jan-16 21:30
professionalBillWoodruff14-Jan-16 21:30 
GeneralRe: How to disable show again the same form ? Pin
Member 1224802815-Jan-16 11:03
Member 1224802815-Jan-16 11:03 
Questionsending/receiving sms with c# code using smartphone Pin
Roberto64_Ge12-Jan-16 4:24
Roberto64_Ge12-Jan-16 4:24 

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.