(Link to AcmlmWiki) Offline: thank ||bass
Register | Login
Views: 13,040,846
Main | Memberlist | Active users | Calendar | Chat | Online users
Ranks | FAQ | ACS | Stats | Color Chart | Search | Photo album
04-23-23 03:03 AM
0 users currently in Programming.
Acmlm's Board - I3 Archive - Programming - .NET Bitmap Problems New poll | |
Add to favorites | Next newer thread | Next older thread
User Post
Dan

Purple Leever


 





Since: 11-18-05

Last post: 5916 days
Last view: 5907 days
Posted on 02-15-06 10:59 AM Link | Quote
I have been writing some code to draw NES tiles using this tutorial here as a template. I think I have it pretty much coded, but one major problem exists. The bitmap that is produced comes out extremely blurry. Presumably, I'm doing something not quite right, or haven't set some obscure property. I would post a screenshot but I'm at work and have no access to a webserver or any such thing to upload it to. The source should be in the attachment hopefully. Or not. Screw it, here's the function:

public void DrawTile(int pX, int pY)

{
Point pixsize = PixelSize;
LockBitmap();
byte Temp2;
byte Temp3;
byte Temp4;
int psize= 7;
for (int y=0;y<=psize; y++)
{
for (int x=0;x<=psize;x++)
{
Temp2 = 0;
Temp3 = 0;
Temp2 = (byte) (((tiledata2[y] & (0x80 >> x)) >> (psize -x)));
Temp3 = (byte) ((tiledata2[y + 8] & (0x80 >> x)) >> (psize -x));
Temp4 = (byte) ((Temp2 << 1) + Temp3);
PixelData* pPixel = PixelAt((pX + x),(pY + y));
if (Temp4 == 1)
{
pPixel->red = (byte) 0xff;
pPixel->green = (byte) 0xff;
pPixel->blue = (byte) 0xff;
}
else if (Temp4 == 2)
{
pPixel->red = (byte) 0x00;
pPixel->green = (byte) 0xff;
pPixel->blue = (byte) 0x00;
}
else if (Temp4 == 0)
{
pPixel->red = (byte) 0xff;
pPixel->green = (byte) 0x00;
pPixel->blue = (byte) 0x00;
}
else if (Temp4 == 3)
{
pPixel->red = (byte) 0x0;
pPixel->green = (byte) 0x0;
pPixel->blue = (byte) 0x0;
}
}
}
UnlockBitmap();
}



(edited by Dan on 02-15-06 10:00 AM)
Guy Perfect









Since: 11-18-05

Last post: 5909 days
Last view: 5907 days
Posted on 02-15-06 11:02 AM Link | Quote
You can upload images as attachments to this forum. New feature. And OGG files, which I think is durn awexome.

Post a screenie of your problem. Actually seeing graphical anomalies is far more effective than looking at code and assuming a problem exists.
Dan

Purple Leever


 





Since: 11-18-05

Last post: 5916 days
Last view: 5907 days
Posted on 02-15-06 11:06 AM Link | Quote
Hopefully this works through the firewall.

Edit- Nope. Doesn't work.


(edited by Dan on 02-15-06 10:08 AM)
FreeDOS +

Giant Red Koopa
Legion: freedos = fritos








Since: 11-17-05
From: Seattle

Last post: 5907 days
Last view: 5907 days
Posted on 02-15-06 02:47 PM Link | Quote
Try forwarding/unblocking port 80, it's probably the one that is stopping you from uploading files.
Disch

Red Cheep-cheep


 





Since: 12-10-05

Last post: 6187 days
Last view: 6187 days
Posted on 02-15-06 03:28 PM Link | Quote
This is probably of no/little use to you -- but I was bored and decided to clean that up a bit:




public void DrawTile(int pX, int pY)
{
LockBitmap();

byte a, b;

PixelData pal[4];
pal[0].red = 0xFF; pal[0].green = 0x00; pal[0].blue = 0x00;
pal[1].red = 0x00; pal[1].green = 0xFF; pal[1].blue = 0x00;
pal[2].red = 0xFF; pal[2].green = 0xFF; pal[2].blue = 0xFF;
pal[3].red = 0x00; pal[3].green = 0x00; pal[3].blue = 0x00;

for(int y=0; y < 8; y++)
{
PixelData* pix = PixelAt(pX,pY + y);

a = tiledata2[y];
b = tiledata2[y + 8];

pix[0] = pal[((a >> 7) & 1) | ((b >> 6) & 2)];
pix[1] = pal[((a >> 6) & 1) | ((b >> 5) & 2)];
pix[2] = pal[((a >> 5) & 1) | ((b >> 4) & 2)];
pix[3] = pal[((a >> 4) & 1) | ((b >> 3) & 2)];
pix[4] = pal[((a >> 3) & 1) | ((b >> 2) & 2)];
pix[5] = pal[((a >> 2) & 1) | ((b >> 1) & 2)];
pix[6] = pal[((a >> 1) & 1) | ((b ) & 2)];
pix[7] = pal[((a ) & 1) | ((b << 1) & 2)];
}

UnlockBitmap();
}



One of the things that stood out to me in your original code was you had your bitplanes backwards (the second bitplane is the high one -- the one you multiply by 2... not the first bitplane). But of course this has nothing to do with your question.
Dan

Purple Leever


 





Since: 11-18-05

Last post: 5916 days
Last view: 5907 days
Posted on 02-15-06 06:45 PM Link | Quote
Okay, this is pretty much my problem here:



And here's the source-code.
Guy Perfect









Since: 11-18-05

Last post: 5909 days
Last view: 5907 days
Posted on 02-15-06 06:58 PM Link | Quote
It simply looks stretched to me. I don't know how things are in .NET, but in VB, you have to set the Form's ScaleMode property to Pixels to get stuff to look right.
Euclid



 





Since: 11-17-05
From: Australia
hmm...

Last post: 5913 days
Last view: 5907 days
Posted on 02-15-06 08:35 PM Link | Quote
Code looks ok to me...

it's sizeMode in .net, check that pictureBox's properties, Normal seems to work for me.
||bass
Administrator








Since: 11-17-05
From: Salem, Connecticut

Last post: 5908 days
Last view: 5907 days
Posted on 02-15-06 09:13 PM Link | Quote
Originally posted by BGNG
It simply looks stretched to me. I don't know how things are in .NET, but in VB, you have to set the Form's ScaleMode property to Pixels to get stuff to look right.
I'm pretty sure that ScaleMode is in pixels by default for all projects in .NET languages.
sloat



 





Since: 11-18-05
From: Delaware, US

Last post: 6010 days
Last view: 6010 days
Posted on 02-16-06 12:56 AM Link | Quote
I'll throw my possible solution in to the ring...

set the graphics object (whatever you're drawing to) .SmoothingMode property to System.Drawing.Drawing2D.SmoothingMode.None
Dan

Purple Leever


 





Since: 11-18-05

Last post: 5916 days
Last view: 5907 days
Posted on 02-16-06 05:02 AM Link | Quote
Tried those solutions, but none of them seem to correct the problem. I don't believe the picturebox control is the problem, as when I save the bitmap object to disk, the bitmap has the problem also.

Does anyone have any working .NET source code that does pixel access in a fast manner?
Euclid



 





Since: 11-17-05
From: Australia
hmm...

Last post: 5913 days
Last view: 5907 days
Posted on 02-16-06 07:07 AM Link | Quote
Have you tried looking into BitmapData and Bitmap.lockBits? They allow you to pretty much write binary for the bitmap image.

That's what i'm using anyway, here's a quick slab of code to draw stuff...


/* 4bits per pixel, snes format */
public System.Drawing.Bitmap bm = new System.Drawing.Bitmap(8,8,System.Drawing.Imaging.PixelFormat.Format4bppIndexed);

/* take metatable data */
public tile8x8(byte[] data)
{
/* put 8x8tile data into bitmap */
BitmapData bmd = bm.LockBits(new Rectangle(0,0,8,8),ImageLockMode.WriteOnly , bm.PixelFormat);
unsafe
{
for(int y=0; y<8; y++)
{
byte* row=(byte *)bmd.Scan0+(y*bmd.Stride);
for(int x=0; x<4; x++)
{
row[x]=Convert.ToByte((data[palCount] << 4) + data[palCount+1]);
palCount+=2;
}
}
}
bm.UnlockBits(bmd);
}
Dan

Purple Leever


 





Since: 11-18-05

Last post: 5916 days
Last view: 5907 days
Posted on 02-16-06 07:38 AM Link | Quote
Now, I feel a wee bit dumb. I was looking at the image zoomed in Windows Picture and Fax Viewer, and it appeared like above also. However, when I opened the image up in Paint, it appeared fine. So it must be something to do with the actual picturebox control. Is there anyway I can disable this rather annoying behaviour and have it zoom normally?

I tried the SmoothingMode = none thing, but I don't even use a graphics object to paint the bitmap onto the Picturebox (I just set the Bitmap property of the control to the Bitmap object). I'm not entirely sure if this is the best way, or even how to work with the Paint events of the Picturebox control.

Edit - I fixed it thankfully. I now use a bitmap of form-level scope, and on every paint operation on the Picturebox, I draw it to the Picturebox. I also set the InterpolationMode to Drawing2D.InterpolationMode.NearestNeighbor, which fixed the weird scaling problem.

Thanks for all the help guys.


(edited by Dan on 02-16-06 07:08 AM)
Add to favorites | Next newer thread | Next older thread
Acmlm's Board - I3 Archive - Programming - .NET Bitmap Problems |


ABII

Acmlmboard 1.92.999, 9/17/2006
©2000-2006 Acmlm, Emuz, Blades, Xkeeper

Page rendered in 0.023 seconds; used 407.73 kB (max 506.91 kB)