Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Imagelist shows blank bitmaps

Posted on 2008-10-08
8
Medium Priority
?
416 Views
Last Modified: 2012-05-05
This strikes me as odd - I create a small in-memory bitmap, and draw a single character with a background color on it. I then transfer this into an Imagelist control. However, when I transfer the imagelist.image(x) to a location in a picturebox, only the background color of the image shows up.

I know that the bitmap was created correctly, because if I use "bmp1.save(filename)" then take the file and read it into an image ("dim g as image = image.fromfile(filename)") then load g into the imagelist, it works great.

Can anyone tell me why it doesn't transfer properly to the imagelist unless I save it to disk and read it back?  Thanks!!


Dim bmp1 As New Bitmap(CellWidth, CellHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb)
 
For i = 1 To CellWidth
  For l = 1 To CellHeight
  'draw the '1's' as black
   If Mid$(CellString(i), l, 1) = "1" Then
     bmp1.SetPixel(i - 1, CellHeight - l, Color.Black)
   Else
     bmp1.SetPixel(i - 1, CellHeight - l, Color.DarkGoldenrod)
   End If
  Next l
Next i
 
IList1A.Images.Add(bmp1)

Open in new window

0
Comment
Question by:LongDave
[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
  • 4
  • 3
8 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 22673239
try with the following:

yourImgList.ImageSize = new System.Drawing.Size(CellWidth, CellHeight)
yourImgList.Images.Add(bmp1)
yourImgList.TransparentColor = Color.DarkGoldenrod  'optional

0
 

Author Comment

by:LongDave
ID: 22673676
Nope - that didn't do it. The wierd thing is that it seems that saving the bmp to a file and then calling it back somehow transforms it so that it loads properly in the Imagelist control. Any other ideas?

0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 22673845
Does this make a diff?
        Dim bmp1 As New Bitmap(cellWidth, cellHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb)
        Dim G As Graphics = Graphics.FromImage(bmp1)
        G.Clear(Color.Goldenrod)
        For i = 1 To cellWidth
            For l = 1 To cellHeight
                'draw the '1's' as black
                If Mid$(CellString(i), l, 1) = "1" Then
                    G.FillRectangle(Brushes.Black, New Rectangle(i - 1, cellHeight - l, 1, 1))
                End If
            Next l
        Next i
        G.Dispose()
        IList1A.Images.Add(bmp1)

Open in new window

0
Technology Partners: 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!

 

Author Comment

by:LongDave
ID: 22673947
OK!! That did it! But I still don't see why the use of the bmp directly to the imagelist didn't work properly. Any ideas? I'd really like to understand why. But I will issue you the points - I just didn't want to close the question before your answer.
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 22674055
I really don't have a TECHNICAL answer for you sorry...just haven't really seen anyone using Bitmap.SetPixel() and I knew that my method would work...   =\

0
 

Author Closing Comment

by:LongDave
ID: 31504403
Hi, Idle_Mind ... This is the 2nd time you've helped me. Thanks a lot! Your solution looks like it works fine - but I wish I knew WHY the other didn't!  :(
Oh, well!
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 22674227
A simple test using your original technique worked for me...not sure what you did wrong:
Public Class Form1
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim CellWidth As Integer = 5
        Dim CellHeight As Integer = 5
 
        Dim pixels As String = "11111,00100,00100,00100,11111;10001,11011,10101,10001,10001"
        For Each charSig As String In pixels.Split(";")
            Dim bmp As New Bitmap(CellWidth, CellHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb)
            Dim rows() As String = charSig.Split(",")
            For y As Integer = 0 To rows.GetUpperBound(0)
                For x As Integer = 0 To rows(y).Length - 1
                    If rows(y).Substring(x, 1) = "1" Then
                        bmp.SetPixel(x, y, Color.Black)
                    Else
                        bmp.SetPixel(x, y, Color.DarkGoldenrod)
                    End If
                Next
            Next
            ImageList1.Images.Add(bmp)
        Next
        PictureBox1.Image = ImageList1.Images(0)
        PictureBox2.Image = ImageList1.Images(1)
    End Sub
 
End Class

Open in new window

IM-Chars.jpg
0
 

Author Comment

by:LongDave
ID: 22674270
Wierd - thanks for the input though. I was using the DrawImage function to place the chars in the picturebox, but I don't know why that would have made any difference (I'm sure it did not).

But thanks again - hope I don't have to bug you too often! :)
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

670 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