none
Urgent help needed!!! Problem with loading byte array into bitmap object RRS feed

  • Pregunta

  • Hi all,

    I don't know if this is the correct forum for uploading this question, i found no other.

    I have the following problem.
    I'm using a check reader which also scans the check.
    The scanner api dll has a certain function for saving the image directly to disk. If I use this function all is ok.
    But the problem is that I need not to save this image to disk because i have to save it in a sql database.
    So, reading the documentation, i realized that after the scanner scans the check, it gives me a pointer to the image buffer.
    So, what I do is load this buffer into a bitmap object. This way is fine for me, then I can save the image to the database from the bitmap object.

    But... here is my problem, if I test saving this bitmap, the I open it, it's the same as the one saved by the dll function, but it's colors are not the same.
    I enclose you here both images (I uploaded them in jpg format but i also updoaded them in bmp format)

    The one that is ok (saved by the dll) -> http://www.sistemasplenario.com.ar/dllbmp.jpg    |     http://www.sistemasplenario.com.ar/dllbmp.bmp
    The one that is bad(saved by me) -> http://www.sistemasplenario.com.ar/mybmp.jpg    |     http://www.sistemasplenario.com.ar/mybmp.bmp

    I enclose here the code I use for locking the bits and asigning them to the bitmap object:

    img.tImageSize  -> is the size of the image

    img.lpImage -> is the pointer to the image buffer

    -------------------------------------------------------------------------------

    Dim

     

    buffer(img.tImageSize) As Byte

    System.Runtime.InteropServices.Marshal.Copy(img.lpImage, buffer, 0, img.tImageSize)

     

    Dim bmp As New Bitmap(img.lWidth, img.lHeight, img.lWidth * 4, Imaging.PixelFormat.Format24bppRgb, buffer(0))

     

    Dim rect As New Rectangle(0, 0, bmp.Width, bmp.Height)

     

    Dim bmpData As System.Drawing.Imaging.BitmapData = bmp.LockBits(rect, Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat)

     

    Dim ptr As IntPtr = bmpData.Scan0

    System.Runtime.InteropServices.Marshal.Copy(buffer, 0, ptr, img.tImageSize)

    bmp.UnlockBits(bmpData)

    bmp.Save(

    "C:\mybmp.bmp")


    Thanks in advance


    Antonio Briones Sistemas Plenario vb and c# .net developer for win and web forms. I work for
    viernes, 28 de agosto de 2009 14:28

Respuestas

  • As I can see you can Speak Spanish, so... Why are you using english in a Spanish forum?
    I think would be better to use Spanish, some people here are good at programming but they can't understand English...
    • Marcado como respuesta Antonio Briones miércoles, 2 de septiembre de 2009 0:07
    martes, 1 de septiembre de 2009 16:15

Todas las respuestas

  • As I can see you can Speak Spanish, so... Why are you using english in a Spanish forum?
    I think would be better to use Spanish, some people here are good at programming but they can't understand English...
    • Marcado como respuesta Antonio Briones miércoles, 2 de septiembre de 2009 0:07
    martes, 1 de septiembre de 2009 16:15
  • Es verdad!, pasa que siempre postee en los foros en ingles, pensaba que este era en ingles tambien!, de cualquier forma ya solucione el problema de otra forma, uso la funcion de la dll para guardar la imagen en un directorio temporal y luego la levanto.
    Gracias igual!
    Antonio Briones Sistemas Plenario vb and c# .net developer for win and web forms. I work for
    miércoles, 2 de septiembre de 2009 0:09