Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Help! Read the image "StreamReader"
However, the image as a whole is pushed aside and outputted.

What should I do?


This is the code I used.



byte[] Buf = rdr.ReadBytes(FILESIZE - START);
Array.Reverse(Buf);
using (FileStream fileStream = File.Open("Convert.bmp", FileMode.Create))
{
   using (BinaryWriter binaryWriter = new BinaryWriter((Stream)fileStream))
{
    binaryWriter.Write(Buf);
    binaryWriter.Close();
}

The link below is a link to the original and the converted image.

original

converted

What I have tried:

search and search and.. search ...
Posted
Updated 12-Mar-21 22:41pm
Comments
Dave Kreskowiak 13-Mar-21 1:57am    
What are you really trying to do?

Just writing the bytes for an image in reverse order does not do anything useful to the image.
H13m5 13-Mar-21 1:59am    
If you look at the image, the two sides are occupied consistently, one line at a time. What I want to do is to reverse the normal image.
Dave Kreskowiak 13-Mar-21 2:02am    
You're going to have to explain what you mean by "reverse". Is it inverting the color palette? Flipping the image right to left? Top to bottom? What?

The images are too small for me to see.
H13m5 13-Mar-21 2:06am    
The picture is too small. I'm sorry.

here big size image :

VIEW IMAGE


First, the image file consists of BMP extensions.

When you open the image with the "HXD" program to verify, you can see information such as the header value of the image and the size of the file, such as "X Coordinate" / "Y Coordinate" / "Palette".

What I want to do here is to flip the hex code and print out the image.

use binarywriter

You can't just read an image file as bytes, reverse the bytes and write it back to an imagefile, even BMP images contain more than just the "raw" pixel data: BMP file format - Wikipedia[^] So that your image just comes over as "pushed to one side" is pretty lucky stuff!

If you want to "flip" an an image horizontally or vertically, you have to read it into an Image class instance, flip the Image, and then save the new version.
This may help: Image.RotateFlip(RotateFlipType) Method (System.Drawing) | Microsoft Docs[^]
 
Share this answer
 
Comments
H13m5 13-Mar-21 2:12am    
Thank you for your kind reply,
But what I want is a byte that's the size of the image when it's flipped.

I want to reconfigure this byte as BinaryWriter.
OriginalGriff 13-Mar-21 2:36am    
Do you want to describe that again, in English this time?

That makes no sense whatsoever!
H13m5 13-Mar-21 2:54am    
Sorry, I'm not good at English. I am not a person who lives in an English-speaking country.

Here's what I'm going to do.

1. Get hexcode value of BMP image.
2. Turn this upside down in reverse order.
3. Paste the reversed hexcode values into another image.

The third one doesn't matter if you copy and paste it manually.

The data in the BMP image file must be in reverse order for the obtained hexcode value to be used.

VIEW IMAGE
If you look at the image in the link above, there is an image converted from the original image.

The difference between the two images, the vertical line of the right image, was pushed one space to the right.
OriginalGriff 13-Mar-21 3:41am    
Read what I said.
You can't just invert the byte order, the file format isn't like that.
Read what I said, and follow the links.
H13m5 13-Mar-21 4:15am    
Okay, I'll try that.

Thank you for your time.
You might also be interested in this CodeProject article: Fundamentals of Image Processing - behind the scenes[^]
 
Share this answer
 
Comments
H13m5 14-Mar-21 8:18am    
Thank you for your answer.

But I don't think this is the way I want it.
RickZeeland 14-Mar-21 8:43am    
No, using a library is probably overkill for what you want, only if you could use the extra functionality it would be of interest I think.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900