Could someone give me a hint on what I goofed up? I can't seem to get this
damned thing to work:
public static bool Brighten(Bitmap b, int nBrightness)
{
// GDI+ return format is BGR, NOT RGB.
Rectangle rect = new Rectangle(0,0,b.Width,b.Height);
BitmapData bmData =
b.LockBits(rect,ImageLockMode.ReadWrite,PixelForma t.Undefined); //This is
the problem
int stride = bmData.Stride;
System.IntPtr Scan0 = bmData.Scan0;
unsafe
{
int nVal;
byte * p = (byte *)(void *)Scan0;
int nOffset = stride - b.Width*3;
int nWidth = b.Width * 3;
for(int y=0;y<b.Height;++y)
{
for (int x = 0; x < nWidth; ++x)
{
nVal = (int) (p[0] + nBrightness);
if (nVal < 0) nVal = 0;
if (nVal > 255) nVal = 255;
p[0] = (byte)nVal;
++p;
}
p += nOffset;
}
}
b.UnlockBits(bmData);
return true;
}
Here's the error I get at the Line above (BitmapData bmData ......)
"Additional information: Invalid parameter used."
I can't figure this one out.
Thank in advance,
JLW 1 1155
I found my problem, GDI is saving the image in 24bpp, and the origional
program is saving it as 8bpp, so I need to modify this sucker to save a 8bpp
jpeg.
Sigh
JLW
"JLW" <as***@someplace.com> wrote in message
news:e0**************@TK2MSFTNGP09.phx.gbl... Could someone give me a hint on what I goofed up? I can't seem to get
this damned thing to work:
public static bool Brighten(Bitmap b, int nBrightness) { // GDI+ return format is BGR, NOT RGB. Rectangle rect = new Rectangle(0,0,b.Width,b.Height); BitmapData bmData = b.LockBits(rect,ImageLockMode.ReadWrite,PixelForma t.Undefined); //This is the problem int stride = bmData.Stride; System.IntPtr Scan0 = bmData.Scan0; unsafe { int nVal; byte * p = (byte *)(void *)Scan0; int nOffset = stride - b.Width*3; int nWidth = b.Width * 3; for(int y=0;y<b.Height;++y) { for (int x = 0; x < nWidth; ++x) { nVal = (int) (p[0] + nBrightness); if (nVal < 0) nVal = 0; if (nVal > 255) nVal = 255; p[0] = (byte)nVal; ++p; } p += nOffset; } } b.UnlockBits(bmData); return true; }
Here's the error I get at the Line above (BitmapData bmData ......) "Additional information: Invalid parameter used."
I can't figure this one out.
Thank in advance, JLW
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mike Henley |
last post by:
I first came across rebol a while ago; it seemed interesting but then
i was put off by its proprietary nature, although the core of the
language is a free download.
Recently however, i can't...
|
by: E. Robert Tisdale |
last post by:
What makes a good C/C++ programmer?
Would you be surprised if I told you that
it has almost nothing to do with your knowledge of C or C++?
There isn't much difference in productivity, for...
|
by: typingcat |
last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so
on. I've tried many PHP IDEs today, but almost non of them supported
Unicode (UTF-8) file.
I've found that the only Unicode...
|
by: Madhur |
last post by:
Hello
what about this nice way to open a file in single line rather than using
if and else.
#include<stdio.h>
void main()
{
FILE *nd;
clrscr();...
|
by: Pyenos |
last post by:
import cPickle, shelve
could someone tell me what things are wrong with my code?
class progress:
PROGRESS_TABLE_ACTIONS=
DEFAULT_PROGRESS_DATA_FILE="progress_data"
PROGRESS_OUTCOMES=
|
by: Siong.Ong |
last post by:
Dear all,
my PHP aims to update a MySQL database by selecting record
one by one and modify then save.
Here are my PHP, but I found that it doesnt work as it supposed to be,
for example, when...
|
by: Tubular Technician |
last post by:
Hello, World!
Reading this group for some time I came to the conclusion that
people here are split into several fractions regarding size_t,
including, but not limited to,
* size_t is the...
|
by: Daniel.C |
last post by:
Hello.
I just copied this code from my book with no modification :
#include <stdio.h>
/* count characters in input; 1st version */
main()
{
long nc;
nc = 0;
|
by: MU |
last post by:
Hello
I have some code that sets a dropdownlist control with a parameter
from the querystring. However, when the querystring is empty, I get
an error.
Here is my code:
Protected Sub...
|
by: mingke |
last post by:
Hi...
So I have problem with my if condition..I don't know what's wrong but it keeps resulting the wrong answer....
So here's the part of my code I have problem with:
for (i=0; i<size2;...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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: 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 project—planning, coding, testing,...
|
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...
| |