Click here to Skip to main content
15,880,651 members
Home / Discussions / C#
   

C#

 
AnswerRe: Dynamically close DB2 CLP window using C# Pin
Richard Deeming30-Mar-16 8:52
mveRichard Deeming30-Mar-16 8:52 
GeneralRe: Dynamically close DB2 CLP window using C# Pin
Tej_dev30-Mar-16 9:03
Tej_dev30-Mar-16 9:03 
QuestionBitmap to BitmapImage Conversion Not Working - WPF Pin
AmbiguousName30-Mar-16 4:36
AmbiguousName30-Mar-16 4:36 
AnswerRe: Bitmap to BitmapImage Conversion Not Working - WPF Pin
Rob Philpott30-Mar-16 5:46
Rob Philpott30-Mar-16 5:46 
GeneralRe: Bitmap to BitmapImage Conversion Not Working - WPF Pin
AmbiguousName30-Mar-16 6:04
AmbiguousName30-Mar-16 6:04 
AnswerRe: Bitmap to BitmapImage Conversion Not Working - WPF Pin
Matt T Heffron30-Mar-16 6:54
professionalMatt T Heffron30-Mar-16 6:54 
AnswerRe: Bitmap to BitmapImage Conversion Not Working - WPF Pin
Gerry Schmitz30-Mar-16 7:06
mveGerry Schmitz30-Mar-16 7:06 
AnswerRe: Bitmap to BitmapImage Conversion Not Working - WPF Pin
V.31-Mar-16 3:42
professionalV.31-Mar-16 3:42 
this should work:
C#
/// <summary>
/// makes the image uniform between operations, size wise and concerning pixelformat.
/// </summary>
/// <param name="bmp"></param>
private BitmapImage SetModifiedImage(System.Drawing.Bitmap bmp){
    bmp = CreateNonIndexedImage(bmp);
    BitmapImage bmpi = new BitmapImage(); 
    bmpi.BeginInit(); 
    bmpi.StreamSource = new System.IO.MemoryStream((byte[])(new System.Drawing.ImageConverter()).ConvertTo(bmp, typeof(byte[])));
    bmpi.EndInit(); 
        return bmpi;
}

/// <summary>
/// Removes the index color table of the image and makes it uniform.
/// </summary>
/// <param name="bmp"></param>
/// <returns></returns>
private System.Drawing.Bitmap CreateNonIndexedImage(System.Drawing.Bitmap bmp){
    System.Drawing.Bitmap newbmp = new System.Drawing.Bitmap(bmp.Width, bmp.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
    System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newbmp);
    g.DrawImage(bmp, 0, 0);
    return newbmp;          
}
You don't need the "CreateNonIndexedImage" normally. I had different sets of input and the difference in the PixelFormat gave me problems when working on the bytes of the bitmap.

Hope this helps.
V.
(MQOTD rules and previous solutions)

Questionworking with pixels Pin
Hira Khalid29-Mar-16 3:16
Hira Khalid29-Mar-16 3:16 
AnswerRe: working with pixels Pin
OriginalGriff29-Mar-16 3:33
mveOriginalGriff29-Mar-16 3:33 
AnswerRe: working with pixels Pin
Dave Kreskowiak29-Mar-16 3:45
mveDave Kreskowiak29-Mar-16 3:45 
AnswerRe: working with pixels Pin
Eddy Vluggen29-Mar-16 4:06
professionalEddy Vluggen29-Mar-16 4:06 
QuestionRe: working with pixels Pin
Richard MacCutchan29-Mar-16 4:25
mveRichard MacCutchan29-Mar-16 4:25 
GeneralRe: working with pixels Pin
harold aptroot29-Mar-16 9:34
harold aptroot29-Mar-16 9:34 
QuestionAccessing unmanaged class from C# Pin
Leif Simon Goodwin29-Mar-16 1:22
Leif Simon Goodwin29-Mar-16 1:22 
QuestionRe: Accessing unmanaged class from C# Pin
Richard MacCutchan29-Mar-16 1:42
mveRichard MacCutchan29-Mar-16 1:42 
AnswerRe: Accessing unmanaged class from C# Pin
Leif Simon Goodwin29-Mar-16 4:17
Leif Simon Goodwin29-Mar-16 4:17 
GeneralRe: Accessing unmanaged class from C# Pin
Richard MacCutchan29-Mar-16 4:32
mveRichard MacCutchan29-Mar-16 4:32 
GeneralRe: Accessing unmanaged class from C# Pin
Leif Simon Goodwin29-Mar-16 5:10
Leif Simon Goodwin29-Mar-16 5:10 
AnswerRe: Accessing unmanaged class from C# Pin
Garth J Lancaster29-Mar-16 1:47
professionalGarth J Lancaster29-Mar-16 1:47 
GeneralRe: Accessing unmanaged class from C# Pin
Leif Simon Goodwin29-Mar-16 1:49
Leif Simon Goodwin29-Mar-16 1:49 
AnswerReply # 2 Pin
Garth J Lancaster29-Mar-16 2:03
professionalGarth J Lancaster29-Mar-16 2:03 
AnswerRe: Accessing unmanaged class from C# Pin
Bernhard Hiller31-Mar-16 0:39
Bernhard Hiller31-Mar-16 0:39 
GeneralRe: Accessing unmanaged class from C# Pin
Leif Simon Goodwin3-Apr-16 21:16
Leif Simon Goodwin3-Apr-16 21:16 
QuestionHow to select Windows explorer's 'Sort by' type programmatically Pin
srikrishnathanthri28-Mar-16 23:32
srikrishnathanthri28-Mar-16 23:32 

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.