Results 1 to 9 of 9

Thread: 2 diff blob format reading error

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2020
    Posts
    6

    2 diff blob format reading error

    Dear All.,

    I want to read a column which has 2 blob format in the below code

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If (OleDbConnection1.State And ConnectionState.Open) <> 0 Then
                OleDbConnection1.Close()
            End If
     OleDbConnection1.ConnectionString = "Provider=IBMDADB2.DB2COPY1;Data Source=PORTLOB;Persist Security Info=True;Password=123456;User ID=Administrator;oledbreportislongforlongtypes=1;lobmaxcolumnsize=20480;longdatacompat=1;allowgetdatalobreaccess=1;"
            'MaximumInlineLobSize=32; HexParserOption=Binary;
            OleDbDataAdapter1.SelectCommand = OleDbSelectCommand1
            OleDbSelectCommand1.CommandText = "SELECT P_IMAGE FROM PORTLOB WHERE ID=(" & Text1.Text & ") "
            OleDbSelectCommand1.Connection = OleDbConnection1
    
            DataSet11.PORT_IMAGE.Clear()
    
            OleDbConnection1.Open()
            Try
                OleDbDataAdapter1.Fill(DataSet11, "PORT_IMAGE")
                Dim c As Integer = DataSet11.Tables("PORT_IMAGE").Rows.Count
                If c > 0 Then
                    Dim bytBLOBImage() As Byte = DataSet11.Tables("PORT_IMAGE").Rows(c - 1)("P_IMAGE")
                    Dim ms As MemoryStream = New MemoryStream(bytBLOBImage)
                    PictureBox1.Image = Image.FromStream(ms)
                Else
                    MessageBox.Show("NO PHOTOS")
                End If
            Catch Ex As OleDb.OleDbException
                MessageBox.Show(Ex.Message)
            End Try
            OleDbConnection1.Close()
    
        End Sub
    I have 2 blob format in the same column as the following:
    1- Colour picture start with 0000 WIDTH=480 HEIGHT=640
    2- B&W (Black and white) picture start with FF B&W WIDTH=153 HEIGHT=208
    I am using DB2 VER10.5 AND VS 2010, I get the below error when I try to read them
    System.ArgumentException: Parameter is not valid.
    at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
    at System.Drawing.Image.FromStream(Stream stream)
    at PHOTOSMATCH.Form4.Button1_Click(Object sender, EventArgs e) in E:\PHOTOSMATCH\PHOTOSMATCH\Form4.vb:line 72
    at System.Windows.Forms.Control.OnClick(EventArgs e)
    at System.Windows.Forms.Button.OnClick(EventArgs e)
    at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
    at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ButtonBase.WndProc(Message& m)
    at System.Windows.Forms.Button.WndProc(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    So, How can I solve the parameter error to be able to read both format?

    Thanks for your co-operations.
    Last edited by si_the_geek; Oct 26th, 2020 at 02:31 PM. Reason: added Code tags

  2. #2
    Frenzied Member
    Join Date
    May 2014
    Location
    Central Europe
    Posts
    1,318

    Re: 2 diff blob format reading error

    1- Colour picture start with 0000 WIDTH=480 HEIGHT=640
    2- B&W (Black and white) picture start with FF B&W WIDTH=153 HEIGHT=208
    does that mean the bytestream starts with certain bytes to indicate the picture? what are these bytes really (0000 =two bytes, FF=one byte?? seems odd)? is the size of the image also included in the byte stream or fixed to these values? is the rest of the byte stream raw uncompressed data?
    please show the first 20 bytes or so of one color and one b/W image along with the size of the bytearray.

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2020
    Posts
    6

    Re: 2 diff blob format reading error

    this is the first 130 string of color picture
    0000000C6A5020200D0A870A00000014667479706A703220000000006A7032200000002D6A70326800000016696864720000 00D000000099000107070000000000
    image lenght=18242

    This for B/W
    FFD8FFE000104A4649460001000100B000B00000FFFE001F4C45414420546563686E6F6C6F6769657320496E632E2056312E 303100FFDB00430003020202020203
    Image lenght =7042

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,562

    Re: 2 diff blob format reading error

    Does this mean the blob field contains 2 images in one record?

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2020
    Posts
    6

    Re: 2 diff blob format reading error

    Does this mean the blob field contains 2 images in one record?
    NO
    blob column contain 2 different format images

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    33,060

    Re: 2 diff blob format reading error

    If you're storing more than one format type in a single column, then you (ideally) need other columns to act as meta data to tell you what the data is and how to handle it. My guess is that you'll need two different sets of codes to handle the different formats. I don't think that you'll find one that can handle every thing.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7
    Frenzied Member
    Join Date
    May 2014
    Location
    Central Europe
    Posts
    1,318

    Re: 2 diff blob format reading error

    You need to tell us more about the format the images are stored. an image 640x480 has 307,200 pixels, an image 153x208 has 37,824 pixels. unless these images have large areas of just one single color and the format uses run length encoding, it is very hard to stuff color data for 307k pixels into 18,242 bytes / 38k pixels into 7,042 bytes.

  8. #8

    Thread Starter
    New Member
    Join Date
    Oct 2020
    Posts
    6

    Re: 2 diff blob format reading error

    already I have a metadata column refer to image
    column =" image_format " with type 1 &2
    1 is for jpeg2000 type
    my problem how to display this type as a picture i found freeimage package but I don't know to use

  9. #9
    Frenzied Member
    Join Date
    May 2014
    Location
    Central Europe
    Posts
    1,318

    Re: 2 diff blob format reading error

    https://www.google.com/search?q=.net...om+byte+stream
    first hit shows an example of how to use freeimage (which i have never done myself):
    Code:
    byte[] myByte = new byte[10];
    MemoryStream theMemStream = new MemoryStream();
    theMemStream.Write(myByte, 0, myByte.Length);
    FreeImageBitmap fbm = FreeImageBitmap.FromStream(theMemStream);
    fbm.Save("text.jpg",FREE_IMAGE_STREAM.FIF_JPEG);
    where are you struggling?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width