News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Bitmaps is a pain. Problems again

Started by minor28, December 14, 2010, 01:36:14 PM

Previous topic - Next topic

minor28

This is what I got.
- I have an image loaded to a static window from memory on an address pPixelData.
- The static window client rect is equal to the whole image.
- The loaded image height is larger than main window client rectangle.

Now I want to edit the displayed part of the image and then save to the same address in memory and also to a file.

Here is the code:


invoke CreateCompatibleDC,hDC
mov hcdc,eax
invoke CreateDIBSection,hDC,pBMI,DIB_RGB_COLORS,addr ppvBits,0,0
.if eax && ppvBits
mov hdib,eax
invoke SelectObject,hcdc,hdib
mov hObj,eax

invoke BitBlt,hcdc,RowStart,ColStart,PixW,PixH,hDC,ColStart,RowStart,SRCCOPY
.if eax
invoke GdiFlush
invoke GdipCreateBitmapFromGdiDib,pBMI,ppvBits,addr srcBitmap
invoke GdipCloneBitmapAreaI,RowStart,ColStart,PixW,PixH,
PixelFormat8bppIndexed,srcBitmap,addr ppBitmap
invoke GdipDisposeImage,srcBitmap
push ColStart
pop rect.left
push RowStart
pop rect.top
push PixW
pop rect.right
push PixH
pop rect.bottom
invoke GdipBitmapLockBits,ppBitmap,addr rect,ImageLockModeWrite,
PixelFormat8bppIndexed,addr bmpd

;This is to compare the two buffers
lea esi,bmpd
mov esi,dword ptr [esi].BitmapData.Scan0
mov edi,pPixelData
xor ecx,ecx
.while ecx<memorysize ;=size of pPixelData
movzx eax,byte ptr [edi+ecx]
movzx edx,byte ptr [esi+ecx]
.if word ptr [edi+ecx]==0
nop
.elseif edx>6
nop
.elseif eax!=edx
nop
.endif
inc ecx
.endw

;Copy edited pixels to pPixelData
lea edi,bmpd
invoke RtlMoveMemory,pPixelData,dword ptr [edi].BitmapData.Scan0,memorysize

invoke GdipDisposeImage,ppBitmap
invoke DeleteObject,hObj
invoke DeleteObject,hdib
.endif

.endif
invoke DeleteDC,hcdc

;Here code to delete undo/redo buffer

invoke RedrawWindow,hMain,0,0,RDW_INVALIDATE or RDW_ERASENOW or RDW_ALLCHILDREN

;Save to file
invoke SaveImage


Here is the problem.

I do not edit but save the image. Function SaveImage do not work. If I comment out "invoke RtlMoveMemory" the save function works. This means there must be a differece between the two buffers.

If I edit the image and then save the image is updated and is displayed OK, but not saved. If I comment out "invoke RtlMoveMemory" the original image is displayed.

Checking the two buffers on presence of two zeros (paddings), byte discrepancis or presence of higher bytevalue than number of colors, show the first byte discrepancy after 8a940h bytes of the total memorysize 0bd4d0h.

After hours of try and error I would appraciate if somebody could tell me how to do this.

Best regards