Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2005-03-30
6
Medium Priority
?
296 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
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

580 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