Image to Text C#
Image to Text C#
Is it possible to convert an image to a text document with magick.net? I can convert an image to text by using imagemagick IMDisplay and it outputs the image into a text file and looks like this:
# ImageMagick pixel enumeration: 1057,314,65535,srgb
0,0: (33410,1799,6939) #82071B srgb(130,7,27)
1,0: (33924,1285,6168) #840518 srgb(132,5,24)
2,0: (34438,1285,6425) #860519 srgb(134,5,25)
3,0: (34181,1028,6168) #850418 srgb(133,4,24)
4,0: (34181,1028,6168) #850418 srgb(133,4,24)
5,0: (34181,1028,5654) #850416 srgb(133,4,22)
6,0: (34181,1028,5654) #850416 srgb(133,4,22)
7,0: (34695,514,5397) #870215 srgb(135,2,21)
If this is possible are there any examples available?
Thanks,
Robert
# ImageMagick pixel enumeration: 1057,314,65535,srgb
0,0: (33410,1799,6939) #82071B srgb(130,7,27)
1,0: (33924,1285,6168) #840518 srgb(132,5,24)
2,0: (34438,1285,6425) #860519 srgb(134,5,25)
3,0: (34181,1028,6168) #850418 srgb(133,4,24)
4,0: (34181,1028,6168) #850418 srgb(133,4,24)
5,0: (34181,1028,5654) #850416 srgb(133,4,22)
6,0: (34181,1028,5654) #850416 srgb(133,4,22)
7,0: (34695,514,5397) #870215 srgb(135,2,21)
If this is possible are there any examples available?
Thanks,
Robert
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Image to Text C#
Just write the image to a "txt:" format output.
snibgo's IM pages: im.snibgo.com
Re: Image to Text C#
Just read the file using read?
using (MagickImage image = new MagickImage("Image.jpg"))
{
image.Write("NewText.txt");
}
I am getting an error message.
using (MagickImage image = new MagickImage("Image.jpg"))
{
image.Write("NewText.txt");
}
I am getting an error message.
Re: Image to Text C#
Still does not work. That to me looks like it just renames the file and puts txt: on the front of it. I also added this:
image.Format = MagickFormat.Txt;
and it did not make any difference.
image.Format = MagickFormat.Txt;
and it did not make any difference.
Re: Image to Text C#
private void btnDecode_Click(object sender, EventArgs e)
{
using (MagickImage image = new MagickImage("image.png"))
{
image.Format = MagickFormat.Txt;
image.Write("NewText.txt");
}
}
just doing it on a button click.
{
using (MagickImage image = new MagickImage("image.png"))
{
image.Format = MagickFormat.Txt;
image.Write("NewText.txt");
}
}
just doing it on a button click.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Image to Text C#
I don't use C# so I can't test it. Perhaps this isn't implemented in the C# interface. Sorry, I don't know what to suggest.
snibgo's IM pages: im.snibgo.com
Re: Image to Text C#
What do you use?
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Image to Text C#
I use the command-line interface, or C mostly at the MagickCore level but sometimes MagickWand.
For example, MagickCore:
This writes the text you want, when argv[2] is "x.txt" or "txt:x.txt".
For example, MagickCore:
Code: Select all
(void) strcpy(thumbnails->filename,argv[2]);
WriteImage(image_info,thumbnails);
snibgo's IM pages: im.snibgo.com
Re: Image to Text C#
Are you using the latest version of Magick.NET? I get a correct file with the following code:
Code: Select all
using (var image = new MagickImage("logo:"))
{
image.Write("logo.txt");
}
Re: Image to Text C#
Awesome guys thanks for the help.
Re: Image to Text C#
Dlemstra,
Would you have any idea as to why my program would crash as soon as I try to execute MagickImage code.
This is the process I followed:
Using visual studio 2013.
.Nets are installed up to 4.5.1.
Installed Magick.NET-Q16-x64.
In project set using ImageMagick;
Put this code in a button.
using (MagickImage image = new MagickImage(@"C:\Images\TestImage.jpg"))
{
image.Format = MagickFormat.Txt;
image.Write(@"C:\Images\TestImage.txt");
}
Then I get this error message:
Additional information: Could not load file or assembly 'Magick.NET-Q16-x64, Version=7.0.0.0, Culture=neutral, PublicKeyToken=2004825badfa91ec' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Then I installed this.
installed Magick.NET.Core-Q16.Native
I am still getting the same error.
Can you see anything that I am doing wrong?
Thanks,
Robert
Would you have any idea as to why my program would crash as soon as I try to execute MagickImage code.
This is the process I followed:
Using visual studio 2013.
.Nets are installed up to 4.5.1.
Installed Magick.NET-Q16-x64.
In project set using ImageMagick;
Put this code in a button.
using (MagickImage image = new MagickImage(@"C:\Images\TestImage.jpg"))
{
image.Format = MagickFormat.Txt;
image.Write(@"C:\Images\TestImage.txt");
}
Then I get this error message:
Additional information: Could not load file or assembly 'Magick.NET-Q16-x64, Version=7.0.0.0, Culture=neutral, PublicKeyToken=2004825badfa91ec' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Then I installed this.
installed Magick.NET.Core-Q16.Native
I am still getting the same error.
Can you see anything that I am doing wrong?
Thanks,
Robert
Re: Image to Text C#
Well I am lucky and it appears to be fixed!
I uninstalled both 64 core and native and used the anycpu and it works now.
THANKS FOR THE HELP!
Have a good one
I uninstalled both 64 core and native and used the anycpu and it works now.
THANKS FOR THE HELP!
Have a good one
Re: Image to Text C#
It looks like your application is 32 bit. Your error messages means that you try to load a 64-bit library in a 32-bit application. Switching to AnyCPU fixed that. And you don't need to use the .NET Core version of Magick.NET.