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 7400265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:13:22+00:00 2026-05-29T04:13:22+00:00

i have read the thread Google Goggles API . and From NotAnotherCodeBlog have created

  • 0

i have read the thread
Google Goggles API. and From
NotAnotherCodeBlog have created a c# implementation using the sample code. Has anyone been able to get it working recently? i know the API isn’t documented and as such may have changed so its possible the code worked and now doesn’t OR that my code is faulty. I keep getting an exception thrown giving me a protocol error. (error 500 in the exception and protocol error in the exception status) Code below.

 using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
public class Goggles
{         // The POST body required to validate the CSSID.         
    private static byte[] CssidPostBody = new byte[] { 34, 0, 98, 60, 10, 19, 34,
        2, 101, 110, 186, 211, 240, 59, 10, 8, 1, 16, 1, 40, 1, 48, 0, 56, 1, 18,             
        29, 10, 9, 105, 80, 104, 111, 110, 101, 32, 79, 83, 18, 3, 52, 46, 49,              
        26, 0, 34, 9, 105, 80, 104, 111, 110, 101, 51, 71, 83, 26, 2, 8, 2, 34,             
        2, 8, 1 };
    // Bytes trailing the image byte array. Look at the next code snippet to see         
    // where it is used in SendPhoto() method.         
    private static byte[] TrailingBytes = new byte[] { 24, 75, 32, 1, 48, 0, 146,
        236, 244, 59, 9, 24, 0, 56, 198, 151, 220, 223, 247, 37, 34, 0 };
    // Generates a cssid.         
    private static string Cssid
    {
        get
        {
            Random random = new Random((int)DateTime.Now.Ticks);
            return string.Format(
                "{0}{1}",
                random.Next().ToString("X8"),
                random.Next().ToString("X8"));
        }
    }
    static void Main(string[] args)
    {
        string cssid = Goggles.Cssid;
        Goggles.ValidateCSSID(cssid);
        // See next code snippet for SendPhoto()             
        //Goggles.SendPhoto(cssid, yourImageByteArray);             
        Console.ReadLine();
    }
    // Validates the CSSID we just created, by POSTing it to Goggles.         
    private static void ValidateCSSID(string cssid)
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(string.Format("http://www.google.com/goggles/container_proto?cssid={0}", cssid));
        Goggles.AddHeaders(request); request.Method = "POST";
        using (Stream stream = request.GetRequestStream())
        {
            stream.Write(Goggles.CssidPostBody, 0, Goggles.CssidPostBody.Length);
            stream.Flush();
        } 
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    }
    private static byte[] imageToByteArray(System.Drawing.Image imageIn)
    {
        MemoryStream ms = new MemoryStream();
        imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
        return ms.ToArray();
    }
    private static void AddHeaders(HttpWebRequest request)
    {
        request.ContentType = "application/x-protobuffer";
        request.Headers["Pragma"] = "no-cache";
        request.KeepAlive = true;
    }
    public static HttpWebResponse SendPhoto(string file)
    {
        System.Drawing.Image oimg = System.Drawing.Image.FromFile(file);

        return (SendPhoto(imageToByteArray(oimg)));
    }
    public static   HttpWebResponse  SendPhoto(byte[] image)
    {
        string cssid = null;
        HttpWebResponse response;
        SendPhoto(ref cssid, image, out response);
        return response;
    }
    public static void SendPhoto( ref string cssid, byte[] image, out HttpWebResponse pHttpWebResponse) 
    { 
        if (cssid == null || cssid == "") 
                cssid = Goggles.Cssid;

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(

            string.Format(        
            "http://www.google.com/goggles/container_proto?cssid={0}",
            cssid));
        Goggles.AddHeaders(request);
        request.Method = "POST";       
        // x = image size
        int x = image.Length;
        byte[] xVarint = Goggles.ToVarint32(x).ToArray<byte>();
        // a = x + 32     
        byte[] aVarint = Goggles.ToVarint32(x + 32).ToArray<byte>();
        // b = x + 14     
        byte[] bVarint = Goggles.ToVarint32(x + 14).ToArray<byte>();
        // c = x + 10     
        byte[] cVarint = Goggles.ToVarint32(x + 10).ToArray<byte>();
        // 0A [a] 0A [b] 0A [c] 0A [x] [image bytes]     
        using (Stream stream = request.GetRequestStream())     
        {         
            // 0x0A         
            stream.Write(new byte[] { 10 }, 0, 1);
                // a         
            stream.Write(aVarint, 0, aVarint.Length);
            // 0x0A         
            stream.Write(new byte[] { 10 }, 0, 1);
            // b         
            stream.Write(bVarint, 0, bVarint.Length);           
            // 0x0A         
            stream.Write(new byte[] { 10 }, 0, 1);
            // c         
            stream.Write(cVarint, 0, cVarint.Length);
            // 0x0A         
            stream.Write(new byte[] { 10 }, 0, 1);
            // x         
            stream.Write(xVarint, 0, xVarint.Length);
            // Write image          
            stream.Write(image, 0, image.Length);
            // Write trailing bytes         
            stream.Write(             
                Goggles.TrailingBytes,
                0,              Goggles.TrailingBytes.Length);
            stream.Flush();
        } try
        {
            pHttpWebResponse = null;
            pHttpWebResponse = (HttpWebResponse)request.GetResponse();
        }
        catch (Exception ex)
        {
            pHttpWebResponse = null;

        }
    }
    // Encodes an int32 into varint32. 
    public static IEnumerable<byte> ToVarint32(int value) 
    {     
        int index = 0;
        while ((0x7F & value) != 0)
        {         
            int i = (0x7F & value);
            if ((0x7F & (value >> 7)) != 0)
            {             
                i += 128;         
            }     

            yield return ((byte)i);         
            value = value >> 7;
            index++;     
        } 
    }
}

Cheers
Tim

  • 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-29T04:13:23+00:00Added an answer on May 29, 2026 at 4:13 am

    One issue may be the fact that you’re sending .gif format as opposed to .jpg. I think that’s what Fadi said he had tested

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using sbt 0.10 with Scala 2.9.1. I've read http://groups.google.com/group/simple-build-tool/browse_thread/thread/792e5360877e78/987b6af687b8e33b?lnk=gst&q=collect+jars#987b6af687b8e33b However I don't want
I have read that using database keys in a URL is a bad thing
I have read (or perhaps heard from a colleague) that in .NET, TransactionScope can
I found some sample code posted at https://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/4d45e9ea5471cba4/4519371a77ed4a74?hl=en&pli=1 for self installing a Windows Service.
I've read this: http://groups.google.com/group/play-framework/browse_thread/thread/1df0a77ef811a225 but not found the answer in fact i have turned
I have read this thread: http://jasperforge.org/plugins/espforum/view.php?group_id=83&forumid=101&topicid=67923 I would rather not repeat the page header
I'm trying to change priority of main thread using android.os.Process.setThreadPriority() . I have log
I have read through several reviews on Amazon and some books seem outdated. I
I have read a lot that LISP can redefine syntax on the fly, presumably
I have read about partial methods in the latest C# language specification , so

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.