473,394 Members | 2,031 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

I want to edit byte data from a .png file - increase byte value

If I open a .png file either by
Dim BitmapImage As New Bitmap(filename)
OR
ByteArray = My.Computer.FileSystem.ReadAllBytes(filename)

I want to either edit byte values (one by one)
or copy data, byte by byte, in such a way that I can edit values during copy

I can then save file
BitmapImage.Save("D:\Test.png", Imaging.ImageFormat.Png)
##### Not sure how to save a ByteArray
Oct 15 '16 #1

✓ answered by IronRazer

Well, it depends on what exactly you want to change in the bytes of the image and how large the image is that will determine the best way to go about this.

If you just want to adjust the ARGB values to change the colors or transparency of a large png image like 256x256 or larger, then i suggest using the Bitmap.LockBits method at the link below. LockBits is very quick at processing large images. There is an example there to show a basic usage.
https://msdn.microsoft.com/en-us/lib...code-snippet-1

If you want to adjust the colors of smaller images, then you could use the Bitmap.GetPixel and Bitmap.SetPixel methods at the links below to read the Color of each pixel, and set the color of each pixel. These methods are slower than Lockbits which is why i only recommend using them on small images. Again, there are examples of their usage at the links.
https://msdn.microsoft.com/en-us/lib...vs.110%29.aspx
https://msdn.microsoft.com/en-us/lib...vs.110%29.aspx

Using the File.ReadAllBytes method to read the bytes of the image into a Byte array, adjusting the bytes, and then saving the Byte array back to the hard drive using the File.WriteAllBytes method would be pretty fast too.

However, you would need to understand how the bytes are arranged in the file so that you know what bytes you want to change. Reading the bytes like this will include the file header, image data, and other bytes such as the file ending byte. You can read the link below to read how the bytes of a Png file can be arranged.
https://en.wikipedia.org/wiki/Portable_Network_Graphics

Here are the msdn links for the File.ReadAllBytes and File.WriteAllBytes methods.
https://msdn.microsoft.com/en-us/lib...vs.110%29.aspx
https://msdn.microsoft.com/en-us/lib...vs.110%29.aspx

4 1722
IronRazer
83 64KB
Well, it depends on what exactly you want to change in the bytes of the image and how large the image is that will determine the best way to go about this.

If you just want to adjust the ARGB values to change the colors or transparency of a large png image like 256x256 or larger, then i suggest using the Bitmap.LockBits method at the link below. LockBits is very quick at processing large images. There is an example there to show a basic usage.
https://msdn.microsoft.com/en-us/lib...code-snippet-1

If you want to adjust the colors of smaller images, then you could use the Bitmap.GetPixel and Bitmap.SetPixel methods at the links below to read the Color of each pixel, and set the color of each pixel. These methods are slower than Lockbits which is why i only recommend using them on small images. Again, there are examples of their usage at the links.
https://msdn.microsoft.com/en-us/lib...vs.110%29.aspx
https://msdn.microsoft.com/en-us/lib...vs.110%29.aspx

Using the File.ReadAllBytes method to read the bytes of the image into a Byte array, adjusting the bytes, and then saving the Byte array back to the hard drive using the File.WriteAllBytes method would be pretty fast too.

However, you would need to understand how the bytes are arranged in the file so that you know what bytes you want to change. Reading the bytes like this will include the file header, image data, and other bytes such as the file ending byte. You can read the link below to read how the bytes of a Png file can be arranged.
https://en.wikipedia.org/wiki/Portable_Network_Graphics

Here are the msdn links for the File.ReadAllBytes and File.WriteAllBytes methods.
https://msdn.microsoft.com/en-us/lib...vs.110%29.aspx
https://msdn.microsoft.com/en-us/lib...vs.110%29.aspx
Oct 16 '16 #2
Thanks for your reply...

I looking at the links you've suggested - It'll take my awhile to play with the code.

To be more honest. I have a working steganography program which works perfectly on .bmp files. But who EVER sends pics in an email in bmp format?

So I am trying to adapt the working concept to use with png files.
Since png use a compression method that I do not understand I thought to read the picture data into an array so that I can access and modify the data as I did the bmp file.
Obviously, to reliably encode a message, I must be able to accurately set the individual RGB values and then resave as a new png file.
I think I can use the methods you outline - unless now that you know what I'm trying to do, you can suggest a better approach
Oct 16 '16 #3
IronRazer
83 64KB
I really have no use for Stenography, i don`t really have anything to hide from anyone. 8)

However, a person i know from the Msdn VB.Net forum has posted an example of using an LSB (least significant bit) Stenography algorithm at the link below. I don`t approve of some of the methods he used in the example code but, it does work. Maybe it will give you some ideas.

https://social.msdn.microsoft.com/Fo...orum=vbgeneral

You can load a .Jpg, .Bmp, or .Png image, encode the image and text, then save them as .Png images.
Oct 16 '16 #4
thanks again.. I'll look at the example.
Cheers
Peter
Oct 16 '16 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Auday Alwash | last post by:
Hi, A month ago, we were running out of disk space on a drive that stores the data file for a SQL Server 7 database. So I added a new drive and created a new data file on the primary filegroup...
1
by: Marquee | last post by:
Hello, This is my first program c#, my background is c++. One thing I would like to do is put binary data (e.g. a record from disk, or network packet) in a struct. In C++ I would create the...
4
by: Gidi | last post by:
Hi, i have a byte array, and i'm writing it to a file, i want to start a new line, how can i do it? (like WriteLine in StreamWriter) I'm using FileStream: FileStream fs = new...
12
by: Steven Bethard | last post by:
Ok, so I have a module that is basically a Python wrapper around a big lookup table stored in a text file. The module needs to provide a few functions:: get_stem(word, pos, default=None)...
2
by: News East | last post by:
I have an existing SQL 7 server named HHARBR. HHARBR has a database named SPR with a table named "reportname" in it, the table has the name HHARBR embedded the table data. I migrated the HHARBR...
4
jeffbroodwar
by: jeffbroodwar | last post by:
Hello, i have a problem about assigning a char value to a byte... please check the code below : ======================================================== Scenario # 1 : This code doesn't work : ...
5
by: deppeler | last post by:
Can someone look at this for me: I am trying to set up a script to edit an item in a flat file DB but I don't seem to be getting the data to the Photoedit script. It seems to be reading the 1st line...
7
by: dana_livni2000 | last post by:
how do i print the acuale byte sequence that represent a vairable (let say a char - i want to see the 8 bits). thanks dana
3
by: ist | last post by:
Hi, I am trying to get (and transfer over ASP.NET) some encrypted data from some MySQL fields. Since the data contains many unicode characters, I tried to get the data as a series of ASCII...
2
by: O.B. | last post by:
When using Marshal to copy data from a byte array to the structure below, only the first byte of the "other" array is getting copied from the original byte array. What do I need to specify to get...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.