?
Solved

Image Comes With Black Background When Read It from DB ??!!

Posted on 2005-03-30
6
Medium Priority
?
293 Views
Last Modified: 2010-04-24
Hi to all .NET Exprts ...

I'm working on VB .NET and SQL Server ...
I save an image in some fields in DB, (the field type is image) ..
but when I read it from VB it comes with black background except to be transpernt... Why ?

This is the code I used :
----------------------------------------------------------------------------
     If Not Ds.Tables(0).Rows(I)("GroupPictureHeaderSmall") Is DBNull.Value Then
        Dim buffer() As Byte = CType(Ds.Tables(0).Rows(I)("GroupPictureHeaderSmall"), Byte())
        Dim str As New System.IO.MemoryStream(buffer)
        Dim PicImage As Image = Image.FromStream(str)
           If Not PicImage Is Nothing Then
                    MyPic.Image = PicImage
           End If
     End If
----------------------------------------------------------------------------

Thanks
0
Comment
Question by:SamehRefaat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 9

Expert Comment

by:Lacutah
ID: 13663777
Instead of:
        Dim PicImage As Image = Image.FromStream(str)
Try:
        Dim PicImage As Image = Image.FromStream(str, True)

The "True" specifies to use embedded color management information in the stream.
0
 

Author Comment

by:SamehRefaat
ID: 13664469
Lacutah .. I tried it .. Still same problem ..
0
 
LVL 9

Expert Comment

by:Lacutah
ID: 13665023
Hmph....  I'm kinda stumped...

Few questions that might help:
1.  Can you restore the image (with the transparancy intact) from the database using any other program?
2.  How was the image saved to the database?  Could the program saving it have stripped the transparancy?
3.  What's the native image format in the database?  (GIF, PNG, etc...)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:SamehRefaat
ID: 13669573

1)....................
2) This is the answer for 3rd question :

Dim Exec As SqlHelper
Dim str As New System.IO.MemoryStream
Pic.Save(str, Imaging.ImageFormat.Jpeg)   ' Same Result if use .Icon
buffer(CInt(str.Length - 1)) As Byte
str.Position = 0
str.Read(buffer, 0, CInt(str.Length))
Dim prmPic As New System.Data.SqlClient.SqlParameter    'create parameter
            With prmPic
                    .ParameterName = "@MyPicture"  
                    .SqlDbType = SqlDbType.Image                        
                    .Value = buffer
             End With
 
Exec.ExecuteNonQuery(connectionstring, CommandType.Text, "Update sMenuGroups  Set " & sender & "=@MyPicture Where ID=" & ID, prmPic)

3) the picture format is Icon

Thanks
0
 

Author Comment

by:SamehRefaat
ID: 13669592
Lacutah ... this problem just in Icon and in its trasperency .. I tried PNG and it's work good
0
 
LVL 9

Accepted Solution

by:
Lacutah earned 2000 total points
ID: 13674153
Pic.Save(str, Imaging.ImageFormat.Jpeg)   ' Same Result if use .Icon
Jpeg doesn't support transparencyso there's no way to "save" that information in the file.
Icon's do support transparancy, but I'll bet you would need to set a transparent color for it to work.
I'd stick to PNG or GIF for saving, since both have support for transparency.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question