.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

encoding/decoding a string to/from bitmap

Posted By:      Posted Date: August 24, 2010    Points: 0   Category :ASP.Net

I have two methods:

Encode - takes a string, converts it to array of bytes, uses bytes to specify colors, creates a color and sets a pixel based on bytes

Decode - takes a pixel, retrieves color (R,G,B) bytes and converts them to characters, that produces a string which was previously encoded

I'm using two for loops (img height/width) to specify position and access pixels

The issue is that once display (Control Panel\Appearance and Personalization\Display) changes to anything other then "Smaller - 100%",
bytes have different values during decoding, thus different string is produced (corrupted).

If the setting is set to "Smaller - 100%" the results are normal.

What can I do to avoid that problem?

Thanks in advance

View Complete Post

More Related Resource Links

Encoding en Decoding HTML



I stored in a database a ntext "<b>Hello</b>";

But when  I read it from the database I see <b>Hello</b> instead of Hello.

In the html source I see this: &lt;b&gt;Hello&lt;/b&gt;

Any Idea?


Encoding.ASCII.GetString(bytes) return string with not expected

Example   byte[] bytes = {  0x36,0x92,0x30,0x94}; string rs=  Encoding.ASCII.GetString(bytes) ; //result rs = ?60?   Is Wrong Result; Result Right is     '60". So this function should fix to properly decode two symbols ' and " Code ASCII ' is 0x92,Code ACII for " is  0x94

help encoding a string like this: The%20Best%20Place%20in%20Vancouver


how do I convert a string like this: "The Best Place in Vancouver " to this -> The%20Best%20Place%20in%20Vancouver





Byte array -> String encoding

Greetings and sorry for the likely newbie question.  I also hope this is in the right forum!

What's the most "pure" way to encode a Byte array into a String?  I've performed several searches but none have yielded much insight into my particular problem.  I'm using C++, COM Interop into a VB6 application that uses a String return for socket class, but the actual issue is in the .NET native code.

  Encoding::ASCII->GetString(byteArray, 0, iNumBytes)
.. converts values >7 bits to a replacement value... and

  Encoding::UTF8->GetString(byteArray, 0, iNumBytes)
.. truncates the higher value chars from the conversion totally..

And obviously Unicode things the string is 1/2 it's actual size which makes parsing for markers in said data a real chore.  The byte streams are about 90% text and 10% binary (with markers/tags).

String containers seem to be able to do what I need them to do as manually initializing them, they get back up to the VB6 app without any problems.  It's just how to get these Byte arrays into them that's the problem.

Replacing the VB6.0 app to use something other than String would also be less than ideal as it's usage wasn't coded very managebly either and is widespread in a very, very large application.

The Byte array is from Socket class operations.  I'm unsure if there is a

How to count number of bytes in string for utf-8 encoding


How to find number of bytes in string in utf-8 encoding ?

str.Length returns number of characters but in utf-8 encoding some characters occupy more than 1 byte ? 

How to Encrypt Query String Parameters in ASP.NET

Encrypt Query String Parameters in ASP.NET.u can send secure data one page another page u can also use query string to encrypt

Connestion string create any database server

This links important to how to create connection string to any data base sever.

SQL Connection String

We can learn or know how can we connect the database from our .net. This will help for freshers or .NET beginners!

Built-in Functions - String Functions

String functions let you extract various portions of character strings, change the case of strings, concatenate and reverse strings and perform many other types of manipulations. All built-in string functions are deterministic with the exception of CHARINDEX and PATINDEX

abstract away the source of the connection string using a class with a static property.

ASP.NET provides a configuration system we can use to keep our applications flexible at runtime. In this article we will examine some tips and best practices for using the configuration system for the best results.

The element of a web.config file is a place to store connection strings, server names, file paths, and other miscellaneous settings needed by an application to perform work. The items inside appSettings are items that need to be configurable depending upon the environment, for instance, any database connection strings will change as you move your application from a testing and staging server into production.

