Main > Forum > 1C:Enterprise Platform > 1C:Enterprise – Business applications platform > COMSafeArray to BinaryData

Forum

Search UsersRules
COMSafeArray to BinaryData
#1
Just came
Points:: 0
Joined:: Jan 17, 2015

Hi,
1C Sql I am recording data as an image.
When I read the sql data, it comes as Type COMSafeArray.
How to convert this type to BinaryData?

Profile
#2
Active user
Points:: 0
Joined:: Nov 3, 2011

Burak,

can you please describe your scenario in detail, so we can recommend the optimal solution? What is this image for and what do you mean by "1C sql"?

Profile
#3
Just came
Points:: 0
Joined:: Jan 17, 2015

Hi,



&Atserver
Procedure SAVE_PICTURE()        


MyPicture = New BinaryData("C:\Users\Burak\Pictures\images.jpg");


AdoCommand = SQLConnection();      
AdoCommand.CommandText ="
|Ins ert mye_ImageData (TableID,RecID_DBCno,RecID_RECno,ImageID,DataID,Data)
|Values (13,0,8,0,'',(SEL ECT  CAST('"+ MyPicture +"' AS VARBINARY(MAX))))";

RecordSet = AdoCommand.Execute();

EndProcedure

&Atserver
Procedure SELECT_PICTURE()        

AdoCommand = SQLConnection();      
AdoCommand.CommandText ="
|SELECT CAST((select Data fr om mye_ImageData Where TableID=13
|and RecID_DBCno=0 and RecID_RECno=8 and ImageID = 0) AS VARCHAR(MAX))";


RecordSet = AdoCommand.Execute();
RecordSet.MoveFirst();

While Not RecordSet.EOF() Do

Value_ = RecordSet.Fields(0).Val ue;

RecordSet.MoveNext();
EndDo;


PictureBinaryData = GetBinaryDataFromString(Value_);


PictureAddress = PutToTempStorage(PictureBinaryData);


EndProcedure

Profile
#4
Just came
Points:: 0
Joined:: Jan 17, 2015

Image display failed

Profile
#5
Active user
Points:: 0
Joined:: Nov 3, 2011

Burak,

let's try to localize the error. Please check what you get in this line:

Code
PictureBinaryData = GetBinaryDataFromString(Value_);


If you write this picture to a file, does it look like the original picture? If not, what's the difference from the original picture file?

Profile
#6
Just came
Points:: 0
Joined:: Jan 17, 2015

Hi,

I used "GetBinaryDataFromBase64String" instead of "GetBinaryDataFromString" , it worked . Thank you.

Profile
#7
Just came
Points:: 0
Joined:: Jan 17, 2015

How to resize the picture?

For example, C# "Bitmap bmp = new Bitmap (pictureBox1.Image, 500, 700);"

Profile
#8
Active user
Points:: 0
Joined:: Nov 3, 2011

Burak,

1C:Enteprrise does not provide this functionality. However, you can attach an add-in that resizes pictures.

Profile
#9
Just came
Points:: 0
Joined:: Aug 11, 2017

How do I add an add-on?

Profile
#10
Active user
Points:: 0
Joined:: Nov 3, 2011

For information about attaching add-ins, see "Chapter 32. Add-ins" of 1C:Enterprise Developer Guide.

For information about add-in development, see https://1c-dn.com/library/add_in_creation_technology/.

Profile
#11
Active user
Points:: 0
Joined:: Nov 3, 2011

Maybe the PictureSize property of "form field extension for a picture" will help? If you need to resize a picture solely for displaying it in a form, simply set the form field size and then set PictureSize to Stretch. The picture will exactly fit the form field.

Profile
#12
Just came
Points:: 0
Joined:: Jan 17, 2015

I made the picture resize with C# and ran RunApp().
Thank you.

Profile
#13
Just came
Points:: 0
Joined:: Nov 1, 2011

Вот так надо делать:

ИмяФайла = КаталогВременныхФайлов() + ГУИДСтрока + ".png";
SaveOptionsEnum = Новый Структура("adSaveCreateNotExist, adSaveCreateOverWrite", 1, 2);
ConnectModeEnum = Новый Структура(
       "adModeRead, adModeReadWrite, adModeRecursive, adModeShareDenyNone,
       |adModeShareDenyRead, adModeShareDenyWrite, adModeShareExclusive,
       |adModeUnknown, adModeWrite", 1, 3, 4194304, 16, 4, 8, 12, 0, 2);
StreamTypeEnum = Новый Структура("adTypeBinary, adTypeText", 1, 2);

StreamOut = Новый COMОбъект("ADODB.Stream");
StreamOut.Type = StreamTypeEnum.adTypeBinary;
StreamOut.Mode = ConnectModeEnum.adModeReadWrite;

StreamOut.Open();
StreamOut.Write(ФотоДвоичныеДанные);
StreamOut.SaveToFile(ИмяФайла, SaveOptionsEnum.adSaveCreateOverWrite);
StreamOut.Close();
ФайлФото = Новый ДвоичныеДанные(ИмяФайла);





Base64ДанныеФотографии = Base64Строка(ФайлФото);

Profile
#14
Administrator
Points:: 0
Joined:: Oct 3, 2019

Hi Valeriy Martikov,

our forum was created to help developers from other countries work with the 1C platform. The language of communication on our forum is English.

We kindly ask you to duplicate your message in English so that all other participants can understand what you wanted to communicate.


I ask you to treat this requirement with understanding.

Profile
Subscribe
Users browsing this topic (guests: 1, registered: 0, hidden: 0)



© 1C LLC. All rights reserved
1C Company respects the privacy of our customers and visitors
to our Web-site.