byte[] von der System.Drawing.Bitmap Klasse.



  • Die frage ist wie komm ich da ran?? Ich hab keine ahnung. Also ich mein jetzt das System.Drawing.Bitmap muss doch irgentwie ein byte[] enthalten wo die ganzen bits gespeichert sind?!

    Das Problem Ich erstelle momentan ein neues byte[] :

    int i = bmp.Height*bmp.Width;
    byte[] arr_bytes = new byte[i];
    i = 0;

    for (int x = 0; x < bmp.Width; x++)
    {
    for (int y = 0; y < bmp.Height; y++)
    {
    byte b = 0;
    if (bmp.GetPixel(x, y).B < 128)
    b = 128;
    arr_bytes[i] = b;
    i++;
    }
    }

    Aber das bei jedem rendering aufruf sprengt die CPU Auslastung ^^

    Kann mir da jemand vllt helfen?!

    mfg KainPlan



  • Ja das ich damit das bild zerstöre is mir gerade auch schon aufgefallen also eher:

    for (int y = 0; y < bmp.Height; y++)
    {
    for (int x = 0; x < bmp.Width; x++)
    {

    byte b = 0;
    if (bmp.GetPixel(x, y).B < 128)
    b = 128;
    arr_bytes[i] = b;
    i++;
    }
    }

    ^^



  • Keiner ne Idee???



  • So ganz klar ist mir Dein Problem nicht ... ich vermute aber mal, Du meinst dies: [url=http://msdn2.microsoft.com/de-de/library/5ey6h79d(VS.80).aspx]??[/url]



  • Ja das ist ne lösung jetzt is aber das problem das die anzeige nur 8bpp hat und das byte[] wird dann nicht korrekt dargestellt... was mach ich da??



  • Was genau hast du den vor?
    Du hast ne Bitmap, speicherst dir dann die Pixel in nen Byte-Array und manipulierst da noch ein wenig rum und willst dann das Ergebnis anzeigen?

    Machst du da nen Spiel oder sowas?
    Bei nur 8-Bit Farbtiefe müsstest du ja quasi Dithern oder sowas (aber macht Windows das nicht von selbst?)



  • Okay.

    Also ich arbeite am G15 Display und ja es wird ein Spiel^^.

    Ich arbeite mit dem hobbit125.lglcd.dll wrapper fürs .net 2.0. Mit dem
    "Av's Logitech G15 LCD interface module" war das alles kein problem aber der GC
    hat da nicht sauber gearbeitet also der Process hat immer mehr speicher "Gefressen" hing aber halt mit dem wrapper zusamm...

    jetzt hab ich halt ein System.Drawing.Bitmap objekt auf das ich mittels Graphics objekt zeichne nach dem zeichen vorgang im Rendering thread sende ich eine interne Bitmap struct die die bits des "surfaces" (das System.drawing.Bitmap objekt) enthält an den wrapper halt das byte[]
    aber das byte[] ist immernoch im falschen Format. Sprich es ist 160x43x4 anstatt 160x43x1!!! grml... ich krieg noch zuviel. ^^



  • AHHHH ICH HABS!!!! 😃

    //Preform bit reading of bmp.
    Draw.Rectangle rect = new Draw.Rectangle(0, 0, bmp.Width, bmp.Height);
    System.Drawing.Imaging.BitmapData bmpData =
    bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,
    bmp.PixelFormat);
    IntPtr ptr = bmpData.Scan0;
    int bytes = bmp.Width * bmp.Height * 4;
    byte[] rgbValues = new byte[bytes];
    //Marshal copy the bits at ptr to rgbValues at 0 for a size of bytes.
    System.Runtime.
    InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);
    bytes = bmp.Width * bmp.Height * 1;
    byte[] bValues = new byte[bytes];
    int i = 0;
    //Convert into a Displayable kind.
    while (i != bytes)
    {
    bValues[i] = rgbValues[i * 4];
    i++;
    }

    lgbmp.pixels = bValues;

    Sorry fürs spammen aber ich hab jetzt die ganze nacht an der lösung gesessen!!!! oh weh. Aber es funzt ohne de CPU auszu lasten (trotz rendering calls) ^^ *Freu


Anmelden zum Antworten