?
Solved

How do I read a 512x512 8-bit grey scale raw image file into a picturebox and display it in a small window?

Posted on 2005-04-21
4
Medium Priority
?
326 Views
Last Modified: 2011-09-20
I have a 512x512 pixel, 8-bit raw, greyscale bitmap image file and would like to display and fit it in a small window.  How do I do it?
0
Comment
Question by:pcssecure
4 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13832915
Where did this image come from?

Bob
0
 
LVL 3

Expert Comment

by:sharpnet
ID: 13835030
Is this a web app or a windows app?  And is the image a standard image file type (ie bmp, gif, jpg)?

If this is a web app, you can use client side script (javascript) to force a window.open to your specifications.  If the images change repeatedly, the script can easily be instantiated from server side code.

In the event method where you want to launch the image, use:

string script = @"<script language='javascript'>window.open('<image path>','windowName','width=512,height=512,scrollbars=false,toolbar=false,statusbar=false');</script>";
RegisterStartupScript("showimage", script);

On a button "submit" event, this will open a new window sized to your image with no toolbars, statusbar or scollbars.

Hope this helps.

Nick
0
 
LVL 10

Accepted Solution

by:
smegghead earned 1500 total points
ID: 13839417
The following code will build a byte array with 262144 (512x512)  elements..

It then displays it onto a graphics device... it can be scaled using the parameters passed into the DrawImage method.

      byte[] id=new byte[512*512];
      int ThisPixel;
      int c1,c2;
      for (c1=0 ; c1<512 ; c1++)
      {
            for (c2=0 ; c2<512 ; c2++)
            {
                  id[(c1*512)+c2]=(byte)(((c1+c2)/1024f)*255f);
            }
      }
      // We now have a nice pattern in the data
      Bitmap bm=new Bitmap(512,512,System.Drawing.Imaging.PixelFormat.Format24bppRgb);
      for (c1=0 ; c1<512 ; c1++)
      {
            for (c2=0 ; c2<512 ; c2++)
            {
                  ThisPixel=(int)id[(c1*512)+c2];
                  bm.SetPixel(c1,c2,Color.FromArgb(ThisPixel,ThisPixel,ThisPixel)); // Grayscale equivalent
            }
      }
      e.Graphics.DrawImage(bm,50,50,100,100); // The size
      bm.Dispose(); // Tidy up

Hth
Smg.
0
 

Author Comment

by:pcssecure
ID: 13840266
Thanks smegghead.  Your code works but the SetPixel call is too slow.  Takes about 1-2s to load a 512x512 image file.  I found some unmanaged code as well that does a better job.  Anyway, I'll give you points.
0

Featured Post

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.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Loops Section Overview
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

807 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