Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I am working with COSMCtrl in order to display maps on to the viewing window.

In the COSMCtrl, a file name is passed on to the CD2DBitmap constructor along with CRenderTarget object. But my application doesnt have image file. It will receive image data (in the form of byte array) from a database.

Could any one please help me in finding out the solution ?

The sample code is below:
C++
BOOL COSMCtrl::DrawTile(CRenderTarget* pRenderTarget, const CD2DRectF& rTile, int nTileX, int nTileY)
{
  //What will be the return value from this function (assume the worst)
  BOOL bSuccess = FALSE;

  //Form the path to the cache file which we want to draw
  int nZoom = static_cast<int>(m_fZoom);
  CString sFile(GetTileCachePath(m_sCacheDirectory, nZoom, nTileX, nTileY, FALSE));

  //Get the fractional value of the zoom
  double fInt = 0;
  double fFractionalZoom = modf(m_fZoom, &fInt);

  //Try to obtain the standard tile
  CD2DBitmap bitmap(pRenderTarget, sFile);

// I have a Byte Array. I should pass the byte array instead of file

  //Determine how the tile should be draw
  BOOL bStandardTile = FALSE;
  if (fFractionalZoom == 0 && SUCCEEDED(bitmap.Create(pRenderTarget)))
   bStandardTile = TRUE;

  //Load up the image from disk and display it if we can
  if (bStandardTile)
  {
    //Draw the image to the screen at the specified position
    pRenderTarget->DrawBitmap(&bitmap, rTile, 1.0);
    bSuccess = TRUE;
  }

return bSuccess;
}


SQL
1. I am not allowed to save the byte array to disk (as image).

2. I have tried using the other constructor of CD2DBitmap which accepts CRenderTarget and HBITMAP. but of no use
Posted

1 solution

CBitmap::SetBitmapBits[^] if your data is RGB ...
 
Share this answer
 
Comments
[no name] 26-May-15 0:55am    
Hi,

I have tried the same as well. May be the pitch calculation was going wrong.
What value possibly could go into the "stride" parameter.

My Image Data (byte array) is a continous data. If i write all the bytes to a file without any modification, i get to see the image.

Could you please post some source code (for better understanding) ?

Thanks and Regards,
Kishor Reddy
barneyman 26-May-15 1:01am    
the stride will be determined by the format of your RGB - if its RGB8 it'll be 3x your scanline, if it's RGBA8 it'll be 4x etc
[no name] 26-May-15 1:10am    
If i save the byte data to file, the below properties are shown.
Dimensions: 256*256
Width : 256
Height : 256
Bit Depth : 24

How to calculate stride using these attributes ?

Also please confirm the source code
CD2DBitmap bitmap(pRenderTarget, _T(""));

int pitch = 0; // Pitch Calculation goes here
bitmap.CopyFromMemory(ByteArray, pitch);

Please confirm whether the source is correct ...

Thanks and Regards,
Kishor Reddy
barneyman 26-May-15 1:21am    
so your scanline (Width) is 256 with 3bytes per pixel - 3 * 256

there MAY be padding in there too - divide the filesize by 256, don't be surprised if it's not 768

i assume that ctor for CD2DBitmap creates a bitmap that's the same size/format as the render target? if that's 256*256*24 it should be fine, otherwise you're going to have to create an HBITMAP from the raw data and use the CRenderTarget ctor that uses HBITMAP - MFC's CBitmap is ok for that

[no name] 26-May-15 6:01am    
Can we use ID2D1RenderTarget::CreateBitmap() for the same ?
If so, can you tell me how to use it ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900