Q&A - Question How to Load/Convert TBitmap into TGIS_Bitmap Question ScoL asked on March 07, 2019, keyword: Developer Kernel We are working on switching over to DK11, and we have multiple libraries that already generate TBitmap graphics that we need to display. We can consider rewriting some or all our library code to use TGIS_Bitmap, but for now, how do we get a TBitmap in memory to load into a TGIS_Bitmap object? Saving to a file and loading from a file is not an acceptable solution. Using the CustomPaint example and adding a couple bitmaps to the Tatukgis sample folder, we have the following 2 snippets in the OnCreate function: // WORKS FINE bmp := TGIS_Bitmap.Create; bmp.LoadFromFile(TGIS_Utils.GisSamplesDataDir + 'Symbols\police.bmp'); // DRAWS NOTHING B : TBitmap; B := TBitmap.Create; B.LoadFromFile(TGIS_Utils.GisSamplesDataDir + 'Symbols\police.bmp'); bmp := TGIS_Bitmap.Create; bmp.LoadFromBitmap(B, 'not sure what to put here'); B.Free; So how do I get a TBitmap into a TGIS_Bitmap using LoadFromBitmap or some other helper function? I AM ONLY USING LOADFROMFILE as an example above to reproduce the problem. In our actual software, we have multiple library functions that give us a TBitmap with a background color (clLime) that should draw as transparent. Any help with how to get this drawing and even drawing with transparency in DK11 would be fantastic. - Scott Answers Tomasz Kosinski (TatukGIS) replied March 06, 2019 Hi There is possible a minor bug there. But try this (below). Same way you can draw PNG, BMP. JPG, SVG and WMF // global cache mysymbol = SymbolList.Prepare( 'path\symbol.bmp?TRUE' ); // ?TRU to make it transparent // and then upon drawing mysymbol.Symbol.Prepare( Viewer, // viewer reference Size, Color, // only vector symbols OutlineColor, // only vector symbols Angle, 0, // gap only for fills TGIS_LabelPosition.MiddleCenter, True, // if true then does not rotate with viewer rotation renderer // current renderer context ) ; mysymbol.Symbol.Draw( x, y ) ; mysymbol.Symbol.Unprepare ; ScoL replied March 07, 2019 This looks exciting, it would have helped to know that the symbol is a TGIS_SymbolPicture and the uses clause is GISSymbols. I am not sure what the scope of SymbolList. Do I declare a TGIS_SymbolList and create it in OnCreate? Or do I use the one I found in TGIS_Utils.SymbolList? Also, this still does not help me draw a TBitmap from memory. I am looking for a solution that does not require me to load from a file. var B : TBitmap; begin B := GetBitmapFromMyExistingSymbolLibrary; // Draw bitmap in TK11 // ??? B.Free; Appreciate your help! - Scott ScoL replied March 07, 2019 So my attempt at implementing your solution has an invalid pointer exception when closing the custom paint demo. Wondering what I should be doing differently? Here is what I did: - I added GisSymbol to the uses list. - I added a variable to the var list: symSchool : TGIS_SymbolAbstract; - I added this call in OnCreate: symSchool := TGIS_Utils.SymbolList.Prepare(sPath + '?TRUE'); - I added to OnDestroy: FreeObject(symSchool); - Then I added the following to GISPaintShapeEvent for Image2: var c : TGIS_Color; // undeclared, a dummy place holder for the Prepare method symSchool.Prepare( GIS, 800, c, c, 0, 0, TGIS_LabelPosition.MiddleCenter, true); symSchool.Draw(pt.X, pt.Y); symSchool.Unprepare; It draws with transparency, but on map close, I get the following now: "Project CustomPaint.exe raised exception class EInvalidPointer with message 'Invalid pointer operation'. When I break, it heads into GisSymbol.pas. What am I doing wrong? Thanks, Scott Lynn Tomasz Kosinski (TatukGIS) replied March 07, 2019 Do not destroy symSchool. SymboList will do this for you. Tomasz Kosinski (TatukGIS) replied March 07, 2019 Also you can just call: symSchool.Prepare( GIS, 800, TGIS_Color.None, TGIS_Color.None, 0, 0, TGIS_LabelPosition.MiddleCenter, true); symSchool.Draw(pt.X, pt.Y); symSchool.Unprepare; ScoL replied March 07, 2019 That works great. Thank you. We will work on converting our libraries to use these great new tools, especially to use PNGs instead of bitmaps anyway. So back to my original question. I have a B : TBitmap created by a function library. It is NOT loaded from a file path. It is in memory and ready to go. How do I draw my B: TBitmap without saving it to a file and then loading it into a TGIS_Bitmap from that file. Or how do I convert a TBitmap to a TGIS_Bitmap in memory? Or draw it some other way? Thanks, Scott Tomasz Kosinski (TatukGIS) replied March 07, 2019 Hi, Wait for 11.28.0-Unstable2 (Unstable are usually on Friday afternoon). We fixed minor error related to LoadFromBitmap. Then the code: procedure TForm1.GISPaintExtraEvent(_sender: TObject; _renderer: TGIS_RendererAbstract; _mode: TGIS_DrawMode); var bmp_b : TGIS_Bitmap; bmp_a : TBitmap; begin bmp_a := TBitmap.Create; try bmp_a.LoadFromFile('police.bmp' ); bmp_b := TGIS_Bitmap.Create; try bmp_b.LoadFromBitmap(bmp_a, ''); _renderer.CanvasDrawBitmap( bmp_b, TRect.Create(0, 0, 32, 32) ); finally bmp_b.Free ; end; finally bmp_a.Free ; end; end; Will work fine. Additional comment: SymboList uses path to avoid creating multiple items. So you can use a := SymboList.Prepare( 'mysymbol.bmp' ); b := SymboList.Prepare( 'mysymbol.bmp' ); // a is equal b Tomasz Kosinski (TatukGIS) replied March 07, 2019 One more comment. TGIS_Bitmap fully support ARGB while TBitmap (and generally Windows HBitmap) support for anything more than RGB is problematic. If you would like to answer the question please Sign In. * * Stay signed in on this computer Please review our recent Privacy Policy.If you have any questions or requests, please contact us. Forgotten password Rules The Questions and Answers (Q & A) is intended to provide a means of communication between TatukGIS customers. Licensed users (with active maintenance play) of TatukGIS products may contribute to the Q & A content. Read-only access is available to anyone. Keep the content positive and professional. Be courteous to others by posting information when a question or issue asked on the Q & A is answered or resolved by other means (such as with help from TatukGIS technical support). Offer others at least a hint how the posted question was answered or the issue was resolved. The Q & A is not a replacement for TatukGIS technical support. TatukGIS team may or may not regularly follow or contribute content.