Let's abstract away the source of the connection string using a class with a static property.

highlight string


i am looking for a function that takes two string parameters 

str1 = "hello how are you today mr john"

str2 = "how today"

and in return it shoud highlight the words "how" and "today".

Any ides? I prefer if its possible using reg expression...Thanks

Could some one tell me whats the Problem with this String Manipulation ??? C#.net



I store some values from code behind to a label which is Hidden !

<asp:Label ID="lbl_Hidden" runat="server" Visible = "false"></asp:Label>

and at the page load event i retrieve the value of the label & assign it to a string !

stringvalue = lbl_Hidden.Text;

Now i dont know why this manipulation does'nt work !

I've a character 'A' in the string and i'm unable to replace it with a space !

stringvalue.Replace(A, " ");

Wot do u think abt it ????

extract picture data from a string


dears,advance thanks.can anybdy help to solve my problem which is describing below.

Example- %%D1,100,0,0004[data...][0d0a]

Head - %%D1
Amount of data package -100
The data package No. - 0
Data Length -1024 (0004 (low bit in front, high bit in back) 0004= 0x0400=1024;)

data- Original Picture data -1024(maximum)
Tail -0x0d0a
Data in hex

from the above example i want to extract picture data and need to store in to the sql table.sql table columname is image and datatype is also image.after that i wanted to display this image column to an aspx page.

expecting help asap.

connection string question from a newbie


when publishing  in the webmatrix dialogue it asks for "destination connection string" for my "database.mdf"

I was not sure what it was so I pasted this from my web.config file :

Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\database.mdf;Integrated Security=True;User Instance=True

it all published ok, but wont run, so I guess it has somthing to do with this connection string or some kind of configuration issue.

My question is this, What should go in the field for "Destination connection string"

WebMatrix conversion failed when converting from a character string to uniqueidentifier?


I am trying to retrieve xml from a small function in my .cshtml page. Its throwing me an error. This however, runs fine in a console/form environment.

It takes 3 parameters and 1 exception.

myDll.GetXML(year, username, uniqueidentifier, out ex);

When I run this page I get the error, "Conversion failed when converting from a character string to uniqueidentifier."

Or a stack of.

System.Data.SqlClient.SqlException (0x80131904): Conversion failed when converting from a character string to uniqueidentifier.

   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)

   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)

   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()

   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)

   at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()

   at System.Data.SqlClient.SqlDataReader.get_MetaData()

   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)

   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBeha

Membership Provider Conn String


Hello. I've bee successfully using the Asp.Net Membership Provider in my VB.Net 3.5/SQL 2005 web app for a year now (Site A). However, I've added 2 new sites (B and C) (both with their own DB) and now I see a problem. It looks like users that get created for sites B and C also get created in site A. Roles that I create for B and C only get created in A. I think it is a conn string problem.

When I created A, I adde the conn string to my machine.config (not sure why I did this or if it is even needed)...


         <add name="LocalSqlServer" connectionString="Data Source=VS689\SQLEXPRESS;Initial Catalog=SiteA;USER ID=sa;PASSWORD=123456"/>


                <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=, Culture=neutral, PublicKeyToken=blahblah" connectionStringName="LocalSqlS

Search for a string in my datasource dynamically


I am displaying an Rssfeed on my page by using XmlDataSource and Datalist controls.

I want the user to be able to limit the information that is returned to my datalist.  To do this I have a textbox on the form that allows the user to enter their search criteria.

I need to be able to dynamically create a query string utilizing the information that the user entered in the textbox.  I am also using a drop down list and allowing the user to select whether they want to search in the title, description, or all parts of the xml file.

I am having trouble figuring out how to reference the data contained in my textbox in my query string.  Where the query string says 'asp', I want to replace 'asp' with the content from my sSearch variable.  Can anyone tell me how to reference my variable in the query string???

string sSearch = txtSearch.Text;
        string SQuery = "";

        if (DropDownList2.SelectedIndex == 0)
            SQuery = "[contains(title), 'asp')]";

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend