Dear all:
How to convert color image to bi-level image? I have confronted one
problem when I build my OCR project. I used an software API function to
enhance my project, but the API only support bi-level image. So I need
this convert code to do this process, but it is not my study field. I
try to view several website to write this code, but it can not work.
Would anyone give me the conversion code or give me some tip or website
to learn. I only need this function to complete my project. I will
appreciate your kindness, thanks a lot. 3 5065
Thanks four your response.
I found a VB.NET code to transform from color image to bi-level image.
I try to transform to C# which I used, but there is always several
error I can't solve. Is anyone can see the error reason and tell me .
Thanks a lot.
-----------------------------------------------------------------------------------------------
Public Function GetBWBitmap(ByV al src As Bitmap) As Bitmap
Dim width, height, index, maskIndex As Integer
Dim dest As Bitmap
Dim row, col As Integer
Dim bmdDest As BitmapData
width = src.Width
height = src.Height
'Create a new bitmap of the proper format
dest = New Bitmap(width, height, PixelFormat.For mat1bppIndexed)
bmdDest = dest.LockBits(N ew Rectangle(0, 0, width, height),
dest.Flags, dest.PixelForma t)
Dim myBytes(bmdDest .Stride * height - 1), temp(0) As Byte
'Copy the src bitmap to the array of bytes
For row = 0 To height - 1
For col = 0 To width - 1
index = row * bmdDest.Stride + ((col - 3.5) / 8)
maskIndex = Math.Abs((col Mod 8) - 7)
temp(0) = myBytes(index)
Dim myBits As New BitArray(temp)
Dim myMask As New BitArray(8, 0)
If (src.GetPixel(c ol, row).GetBrightn ess() > 0.5F) Then
myMask(maskInde x) = True
End If
myBits.Or(myMas k)
myBits.CopyTo(m yBytes, index)
Next
Next
'Copy array of bytes into destination bitmap
Marshal.Copy(my Bytes, 0, bmdDest.Scan0, bmdDest.Stride * height
- 1)
dest.UnlockBits (bmdDest)
GetBWBitmap = dest
End Function
----------------------------------------------------------------------------------------------------
public Bitmap ImageConvert(Bi tmap SourceImg)
{
//Declare Variable
int ImgWidth;
int ImgHeight;
Bitmap DestinationImg;
BitmapData DestinationData ;
//Set SourceImg width and height to variables imgwidth and
imgheight
ImgWidth = SourceImg.Width ;
ImgHeight = SourceImg.Heigh t;
//Create a new bitmap of the proper format
//Set DestinationImg to the Black and White formate,
Format1bppindex ed.
//Specifies that the pixel format is 1 bit per pixel and
that it uses indexed color.
//The color table therefore has two colors in it.
DestinationImg = new Bitmap(ImgWidth , ImgHeight,
PixelFormat.For mat1bppIndexed) ;
//Locks a Bitmap into system memory.
DestinationData = DestinationImg. LockBits(new Rectangle(0,
0, ImgWidth, ImgWidth), DestinationImg. Flags,
DestinationImg. PixelFormat);
//Copy the SourceImg bitmap to the array of bytes
byte[] TempBytes;
byte[] ImgBytes = new
byte[DestinationData .Stride*ImgHeig ht-1];
int index;
int maskIndex;
for (int row = 0; row <= ImgHeight - 1; row++)
{
for (int col = 0; col <= ImgWidth - 1; col++)
{
index = row * DestinationData .Stride + (int)((col -
3.5) / 8);
maskIndex = Math.Abs((col % 8) - 7);
TempBytes = ImgBytes;
BitArray myBits = new BitArray(TempBy tes);
BitArray myMask = new BitArray(8,true );
if ((SourceImg.Get Pixel(col, row).GetBrightn ess() >
0.5F))
{
myMask[maskIndex]= true;
}
myBits.Or(myMas k);
myBits.CopyTo(I mgBytes, index);
}
}
Marshal.Copy(Im gBytes, 0, DestinationData .Scan0,
DestinationData .Stride * ImgHeight - 1);
DestinationImg. UnlockBits(Dest inationData);
return DestinationImg;
}
The error message is "parameter is not valid", it is on
DestinationData = DestinationImg. LockBits(new Rectangle(0,
0, ImgWidth, ImgWidth), DestinationImg. Flags,
DestinationImg. PixelFormat);
Is there anyone knows how to solve this error? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: DD |
last post by:
Hi Guys!
Just would like to share with you my experiense in this matter.
I was trying to evaluate how suitable Oracle OLAP for our
applications.
As probably you did, I have downloaded from OTN website OraJDeveloper
and BI Beans, installed them and opened Cube Viewer ... no luck! Just
did not work.
After very long conversation(s) with...
|
by: V?ronique |
last post by:
hi everyone,
if you are a BI tool user, speak spanish, then you might be interested
in decideo, which is a community of BI tool users. the newsletter is
on:
http://www.decideo.com/es/newsletters/decideo_es_3_21_02-2004.htm
and you can subscribe for free, it's bimensual and the info is good as
they are far away from the comercial blabla...
|
by: YellowFin Announcements |
last post by:
Announcing Yellowfin Version 2.4 release. (www.yellowfin.com.au)
Existing SQLserver users can take advantage of this upgrade as soon as
convenient.
V2.4
Exciting changes in the latest Yellowfin BI version are set to make the
users experience simpler yet more powerful.
|
by: jimdandy |
last post by:
Hi all,
Am looking for some guidance/advice in terms of best practices for
deploying a MS BI project.
We have a relatively large BI system that we need to deploy between
DEV/QA/UAT/PROD and want a simple way to manage this deployment between
environments. The system consists of:
SQL Server 2005 Catabases, tables, views, sprocs,...
|
by: ngocviet |
last post by:
I have a text like this: "Thuyền Và Biển"
How to convert it to: "Thuyền Và Biển"
Please help!
| |
by: YellowFin |
last post by:
Yellowfin International today announced that Yellowfin has joined
IBM's Partner Program, and that the Yellowfin BI Suite are now
validated on IBM's popular DB2 9 database. This partnership opens new
markets for Yellowfin, and provides IBM and its partners with an
attractive opportunity to expand its presence in international markets
and in...
|
by: rinmanb70 |
last post by:
I use a db for keeping up with my checkbook and I'm having trouble
setting up a new functionality. I get paid every two weeks on Friday,
and I need a report to figure my balance that includes only
transactions that are dated before the date of my next payday. Any
transactions that are dated on or after my next payday (ones I have
scheduled...
|
by: YellowFin Announcements |
last post by:
Yellowfin, Powered by J2EE, Jasper, BIRT, Spring, jfreeChart
Advanta releases ATLAS BI using Yellowfin Business Intelligence
3rd of August, 2007 - Advanta Software, specialist software solutions
provider to the 3PL and logistics markets, announced the release of
ATLAS BI, a state of the art business intelligence module as an
addition to...
|
by: sharmajavaforum |
last post by:
Hai,
I have a small task.
I have an .HTML file.
I wanted to convert .HTML file into a plain .txt file.
Means after i convert the file, the .txt file should contain only the text rather
than the HTML tags information.
If you have a solution please guild me.
Bi.
|
by: zyro |
last post by:
Hi,
This is Michael Bowen. I've put together cubegeek.com as a new and
hopefully exciting site for the BI professional to network, share get
information. This is the industry's first portal built from the ground
up to support cross-vendor applications. I'd like you to join us.
We are at a turning point in our industry. The demands are...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |