|
I'm relatively new to GDI+. I'm trying to create a texture brush from a bitmap stored in a resource file in a Visual C++ project. However, the image comes out much too small when I fill a shape with the texture brush.
The bitmap I'm using is 32x32 and is monochrome.
Bitmap bmpPattern(AfxGetResourceHandle(), (WCHAR*)lpszBmpName);<br />
TextureBrush *pBrush = new TextureBrush(&bmpPattern);
If I want to see the image as it's drawn when using GDI's CreateDIBPatternBrushPt, I have to do a scale tranform on the texture brush by about 10 times.
I'm not sure what's causing this, but I'm guessing it's something to do with the page units. Any clues? Thanks in advance!
|
|
|
|
|
Are you using GDI+ or GDI to draw a filled shape.
Taking from your GDI+ code, I did this in a CWnd-derived OnPaint()...
// IDB_BITMAP4 is a 32x32 monochrome bitmap resource, black 2-pixel-wide border filled with
// dithered pixels (from a color in the monochrome bitmap editor palette).
Graphics DstGraphics(*this);
Bitmap brushbitmap(AfxGetResourceHandle(), MAKEINTRESOURCE(IDB_BITMAP4));
TextureBrush texturebrush(&brushbitmap, WrapModeTile);
Rect ellipserect(0, 0, 640, 640);
DstGraphics.FillEllipse(&texturebrush, ellipserect);
The bitmap is drawn full size in the ellipse. Do you get the same result?
Mark
"Go that way, really fast. If something gets in your way, turn."
|
|
|
|
|
No, mine is displayed at about 1/10th the size it should be.
I thought that my problem might be that the bitmap was created from a resource file bitmap. So, I tested just creating a bitmap by doing this:
Bitmap bmpTest(32, 32, PixelFormat32bppARGB);<br />
BitmapData bitmapData;<br />
bmpTest.LockBits(&Rect(0, 0, 32, 32),<br />
ImageLockModeRead | ImageLockModeWrite,<br />
PixelFormat32bppARGB,<br />
&bitmapData);<br />
UINT* pixels = (UINT*)bitmapData.Scan0;<br />
<br />
for(UINT row = 0; row < 32; ++row)<br />
for(UINT col = 0; col < 32; ++col)<br />
pixels[row * bitmapData.Stride / 4 + col] = (row == 0 || row == 31 || col == 0 || col == 31) ? 0xFF000000 : 0xFFFFFFFF;<br />
<br />
bmpTest.UnlockBits(&bitmapData);<br />
TextureBrush *pBrush = new TextureBrush(&bmpTest);
But it still displays much too small. I'm thinking maybe it's a problem of page units, but if that's the case, then why do all my ellipses and rectangles show up in the right place, just with their texture-filled insides too small?
|
|
|
|
|
Your code works for me too. I'm not sure what page units you're referring to, but the problem
seems to be in the Graphics object you're drawing to (i haven't seen ay code showing your
Graphics object creation and drawing ).
Maybe try this...
Right before you draw, call DstGraphics.ResetTransform();
"Go that way, really fast. If something gets in your way, turn."
|
|
|
|
|
Ah, very true! I create my graphics object from a handle to a CDC that gets passed down from an OnPaint's CPaintDC.
I tried the reset transform on the graphics object, but no luck. By page units, I mean the SetPageUnit method of the Graphics class.
|
|
|
|
|
If you're using SetPageUnit() then maybe this will be of interest:
Types of Coordinate Systems[^]
"Go that way, really fast. If something gets in your way, turn."
|
|
|
|
|
Hi to All!
I have a problem to catch event from button on webcam using DirectX or WIA.
Any ideas.
|
|
|
|
|
I am thinking of enhancing the 3D display of the scene in my app. Currently I'm using a simple method with OpenGL.
The idea is displaying a scene with a LOT of objects, but there is no need for complex rendering (I mean: no need for extreme realism). I want to be able to change viewpoint, zoom, etc., but it's not a game, so no need for maximum speed.
What are my options ? OpenGL, DirectX ? Maybe WPF ?
Things to consider ?
Thanks in advance.
|
|
|
|
|
BusyDeveloper wrote: Things to consider ?
if your focus is on the "scene" of objects, not on the objects themselves, you might change focus a bit towards a scene-graph. This is not a replacement of OpenGL or DirectX, it is a higher level operation that is simply an organization construct. Objects are placed on the scene-graph and the scene-graph is then rendered via OpenGL or DirectX. There are many scene-graphs available, but if you are using OpenGL already, OpenSceneGraph might be easiest to switch to.
http://www.openscenegraph.com/index.php[^]
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
Dear All
Regards!
I am using OpenGL(CSGL) in C#, i draw a line and now want to zoomin and zoomout it in OpenGL, kindly help me while developing program for Zooming in openGL.
Regards
David
david
|
|
|
|
|
How can i change alpha channel values without rinning Height*width loop
Is there any way that i can drawimage without altering alpha values of background??.
i mean i have two images where bye sequences of pixels will be as follows
22 0
34 0
56 0
255 14
55 0
22 0
44 0
255 10
23 0
37 0
56 0
255 14
51 0
28 0
44 0
255 10
now i want to replace 255 with other values or Replace 0's with values from first column.
|
|
|
|
|
I'm confused. How does a drawimage alter alpha values of a background?
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
If i create the graphics object from a bitmap object which has some alpha values.
Now using this graphics object if i draw some other bitmap on firstbitmap the alpha values are altered i mean they will be set to 255.
|
|
|
|
|
Gotcha.
Since there's only two compositing modes, you may have to loop through and combine the alpha
values the way you want to.
SandipG wrote: now i want to replace 255 with other values or Replace 0's with values from first column.
CompositingModeSourceOver works for the "Replace 0's with values from first column" case but not
for the "replace 255 with other values" case.
Here's some code you can play with to see the compositing results...
Gdiplus::Bitmap Bitmap1(20, 20, PixelFormat32bppARGB);
Gdiplus::Rect rect(0, 0, 20, 20);
Gdiplus::Graphics *pBitmapGraphics1 = Gdiplus::Graphics::FromImage(&Bitmap1);
pBitmapGraphics1->SetCompositingMode(Gdiplus::CompositingModeSourceOver);
Gdiplus::SolidBrush solidbrush(Gdiplus::Color(0xFF,0x00,0xFF,0x00));
Gdiplus::Pen solidpen(Gdiplus::Color(0x40,0xFF,0x00,0x00), 1.0);
pBitmapGraphics1->FillRectangle(&solidbrush, rect);
pBitmapGraphics1->DrawLine(&solidpen, 0, 0, 19, 0);
delete pBitmapGraphics1;
pBitmapGraphics1 = 0;
Gdiplus::BitmapData bitmapData;
Bitmap1.LockBits(&rect, ImageLockModeRead, PixelFormat32bppARGB, &bitmapData);
RGBQUAD *pRGBQuads = (RGBQUAD *)bitmapData.Scan0;
Bitmap1.UnlockBits(&bitmapData);
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I played with it but it works with pens and brushes only.
No change in effect of DrawImage.
|
|
|
|
|
With DrawImage(), on the destination Graphics...
SetCompositingMode(CompositingModeSourceCopy) will cause the drawn image to replace whatever was
in the destination image.
SetCompositingMode(CompositingModeSourceOver) will cause the drawn image to be blended with
whatever was in the destination image (the resulting alpha values are not always set to 255).
You should get the same results as with a pen and a brush. A bitmap filled with values with alpha
set to 0 drawn on an image with alpha set to, say, 0x80, will leave the destination alpha 80.
That matches your replace 0s with the first column alpha value, just like with a brush or pen.
Regardless, I guess my point was that to get the results you want with the alpha channels, I
don't believe the APIs are going to do it.
Even though you were looking to avoid it, LockBits/UnlockBits makes it relatively trivial to loop
through the images and combine them yourself.
Mark
-- modified at 13:09 Monday 25th June, 2007
"Go that way, really fast. If something gets in your way, turn."
|
|
|
|
|
Hi ,
I need a function to warp image .
Warp(HBITMAP,HBITMAP,point1,point2,point3,point4) or
Warp(Byte*,Byte*,inputsize,point1,point2,point3,point4)
this function would tranform image to fit the quadrilateral pointed by four points.
there is artical on codeproject AAform which is really very good but it is very slow.
for me that quadrilateral will always be convex.
Some help in this will be highly appreciated
Thanks in advance.
Sandip.
|
|
|
|
|
There's the old PlgBlt fron GDI:
"The PlgBlt function performs a bit-block transfer of the bits of color data from the specified rectangle in the source device context to the specified parallelogram in the destination device context."
However, it probably doesn't do the anti-aliasing mentioned in the AAForm article.
Have you looked at the GDI+ functions? There looks to be about twenty different 'DrawImage' methods in the Graphics class, as well as a SetSmoothingMode method with a SmoothingModeAntiAlias as an option (although this method may just apply to lines and curves).
|
|
|
|
|
I tried GDI+ DrawImage but it will always fit image in parallelogram where is in my case it always need not be parallelogram.
|
|
|
|
|
I want to know how can i make Intelligent Connectors,like those in MS Visio that connect 2 or more blocks and when the blocks are moved, the connectors position themselves accordingly without interferring with any other block.
Is it possible to make such connectors using VC++? I need this as i have to do a the same for my project.
Pls help
Meenu
|
|
|
|
|
whatitis wrote: Is it possible to make such connectors using VC++?
Yes.
|
|
|
|
|
How....can u explain a bit more..
Regards
|
|
|
|
|
I want to know how can i make Intelliegnt Connectors,like those in MS Visio that connect 2 or more blocks and when the blocks are moved, the connectors position themselves accordingly without interferring with any other block.
Is it possible to make such connectors using VC++? I need this as i have to do a the same for my project.
Pls help
Meenu
|
|
|
|
|
Hi all, I'm having trouble with drawing on a secondary screen. When I use IDirectDrawSurface7::Blt to draw with a window totally inside the primary screen, it works well. However, when I move the window so that it's half on primary screen and half on secondary screen or move the window so that it's inside the secondary screen, this function returns E_NOTIMPL. What should I do to make it works on secondary screen? Please help me!
Thanks.
-- modified at 23:03 Sunday 17th June, 2007
|
|
|
|
|
My application is a scrolling histogram. With each tick of the clock I add another rectangle to the graphicspath and then use TranslateTransform() to scale and "scroll" the data.
Unfortunately this app must run 24/7 for weeks (months?!) at a time so the GraphicsPath gets very big. Does anyone know a way to remove PathPoints from a GraphicsPath? Something better than the following barebones class?
Thanks for having a look.
Public Class SizeLimitedGraphicsPath
Private Gp1 As New GraphicsPath
Private Gp2 As New GraphicsPath
Private ActivePtr As GraphicsPath
Private InActivePtr As GraphicsPath
Private NextActiveGp As Integer
Private _minimumSize As Integer
Public Sub New(ByVal MinimumSize As Integer)
_minimumSize = MinimumSize
ActivePtr = Gp1
InActivePtr = Gp2
NextActiveGp = 2
End Sub
Public Sub AddRectangle(ByVal rect As RectangleF)
Gp1.AddRectangle(rect)
Gp2.AddRectangle(rect)
SwapIfNecessary()
End Sub
Public ReadOnly Property gp() As GraphicsPath
Get
Return ActivePtr
End Get
End Property
Private Sub SwapIfNecessary()
If InActivePtr.PointCount > _MinimumSize Then
If NextActiveGp = 1 Then
ActivePtr = Gp1
InActivePtr = Gp2
Gp2.Reset()
NextActiveGp = 2
Else ' Nextgp = 2
ActivePtr = Gp2
InActivePtr = Gp1
Gp1.Reset()
NextActiveGp = 1
End If
End If
End Sub
End Class
Wfanning@gso.uri.edu
-- modified at 8:29 Monday 18th June, 2007
|
|
|
|
|