如何在wpf + c#中将图像转换为文本和文本到图像#

时间:2022-09-13 09:35:54

I want to develop an appication which can converts image to text format(some Ascii format) and text to image format. I want this because i need to decrease the size of the image file. Any suggestion plz. Thanks in advance, Ibrahim.

我想开发一个应用程序,可以将图像转换为文本格式(一些Ascii格式)和文本到图像格式。我想要这个因为我需要减小图像文件的大小。任何建议PLZ。谢谢,易卜拉欣。

3 个解决方案

#1


2  

Actually, when you convert an image to text, you will increase the size, not decrease it! The reason for this is simple: if you store an image in binary format, you'll have the full value spectrum of a byte available to store your image in. When you use a text format, the value spectrum is limited to 26 uppercase characters, 26 lowercase characters, 10 digits and a bunch of special characters, but it will be far less than the 256 values that you have in binary mode.

实际上,当您将图像转换为文本时,您将增加大小,而不是减少它!原因很简单:如果以二进制格式存储图像,您将拥有可用于存储图像的字节的完整值谱。当您使用文本格式时,值谱限制为26个大写字符,26个小写字符,10个数字和一堆特殊字符,但它远小于二进制模式下的256个值。

Converting binary to text and back again is often done by using UUEncoding. It's an encoding system that still manages to generate a reasonable small text-stream and it's a good standard that is used in many places already, with plenty of libraries for dozens of languages. UUEncoding uses 64 different characters, thus every 3 bytes of binary data gets translated to 4 characters. (Increase with one-third.)

通常使用UUEncoding将二进制文件转换为文本并再次返回。它是一个编码系统,仍然可以生成一个合理的小文本流,这是一个很好的标准,已经在很多地方使用,有大量的库可供数十种语言使用。 UUEncoding使用64个不同的字符,因此每3个字节的二进制数据被转换为4个字符。 (增加三分之一。)

To make your binary images smaller, use a different image format like JPG or PNG. JPG is advised for photo's where some loss of quality isn't a big problem. PNG is often used when image quality must be high or when your image has some transparent parts. If your original image is a BMP then converting it to PNG and then UUEncoding the PNG file will result in a considerable shrinking in filesize. (But that's because of the PNG compression, not the encoding.)

要缩小二进制图像,请使用不同的图像格式,如JPG或PNG。建议JPG拍摄照片,其中一些质量损失不是一个大问题。当图像质量必须很高或图像有一些透明部分时,通常会使用PNG。如果您的原始图像是BMP然后将其转换为PNG,然后对PNG文件进行UUEncoding将导致文件大小的相当大的缩小。 (但这是因为PNG压缩,而不是编码。)

#2


1  

When you say that you wish to reduce the size of the image do you mean that you wish to reduce the image file size or reduce the dimensions that it takes up on the display?

如果您希望减小图像的大小,是否意味着您希望缩小图像文件大小或减小显示屏上占用的尺寸?

If you wish to reduce the file size then converting it to an ASCII file won't help. Instead you need to compress it. (Say by converting bitmap to jpeg).

如果您希望减小文件大小,那么将其转换为ASCII文件将无济于事。相反,你需要压缩它。 (通过将位图转换为jpeg来说)。

Edit

Based on your comment. I would suggest that you look at JpegBitmapDecoder and JpegBitmapEncoder classes for decoding the jpeg file into a bitmap and then encoding the bitmap with different valkues from the start.

根据你的评论。我建议您查看JpegBitmapDecoder和JpegBitmapEncoder类,将jpeg文件解码为位图,然后从头开始使用不同的valkues编码位图。

Microsoft info

Also look here for more information including how to override the default compression of 75% More info

另请查看此处了解更多信息,包括如何覆盖75%的默认压缩更多信息

#3


0  

If you are wanting to recognise letters in your image and convert that to text, how about one of the OCR libraries?

如果您想要识别图像中的字母并将其转换为文本,那么其中一个OCR库怎么样?

#1


2  

Actually, when you convert an image to text, you will increase the size, not decrease it! The reason for this is simple: if you store an image in binary format, you'll have the full value spectrum of a byte available to store your image in. When you use a text format, the value spectrum is limited to 26 uppercase characters, 26 lowercase characters, 10 digits and a bunch of special characters, but it will be far less than the 256 values that you have in binary mode.

实际上,当您将图像转换为文本时,您将增加大小,而不是减少它!原因很简单:如果以二进制格式存储图像,您将拥有可用于存储图像的字节的完整值谱。当您使用文本格式时,值谱限制为26个大写字符,26个小写字符,10个数字和一堆特殊字符,但它远小于二进制模式下的256个值。

Converting binary to text and back again is often done by using UUEncoding. It's an encoding system that still manages to generate a reasonable small text-stream and it's a good standard that is used in many places already, with plenty of libraries for dozens of languages. UUEncoding uses 64 different characters, thus every 3 bytes of binary data gets translated to 4 characters. (Increase with one-third.)

通常使用UUEncoding将二进制文件转换为文本并再次返回。它是一个编码系统,仍然可以生成一个合理的小文本流,这是一个很好的标准,已经在很多地方使用,有大量的库可供数十种语言使用。 UUEncoding使用64个不同的字符,因此每3个字节的二进制数据被转换为4个字符。 (增加三分之一。)

To make your binary images smaller, use a different image format like JPG or PNG. JPG is advised for photo's where some loss of quality isn't a big problem. PNG is often used when image quality must be high or when your image has some transparent parts. If your original image is a BMP then converting it to PNG and then UUEncoding the PNG file will result in a considerable shrinking in filesize. (But that's because of the PNG compression, not the encoding.)

要缩小二进制图像,请使用不同的图像格式,如JPG或PNG。建议JPG拍摄照片,其中一些质量损失不是一个大问题。当图像质量必须很高或图像有一些透明部分时,通常会使用PNG。如果您的原始图像是BMP然后将其转换为PNG,然后对PNG文件进行UUEncoding将导致文件大小的相当大的缩小。 (但这是因为PNG压缩,而不是编码。)

#2


1  

When you say that you wish to reduce the size of the image do you mean that you wish to reduce the image file size or reduce the dimensions that it takes up on the display?

如果您希望减小图像的大小,是否意味着您希望缩小图像文件大小或减小显示屏上占用的尺寸?

If you wish to reduce the file size then converting it to an ASCII file won't help. Instead you need to compress it. (Say by converting bitmap to jpeg).

如果您希望减小文件大小,那么将其转换为ASCII文件将无济于事。相反,你需要压缩它。 (通过将位图转换为jpeg来说)。

Edit

Based on your comment. I would suggest that you look at JpegBitmapDecoder and JpegBitmapEncoder classes for decoding the jpeg file into a bitmap and then encoding the bitmap with different valkues from the start.

根据你的评论。我建议您查看JpegBitmapDecoder和JpegBitmapEncoder类,将jpeg文件解码为位图,然后从头开始使用不同的valkues编码位图。

Microsoft info

Also look here for more information including how to override the default compression of 75% More info

另请查看此处了解更多信息,包括如何覆盖75%的默认压缩更多信息

#3


0  

If you are wanting to recognise letters in your image and convert that to text, how about one of the OCR libraries?

如果您想要识别图像中的字母并将其转换为文本,那么其中一个OCR库怎么样?