Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 320961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:48:06+00:00 2026-05-12T08:48:06+00:00

I need to step through a .gif image and determine the RGB value of

  • 0

I need to step through a .gif image and determine the RGB value of each pixel, x and y coordinates. Can someone give me an overview of how I can accomplish this? (methodology, which namespaces to use, etc.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T08:48:06+00:00Added an answer on May 12, 2026 at 8:48 am

    This is a complete example with both methods, using LockBits() and GetPixel(). Besides the trust issues with LockBits() things can easily get hairy.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Drawing;
    
    namespace BitmapReader
    {
        class Program
        {
            static void Main(string[] args)
            {
                //Try a small pic to be able to compare output, 
                //a big one to compare performance
                System.Drawing.Bitmap b = new 
                    System.Drawing.Bitmap(@"C:\Users\vinko\Pictures\Dibujo2.jpg"); 
                doSomethingWithBitmapSlow(b);
                doSomethingWithBitmapFast(b);
            }
    
            public static void doSomethingWithBitmapSlow(System.Drawing.Bitmap bmp)
            {
                for (int x = 0; x < bmp.Width; x++)
                {
                    for (int y = 0; y < bmp.Height; y++)
                    {
                        Color clr = bmp.GetPixel(x, y);
                        int red = clr.R;
                        int green = clr.G;
                        int blue = clr.B;
                        Console.WriteLine("Slow: " + red + " " 
                                           + green + " " + blue);
                    }
                }
            }
    
            public static void doSomethingWithBitmapFast(System.Drawing.Bitmap bmp)
            {
                Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
    
                System.Drawing.Imaging.BitmapData bmpData =
                    bmp.LockBits(rect, 
                        System.Drawing.Imaging.ImageLockMode.ReadOnly,
                        bmp.PixelFormat);
    
                IntPtr ptr = bmpData.Scan0;
    
                int bytes = bmpData.Stride * bmp.Height;
                byte[] rgbValues = new byte[bytes];
    
                System.Runtime.InteropServices.Marshal.Copy(ptr, 
                               rgbValues, 0, bytes);
    
                byte red = 0;
                byte green = 0;
                byte blue = 0;
    
                for (int x = 0; x < bmp.Width; x++)
                {
                    for (int y = 0; y < bmp.Height; y++)
                    {
                        //See the link above for an explanation 
                        //of this calculation
                        int position = (y * bmpData.Stride) + (x * Image.GetPixelFormatSize(bmpData.PixelFormat)/8); 
                        blue = rgbValues[position];
                        green = rgbValues[position + 1];
                        red = rgbValues[position + 2];
                        Console.WriteLine("Fast: " + red + " " 
                                           + green + " " + blue);
                    }
                }
                bmp.UnlockBits(bmpData);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an MVC 3 web application. I need to step through the controller
I need to step through the Qt code to help solve a bug in
I'm trying to step through the Data-Driven Report Subscription setup, but I can't get
I need to step through and debug an assembly uploaded to SQL Server. The
Is there an equivalent of 'perl -d' for PHP? I need to step through
I am in a situation where I need to step through the controller method
I am trying to compile the following software so that I can step through
Very new to XSL (and XML for that matter), but I need to step
I need to do this but one step leads me to uncheck the Allow
I need to extend the Magento shopping cart to include an extra step for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.