Jump to content

How save to .jpg after " _GDIPlus_BitmapCreateFromGraphics" ??


Recommended Posts

Hello everyone!

Here is my problem: I want to make temporary GUI to extract a graph as an image ...

But impossible! I just have a black box that comes as an image ...

Can you help me??

My code attached ...

File "data_graph.ini" :

[Relevés]
1=75
2=30
3=30
4=90
5=100
6=110
7=70
8=86
9=60
10=78
11=83
12=89
13=180
14=120
15=95
16=89
17=86
18=65
19=90
20=34
21=0
22=0
23=56
24=0

P.S : Sorry for my english but i'm french :(

TEST CREATION GRAPH SIMPLE.au3

Edited by Tomy46

======> Tomy ... just for fun ;) <======

Link to comment
Share on other sites

Shouldn't you be saving $backbuffer instead?

; !!!!!!! SAUVEGARDE EN FICHIER IMAGE !!!!!!!
; _GDIPlus_ImageSaveToFile ($bitmap, @MyDocumentsDir & "\TEST_GRAPH.bmp")
_GDIPlus_ImageSaveToFile($backbuffer, @MyDocumentsDir & "\TEST_GRAPH.bmp")

Not sure, couldn't test.

:idea:

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Shouldn't you be saving $backbuffer instead?

; !!!!!!! SAUVEGARDE EN FICHIER IMAGE !!!!!!!
; _GDIPlus_ImageSaveToFile ($bitmap, @MyDocumentsDir & "\TEST_GRAPH.bmp")
_GDIPlus_ImageSaveToFile($backbuffer, @MyDocumentsDir & "\TEST_GRAPH.bmp")

Not sure, couldn't test.

:idea:

After test : bad :s

No image saved ...

No results...

HELP :)

UP...

======> Tomy ... just for fun ;) <======

Link to comment
Share on other sites

  • 8 months later...

I just have a black box that comes as an image ...

I have the exact same problem. God, help us, GDI+ is shit!

I wish I had a wrapper for GD or GD2... I could write one but I don't know how to pass a FILE* in parameter during a DllCall (http://www.libgd.org/ImageCreation#gdImageCreateFromPng.28FILE_.2Ain.29_.28FUNCTION.29). So just stumbling from one problem to another. This is just too depressing...

Link to comment
Share on other sites

When you draw a black pen to a black screen then you will see only a black bitmap. :P

Try this:

#include <GDIPlus.au3>
#include <WinAPI.au3>
;CONVENTIONNEL
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)


Global $GUI, $nombre, $start, $style, $graphics, $backbuffer, $bitmap, $nMsg
Global $axe_x_1, $axe_y_1, $axe_x_2, $axe_y_2, $releve_axe_y, $valeurs_axe_y
Global $GUI_GRAPH

_GUI()
_LANCER()
_Main()

Func _GUI()

; Initialisation du GDI+ et du GUI Virtuel
$GUI_GRAPH = GUICreate("GUI Graph", 280, 150)
GUISetBkColor(0xF0F0F0, $GUI_GRAPH)
GUISetState(@SW_SHOW)

EndFunc

Func _LANCER()

; =======================================================================================

_GDIPlus_Startup ()

;Création de la matrice graphique
$graphics = _GDIPlus_GraphicsCreateFromHWND($GUI_GRAPH)

;Conversion de la matrice sous forme de Bitmap (Toujours en mémoire)
$bitmap = _GDIPlus_BitmapCreateFromGraphics(280, 150, $graphics)

;Création du buffer de création des lignes de graph
$backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
_GDIPlus_GraphicsSetSmoothingMode($backbuffer, 2)
_GDIPlus_GraphicsClear($backbuffer, 0xFFF0F0F0)
; ==================== Realisation du graphique ====================

;Initialisation des variables
$axe_x_1 = 20
$axe_y_1 = 0
$releve_axe_y = 0

;Parametre de création
$style = _GDIPlus_PenCreate (0xFF000000)

;Création du repère (Start X/Y ; End X/Y)
_GDIPlus_GraphicsDrawLine ($backbuffer, 20, 20, 20, 130, $style)
_GDIPlus_GraphicsDrawLine ($backbuffer, 20, 130, 270, 130, $style)

;Chargement des valeurs
$valeurs_axe_y = IniReadSection ("data_graph.ini", "Relevés")
If @error Then MsgBox(64, "Erreur de chargement des données du graphique !", "Attention, les données du graphique n'ont pas été correctement chargées!")

;MAJ Positions sur -Y
Do
    _PLACEMENT()
Until $releve_axe_y = 24

; ========================== Finalisation ===========================
_GDIPlus_PenDispose($style)

;Affichage de l'image chargé en variable sur GUI de base (Position X/Y) = OK
_GDIPlus_GraphicsDrawImageRect($graphics,$bitmap,0,0,280,150)

; !!!!!!! SAUVEGARDE EN FICHIER IMAGE !!!!!!!
_GDIPlus_ImageSaveToFile ($bitmap, @ScriptDir & "\TEST_GRAPH.jpg")

;Nettoyage de la variable = OK
_GDIPlus_BitmapDispose($bitmap)

; Arrêt de la librairie GDI+
_GDIPlus_ShutDown ()

; =======================================================================================
EndFunc

Func _PLACEMENT()
    ;Calcul X/Y Depart
    If $releve_axe_y = 0 Then
        $releve_axe_y += 1
        $axe_x_1 += 10
        $axe_y_1 = 130 - $valeurs_axe_y[""& $releve_axe_y &""][1]
    Else
        $releve_axe_y += 1
        $axe_x_1 = $axe_x_2
        $axe_y_1 = $axe_y_2
    EndIf

    ;Calcul X/Y Final
    $axe_x_2 = $axe_x_1 + 10
    $axe_y_2 = 130 - $valeurs_axe_y[""& $releve_axe_y &""][1]

    ;Création du repère (Start X/Y ; End X/Y)
    _GDIPlus_GraphicsDrawLine ($backbuffer, $axe_x_1, $axe_y_1, $axe_x_2, $axe_y_2, $style)

EndFunc

Func _MAIN()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
EndFunc

Also check out the order how you paint to graphic and save the image afterwards!

Br,

UEZ

Edit: original post is from 20 April 2010 - 01:34 AM :x

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...