Re: GDI+ Question
On Feb 29, 5:27 pm, "Mark Salsbery [MVP]"
<MarkSalsbery[MVP]@newsgroup.nospam> wrote:
<marcusadel...@gmail.com> wrote in message
news:9d2b856f-57f9-4794-8952-2aefe854e5e6@s19g2000prg.googlegroups.com...
Hi,
I have a GDIPlus Image object and I want to be able to obtain a source
global memory handle (HGLOBAL) to the DIB. How can I go about doing
this?
What do you mean by "the DIB"? The GDI+ Image is not a GDI DIB.
What form do you want your DIB in? A packed bitmap like a BMP file? =
Just a
BITMAPINFO struct followed by the pixel bits?
Mark
--
Mark Salsbery
Microsoft MVP - Visual C++
Thanks,
Marcus de Leon- Hide quoted text -
- Show quoted text -
Hi... well I am very unfamiliar with this process and this is what I
need to do. Currently there is a method that converts a JPG to a BMP
with the method below. I need to be able to do the same with a TIF. I
think I was told that using GDI+ to read the TIF and then write the
bits to a stream to get the DIB would be a method of doing this,
rather than doing it like the method below. What do you think?
BOOL Jpg2Bmp(PTERWND w,int input, LPBYTE InFile,HGLOBAL hBuf,long
BufLen, HGLOBAL far *hDIB, BOOL import)
{
HFILE hFile=HFILE_ERROR;
OFSTRUCT OpenBuf;
struct StrJpg far *jpg=NULL;
BYTE huge *InBuf=NULL;
BYTE marker;
int i;
BOOL IsJpgFile=TRUE,ReadComplete=FALSE;
if (hDIB) (*hDIB)=NULL;
// open the input file
if (input==TER_FILE) { // data in the file
lstrupr(InFile);
rTrim(InFile); // trim any spaces on right
if (lstrlen(InFile)==0) return FALSE;
lstrcpy(TempString,InFile); // make a copy in the data
segment
if
(HFILE_ERROR==(hFile=OpenFile(TempString,&OpenBuf,OF_READ)))
return PrintError(w,MSG_ERR_FILE_OPEN,"Jpg2Bmp");
}
else { // lock the buffer
if (NULL==(InBuf=GlobalLock(hBuf))) return
PrintError(w,MSG_ERR_MEM_LOCK,"Jpg2Bmp");
}
// allocate space for the jpg info structure
if (NULL==(jpg=(struct StrJpg far *)OurAlloc(sizeof(struct
StrJpg)))) {
if (input==TER_FILE) _lclose(hFile);
return PrintError(w,MSG_OUT_OF_MEM,"Jpg2Bmp");
}
FarMemSet(jpg,0,sizeof(struct StrJpg)); // initialize with zeros
jpg->w=w; // store our pointer
if (input==TER_FILE) jpg->hFile=hFile;
else {
jpg->buf=InBuf;
jpg->BufLen=BufLen;
jpg->hFile=HFILE_ERROR;
}
// Read Start-of-Image
if (!JpgGetMarker(w,jpg,&marker)) goto END_FILE;
if (import && marker!=0xD8) return
PrintError(w,MSG_BAD_JPG_FILE,"Jpg2Bmp");
IsJpgFile=(marker==0xD8);
if (!import) {
ReadComplete=TRUE;
goto END_FILE;
}
NEXT_MARKER:
if (!JpgGetMarker(w,jpg,&marker)) goto END_FILE; // get next
marker
if (marker==0xD9) { // end of file marker
ReadComplete=TRUE;
goto END_FILE;
}
else if (marker==0xDB) { // get the quantization
table
if (!JpgGetQTable(w,jpg)) goto END_FILE;
}
else if (marker==0xC0) { // get the image
information (SOF)
if (!JpgGetImageInfo(w,jpg)) goto END_FILE;
}
else if (marker==0xC1) goto END_FILE; // Extended sequential DCT
frame not supported
else if (marker==0xC2) goto END_FILE; // Progressive DCT frame
not supported
else if (marker==0xC3) goto END_FILE; // Lossless DCT frame not
supported
else if (marker==0xC4) { // Huffman table
if (!JpgGetHuffTable(w,jpg)) goto END_FILE;
}
else if (marker==0xDD) { // Restart interval
if (!JpgGetWord(w,jpg)) goto END_FILE; // pass over the segment
length
if (!JpgGetWord(w,jpg)) goto END_FILE; // retrieve restart
interval
jpg->McuPerInterval=jpg->CurWord;
}
else if (marker==0xDA) { // image data
if (!JpgReadImage(w,jpg)) goto END_FILE;
}
else JpgSkipMarker(w,jpg); // skip over the current marker
goto NEXT_MARKER;
END_FILE:
// pass the DIB handle
GlobalUnlock(jpg->hDIB);
if (hDIB==NULL || !IsJpgFile || !ReadComplete) {
GlobalFree(jpg->hDIB);
jpg->hDIB=NULL;
}
if (hDIB) (*hDIB)=jpg->hDIB;
// close file and release buffers
if (input==TER_FILE) _lclose(jpg->hFile);
// release memory
for (i=0;i<jpg->HuffTblCount;i++) {
if (jpg->HuffTbl[i].pSymbol) OurFree(jpg->HuffTbl[i].pSymbol);
if (jpg->HuffTbl[i].pSymLen) OurFree(jpg->HuffTbl[i].pSymLen);
if (jpg->HuffTbl[i].pCode) OurFree(jpg->HuffTbl[i].pCode);
}
OurFree(jpg);
if (ReadComplete) {
if (import) return (BOOL)(*hDIB);
else return IsJpgFile;
}
else return FALSE;
}