Comments (5)
Hello @uklatt,
hdcMem = CreateCompatibleDC( hdc );
Where is hdc
initialized? Is this code part of something large in a window procedure callback function?
When I display the bitmap file (8 bit palette image) with
GdDrawImageFromFile(hdc->psd, x,y,dx,dy, filename,0);
only the top half of the bitmap is displayed.
In general, it isn't recommended to call Gdxxx
routines directly from another (Win32 or Nano-X) API. What API are you writing programs in generally?
That said, the above GdDrawImageFromFile could be being clipped to the output window, depending on the API being used.
You might grep/look through the various demo programs in src/bin as well as demos/mwin and demos/nanox, there are a number which draw images.
Thank you!
from microwindows.
Hi Greg,
hdc
comes from BeginPaint()
in WM_PAINT of the window.
If I use the image_penguine:
extern MWIMAGEHDR image_penguin;
PMWIMAGEHDR image = &image_penguin;
the following code works.
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rc);
hdcMem = CreateCompatibleDC(hdc);
hbmp = CreateCompatibleBitmap(hdcMem, image->width, image->height);
hbmpOrg = SelectObject(hdcMem, hbmp);
DrawDIB(hdcMem, 0, 0, image);
StretchBlt(ps.hdc, 0, 0, rc.right, rc.bottom, hdcMem, 0, 0, image->width, image->height, MWROP_COPY);
DeleteObject(SelectObject(hdcMem, hbmpOrg));
DeleteDC(hdcMem);
EndPaint(hwnd, &ps);
break;
But when I try to load the same bitmap it doesn't work:
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rc);
image = (PMWIMAGEHDR)GdLoadImageFromFile( "./penguin.bmp", 0 );
hdcMem = CreateCompatibleDC(hdc);
hbmp = CreateCompatibleBitmap(hdcMem, image->width, image->height);
hbmpOrg = SelectObject(hdcMem, hbmp);
DrawDIB(hdcMem, 0, 0, image);
StretchBlt(ps.hdc, 0, 0, rc.right, rc.bottom, hdcMem, 0, 0, image->width, image->height, MWROP_COPY);
DeleteObject(SelectObject(hdcMem, hbmpOrg));
DeleteDC(hdcMem);
EndPaint(hwnd, &ps);
break;
gdb-output:
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/libthread_db.so.1".
1920x1080x32bpp pitch 7680 type 0 visual 2 colors 16777216 pixtype 8
Program received signal SIGSEGV, Segmentation fault.
0x0000aaaaaaaa10c4 in wproc (hwnd=0xaaaaaaac19e0, message=15, wParam=0, lParam=0) at main.c:65
65 hbmp = CreateCompatibleBitmap(hdcMem, image->width, image->height);
(gdb) print image
$1 = (PMWIMAGEHDR) 0xffffffffaaac6f80
(gdb) print image->width
Cannot access memory at address 0xffffffffaaac6f84
This looks like a 32Bit/64Bit pointer problem...
==========================
I found the reason!
I missed the declaration of GdLoadImageFromFile()
.
Without the declaration the return value of GdLoadImageFromFile()
ist truncated to int (32 bits).
from microwindows.
One small thing:
I use copy from memory device context to another memory device context.
This triggers the assert in gen_allocatememgc
I must disable this check.
PSD gen_allocatememgc(PSD psd)
{
PSD mempsd;
// assert(psd == &scrdev); // triggers when copy from one memory device context to another one
...
}
from microwindows.
image = (PMWIMAGEHDR)GdLoadImageFromFile( "./penguin.bmp", 0 );
In general, one can't call Gdxxx
functions from the WIN32 API. The reason your program is crashing is that GdLoadImageFromtFile
returns a PSD
, where as a PMWIMAGEHDR
is an entirely different structure. Casting from one structure pointer to another won't work.
For WIN32 API, generally you'll have to convert the image to a .c file, which the demos/mwin/mwdemo.c program does, or, you can convert the image to BMP format, then store load it from a .res resource file using resLoadBitmap
. Look at demos/mwin/mwmine.c for how that can be done.
from microwindows.
Hi Greg,
I compile the code on Linux x64 and it works ;-)
Thank you for your help
Uwe
from microwindows.
Related Issues (20)
- libxcb support? HOT 1
- Porting to sel4 HOT 1
- GrCopyArea all 0s HOT 12
- Window border glitches after resize HOT 4
- Next Update? HOT 2
- Error running nano-X on linux framebuffer HOT 1
- I am so confused! HOT 3
- Question on keyboard event devices in linux HOT 5
- Strange gtk 1.2.10 behaviors with nano-X HOT 5
- How to switch from 16bit to 32bit colors HOT 16
- endian.h HOT 4
- Present to the future challenge HOT 2
- cosmopolitan binaries experiment? HOT 4
- Doc has dead links
- Linker Error with GCC 11 HOT 5
- microwindows on 64bit ARM HOT 6
- NanoX on Microsoft Windows HOT 1
- 'ft2build.h' file not found HOT 1
- wasm: hide window content while dragging ? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from microwindows.